Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/mathparse_honeypot.py
diff options
context:
space:
mode:
Diffstat (limited to 'mathparse_honeypot.py')
-rw-r--r--mathparse_honeypot.py103
1 files changed, 0 insertions, 103 deletions
diff --git a/mathparse_honeypot.py b/mathparse_honeypot.py
deleted file mode 100644
index f8d5f2c..0000000
--- a/mathparse_honeypot.py
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright (C) 2010, Johannes Ponader
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-import logging
-_logger = logging.getLogger('mathparse')
-_logger.setLevel(logging.DEBUG)
-
-import sys, random, time, re, ast, parser
-
-
-class mathparse_honeypot:
-
- def __init__(self, runaslib=True):
-
- # Seed the random number generator
- random.seed(time.time())
-
- def parse(self, drop):
- question = drop[0]
- answer = drop[1]
-
- # look for "[1-10]" etc.
- regexp = r"\[(\d+)-(\d+)]"
- _logger.debug('begin parse: ' + str(question))
- question = re.split(regexp, question)
- _logger.debug('split q1: ' + str(question))
- # "\1" stands for random_value[0]
- random_values = []
- for i in range(1, len(question), 3):
- _logger.debug(len(question))
- rand_val = str(random.randint(int(question[i]), int(question[i+1])+1))
- random_values.append(rand_val)
- question[i] = rand_val
- question[i+1] = ""
- _logger.debug('q1[' + str(i) + ']: ' + str(question))
- # make it one string again
- question = u"".join(question)
- _logger.debug('join q1: ' + str(question))
-
- # look for markers like "\1"
- regexp = r"\\(\d+)"
- question = re.split(regexp, question)
- _logger.debug('split q2: ' + str(question))
- for i in range(1, len(question), 2):
- #no error/range checking so far
- question[i] = random_values[int(question[i])-1]
- _logger.debug('q2[' + str(i) + ']: ' + str(question))
- question = u"".join(question)
- _logger.debug('join q2: ' + str(question))
-
- # look for expressions to evaluate: "{...}"
- regexp = r"\{(.*)}"
- question = re.split(regexp, question)
- _logger.debug('split q3: ' + str(question))
- for i in range(1, len(question), 2):
- # Sicherheitsluecke!
- # vgl. http://effbot.org/zone/librarybook-core-eval.htm
- question[i] = str(eval(question[i]))
- _logger.debug('q3[' + str(i) + ']: ' + str(question))
- question = u"".join(question)
- _logger.debug('join q3: ' + str(question))
-
- regexp = r"\\(\d+)"
- answer = re.split(regexp, answer)
- _logger.debug('split a1: ' + str(question))
- for i in range(1, len(answer), 2):
- answer[i] = random_values[int(answer[i])-1]
- _logger.debug('a1[' + str(i) + ']: ' + str(question))
- answer = u"".join(answer)
- _logger.debug('join a1: ' + str(question))
-
- regexp = r"\{(.*)}"
- answer = re.split(regexp, answer)
- _logger.debug('split a2: ' + str(question))
- for i in range(1, len(answer), 2):
- answer[i] = str(eval(answer[i]))
- # answer[i] = str(ast.literal_eval(ast.parse(answer[i])))
- _logger.debug('a2[' + str(i) + ']: ' + str(question))
- answer = u"".join(answer)
- _logger.debug('join a2: ' + str(question))
-
- return [question,answer]
-
-
-if __name__ == '__main__':
- mathparse_honeypot(False)
-
- \ No newline at end of file