Permalink
Browse files

Improved logging, added options sanity checks

  • Loading branch information...
1 parent c6d02a8 commit 816172cc952736eb068fb99218b87d5ed2ca5be6 @gbrindisi committed Jul 23, 2012
Showing with 66 additions and 32 deletions.
  1. +8 −6 README.md
  2. +5 −24 wordpot.py
  3. +53 −1 wordpot/__init__.py
  4. +0 −1 wordpot/logger.py
View
@@ -6,12 +6,14 @@ Wordpot is a Wordpress honeypot which detects probes for plugins, themes, timthu
Usage: wordpot.py [options]
Options:
- -h, --help show this help message and exit
- --host=HOST Host address
- --port=PORT Port address
- --title=TITLE Blog Title
- --theme=THEME Default theme name
- --ver=VERSION Wordpress version
+ -h, --help show this help message and exit
+ --host=HOST Host address
+ --port=PORT Port address
+ --title=TITLE Blog Title
+ --theme=THEME Default theme name
+ --plugins=PLUGINS Fake installed plugins
+ --themes=THEMES Fake installed plugins
+ --ver=VERSION Wordpress version
To configure the honeypot you can edit the config file `wordpot.conf` or provide arguments trough the command line interface as shown above.
View
@@ -7,36 +7,17 @@
print " $ pip install flask\n"
exit()
-from wordpot import app, pm
+from wordpot import app, pm, parse_options, check_options
from wordpot.logger import *
-from optparse import OptionParser
-import os
-
-def parse_options():
- usage = "usage: %prog [options]"
-
- parser = OptionParser(usage=usage)
- parser.add_option('--host', dest='HOST', help='Host address')
- parser.add_option('--port', dest='PORT', help='Port number')
- parser.add_option('--title', dest='BLOGTITLE', help='Blog title')
- parser.add_option('--theme', dest='THEME', help='Default theme name')
- parser.add_option('--plugins', dest='PLUGINS', help='Fake installed plugins')
- parser.add_option('--themes', dest='THEMES', help='Fake installed themes')
- parser.add_option('--ver', dest='VERSION', help='Wordpress version')
- (options, args) = parser.parse_args()
-
- for opt, val in options.__dict__.iteritems():
- if val is not None:
- if opt in ['PLUGINS', 'THEMES']:
- val = [ v.strip() for v in val.split(',') ]
- app.config[opt] = val
+import os
-# Setup logging before execute the main
-logging_setup()
+check_options()
if __name__ == '__main__':
parse_options()
+ LOGGER.info('Checking command line options')
+ check_options()
LOGGER.info('Honeypot started on %s:%s', app.config['HOST'], app.config['PORT'])
app.run(debug=app.debug, host=app.config['HOST'], port=int(app.config['PORT']))
View
@@ -7,6 +7,8 @@
print " $ pip install flask\n"
exit()
+from optparse import OptionParser
+from wordpot.logger import *
from werkzeug.routing import BaseConverter
from wordpot.plugins_manager import PluginsManager
import os
@@ -20,6 +22,51 @@ def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
+# -------
+# Options
+# -------
+
+REQUIRED_OPTIONS = {
+ 'HOST': '127.0.0.1',
+ 'PORT': '80',
+ 'THEME': 'twentyeleven',
+ 'BLOGTITLE': 'Random Rambling',
+ 'AUTHORS': ['admin']
+ }
+
+
+def parse_options():
+ usage = "usage: %prog [options]"
+
+ parser = OptionParser(usage=usage)
+ parser.add_option('--host', dest='HOST', help='Host address')
+ parser.add_option('--port', dest='PORT', help='Port number')
+ parser.add_option('--title', dest='BLOGTITLE', help='Blog title')
+ parser.add_option('--theme', dest='THEME', help='Default theme name')
+ parser.add_option('--plugins', dest='PLUGINS', help='Fake installed plugins')
+ parser.add_option('--themes', dest='THEMES', help='Fake installed themes')
+ parser.add_option('--ver', dest='VERSION', help='Wordpress version')
+
+ (options, args) = parser.parse_args()
+
+ for opt, val in options.__dict__.iteritems():
+ if val is not None:
+ if opt in ['PLUGINS', 'THEMES']:
+ val = [ v.strip() for v in val.split(',') ]
+ app.config[opt] = val
+
+def check_options():
+ for k, v in REQUIRED_OPTIONS.iteritems():
+ if k not in app.config:
+ LOGGER.error('%s was not set. Falling back to default: %s', k, v)
+ app.config[k] = v
+
+# -------------------
+# Building the Logger
+# -------------------
+
+logging_setup()
+
# ------------
# Building app
# ------------
@@ -29,7 +76,12 @@ def __init__(self, url_map, *items):
# Import config from file
conffile = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../wordpot.conf')
-app.config.from_pyfile(conffile)
+LOGGER.info('Loading conf file: %s', conffile)
+try:
+ app.config.from_pyfile(conffile)
+except:
+ LOGGER.error('Can\'t load conf file')
+check_options()
# ----------------------------
# Building the plugins manager
View
@@ -1,6 +1,5 @@
#!/usr/bin/env python
-from wordpot import app
import logging
import logging.handlers
import os

0 comments on commit 816172c

Please sign in to comment.