diff options
Diffstat (limited to 'xml_honeypot.py')
-rw-r--r-- | xml_honeypot.py | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/xml_honeypot.py b/xml_honeypot.py deleted file mode 100644 index 4c2647a..0000000 --- a/xml_honeypot.py +++ /dev/null @@ -1,111 +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('xml_honeypot') -_logger.setLevel(logging.DEBUG) - -# we need to parse some xml files -from xml.sax import saxutils, handler -from xml.sax import make_parser -from xml.sax.handler import feature_namespaces - -class content_handler(handler.ContentHandler): - def __init__(self): - _logger.debug("content_handler init") - - def startDocument(self): - self.drops = [] - - def endDocument(self): - _logger.debug('end of xml document') - - def startElement(self, name, attrs): - # we don't check for errors at the moment, and ignore many features - if name == 'question' or name == 'answer': - self.wait_for_characters = name - else: - self.wait_for_characters = False - _logger.debug("element: " + name + ", attributes: " + str(attrs)) - - def characters(self, content): - # it's a hack for now, i just take the first chunk of content, this might produce errors - if self.wait_for_characters == 'question': - self.question = content - self.wait_for_characters = '' - if self.wait_for_characters == 'answer': - self.answer = content - self.wait_for_characters = '' - self.drops.append([self.question, self.answer]) - _logger.debug('q/a: ' + self.question + '/' + self.answer) - - _logger.debug('content: ' + content) - - - -class DTD_handler(handler.DTDHandler): - def __init__(self): - _logger.debug("DTD_handler init") - -class error_handler(handler.ErrorHandler): - def __init__(self): - _logger.debug("error_handler init") - - def warning(self, exception): - _logger.debug(exception) - - def error(self, exception): - _logger.debug(exception) - - def fatalError(self, exception): - _logger.debug(exception) - - - -class xml_honeypot: - - def __init__(self, runaslib=True): - - # see http://pyxml.sourceforge.net/topics/howto/node12.html - - # Create a parser - self.parser = make_parser() - - # Tell the parser we are not interested in XML namespaces - self.parser.setFeature(feature_namespaces, 0) - - # Create the handler - self.content_handler = content_handler() - self.DTD_handler = DTD_handler() - self.error_handler = error_handler() - - # Tell the parser to use our handler - self.parser.setContentHandler(self.content_handler) - self.parser.setDTDHandler(self.DTD_handler) - self.parser.setErrorHandler(self.error_handler) - - def load_drops(self): - - # Parse the input - self.xml_filename = 'my_first_questions.honeypot' - # xml_file = open(self.xml_filename, 'r') - self.parser.parse(self.xml_filename) - -if __name__ == '__main__': - xml_honeypot(False) - |