Skip to content

Commit

Permalink
Improved logging, added options sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrindisi committed Jul 23, 2012
1 parent c6d02a8 commit 816172c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 32 deletions.
14 changes: 8 additions & 6 deletions README.md
Expand Up @@ -6,12 +6,14 @@ Wordpot is a Wordpress honeypot which detects probes for plugins, themes, timthu
Usage: wordpot.py [options] Usage: wordpot.py [options]


Options: Options:
-h, --help show this help message and exit -h, --help show this help message and exit
--host=HOST Host address --host=HOST Host address
--port=PORT Port address --port=PORT Port address
--title=TITLE Blog Title --title=TITLE Blog Title
--theme=THEME Default theme name --theme=THEME Default theme name
--ver=VERSION Wordpress version --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. To configure the honeypot you can edit the config file `wordpot.conf` or provide arguments trough the command line interface as shown above.


Expand Down
29 changes: 5 additions & 24 deletions wordpot.py
Expand Up @@ -7,36 +7,17 @@
print " $ pip install flask\n" print " $ pip install flask\n"
exit() exit()


from wordpot import app, pm from wordpot import app, pm, parse_options, check_options
from wordpot.logger import * 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() import os

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


# Setup logging before execute the main check_options()
logging_setup()


if __name__ == '__main__': if __name__ == '__main__':
parse_options() parse_options()
LOGGER.info('Checking command line options')
check_options()


LOGGER.info('Honeypot started on %s:%s', app.config['HOST'], app.config['PORT']) 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'])) app.run(debug=app.debug, host=app.config['HOST'], port=int(app.config['PORT']))
Expand Down
54 changes: 53 additions & 1 deletion wordpot/__init__.py
Expand Up @@ -7,6 +7,8 @@
print " $ pip install flask\n" print " $ pip install flask\n"
exit() exit()


from optparse import OptionParser
from wordpot.logger import *
from werkzeug.routing import BaseConverter from werkzeug.routing import BaseConverter
from wordpot.plugins_manager import PluginsManager from wordpot.plugins_manager import PluginsManager
import os import os
Expand All @@ -20,6 +22,51 @@ def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map) super(RegexConverter, self).__init__(url_map)
self.regex = items[0] 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 # Building app
# ------------ # ------------
Expand All @@ -29,7 +76,12 @@ def __init__(self, url_map, *items):


# Import config from file # Import config from file
conffile = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../wordpot.conf') 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 # Building the plugins manager
Expand Down
1 change: 0 additions & 1 deletion wordpot/logger.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python


from wordpot import app
import logging import logging
import logging.handlers import logging.handlers
import os import os
Expand Down

0 comments on commit 816172c

Please sign in to comment.