Skip to content

Commit

Permalink
Merge pull request #8 from threatstream/hpfeeds
Browse files Browse the repository at this point in the history
Hpfeeds support for Wordpot
  • Loading branch information
gbrindisi committed Sep 23, 2014
2 parents bbaf582 + 38c0eea commit e42eeda
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.*
*.pyc
!.gitignore
/env

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==0.10.1
-e git+https://github.com/threatstream/hpfeeds/#egg=hpfeeds-dev
7 changes: 7 additions & 0 deletions wordpot.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ AUTHORS = ['admin'] # Authors list

#PLUGINS = [] # Installed plugins list
#THEMES = [] # Installed themes list

HPFEEDS_ENABLED = False
HPFEEDS_HOST = '127.0.0.1'
HPFEEDS_PORT = 10000
HPFEEDS_IDENT = 'wordpot'
HPFEEDS_SECRET = 'wordpot-pass'
HPFEEDS_TOPIC = 'wordpot.events'
13 changes: 13 additions & 0 deletions wordpot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def check_options():
LOGGER.error('Can\'t load conf file')
check_options()

if app.config['HPFEEDS_ENABLED']:
import hpfeeds
print 'Connecting to hpfeeds broker {}:{}'.format(app.config['HPFEEDS_HOST'], app.config['HPFEEDS_PORT'])
app.config['hpfeeds_client'] = hpfeeds.new(
app.config['HPFEEDS_HOST'],
app.config['HPFEEDS_PORT'],
app.config['HPFEEDS_IDENT'],
app.config['HPFEEDS_SECRET']
)
app.config['hpfeeds_client'].s.settimeout(0.01)
else:
LOGGER.warn('hpfeeds is disabled')

# ----------------------------
# Building the plugins manager
# ----------------------------
Expand Down
1 change: 1 addition & 0 deletions wordpot/plugins/badlogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def run(self):
username = self.inputs['request'].form['log']
password = self.inputs['request'].form['pwd']
self.outputs['log'] = '%s tried to login with username %s and password %s' % (origin, username, password)
self.outputs['log_json'] = self.to_json_log(username=username, password=password, plugin='badlogin')
self.outputs['template_vars']['BADLOGIN'] = True
self.outputs['template'] = 'wp-login.html'
else:
Expand Down
1 change: 1 addition & 0 deletions wordpot/plugins/commonfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def run(self):

if filename in common:
self.outputs['log'] = '%s probed for: %s' % (origin, filename)
self.outputs['log_json'] = self.to_json_log(filename=filename, plugin='commonfiles')
self.outputs['template'] = common[filename]

return
2 changes: 1 addition & 1 deletion wordpot/plugins/timthumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def run(self):
# Message to log
log = '%s probed for timthumb: %s' % (self.inputs['request'].remote_addr, self.inputs['subpath'])
self.outputs['log'] = log

self.outputs['log_json'] = self.to_json_log(filename=self.inputs['subpath'], plugin='timthumb')
# Template to render
self.outputs['template'] = 'timthumb.html'

Expand Down
1 change: 1 addition & 0 deletions wordpot/plugins/userenumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def run(self):
for k, a in enumerate(app.config['AUTHORS']):
if (k + 1) == int(req_args['author']):
self.outputs['log'] = '%s probed author page for user: %s' % (origin, a)
self.outputs['log_json'] = self.to_json_log(author=a, plugin='userenumeration')
self.outputs['template_vars']['AUTHORPAGE'] = True
self.outputs['template_vars']['CURRENTAUTHOR'] = (k+1, a)
self.outputs['template'] = app.config['THEME'] + '.html'
Expand Down
12 changes: 12 additions & 0 deletions wordpot/plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ def start(self, **kwargs):

def run(self):
return

def to_json_log(self, **kwargs):
import json
return json.dumps(dict(kwargs,
source_ip=self.inputs['request'].remote_addr,
source_port=self.inputs['request'].environ['REMOTE_PORT'],
dest_ip=self.inputs['request'].environ['SERVER_NAME'],
dest_port=self.inputs['request'].environ['SERVER_PORT'],
user_agent=self.inputs['request'].user_agent.string,
url=self.inputs['request'].url
))

8 changes: 8 additions & 0 deletions wordpot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def commons(filename=None, ext=None):
p.start(filename=filename, ext=ext, request=request)
if 'log' in p.outputs:
LOGGER.info(p.outputs['log'])
if 'log_json' in p.outputs and app.config['HPFEEDS_ENABLED']:
app.config['hpfeeds_client'].publish(app.config['HPFEEDS_TOPIC'], p.outputs['log_json'])
if 'template' in p.outputs:
if 'template_vars' in p.outputs:
return render_template(p.outputs['template'], vars=p.outputs['template_vars'])
Expand All @@ -40,6 +42,8 @@ def admin(subpath='/'):
p.start(subpath=subpath, request=request)
if 'log' in p.outputs:
LOGGER.info(p.outputs['log'])
if 'log_json' in p.outputs and app.config['HPFEEDS_ENABLED']:
app.config['hpfeeds_client'].publish(app.config['HPFEEDS_TOPIC'], p.outputs['log_json'])
if 'template' in p.outputs:
if 'template_vars' in p.outputs:
return render_template(p.outputs['template'], vars=p.outputs['template_vars'])
Expand All @@ -63,6 +67,8 @@ def plugin(plugin, subpath='/'):
p.start(plugin=plugin, subpath=subpath, request=request)
if 'log' in p.outputs:
LOGGER.info(p.outputs['log'])
if 'log_json' in p.outputs and app.config['HPFEEDS_ENABLED']:
app.config['hpfeeds_client'].publish(app.config['HPFEEDS_TOPIC'], p.outputs['log_json'])
if 'template' in p.outputs:
if 'template_vars' in p.outputs:
return render_template(p.outputs['template'], vars=p.outputs['template_vars'])
Expand All @@ -86,6 +92,8 @@ def theme(theme, subpath='/'):
p.start(theme=theme, subpath=subpath, request=request)
if 'log' in p.outputs:
LOGGER.info(p.outputs['log'])
if 'log_json' in p.outputs and app.config['HPFEEDS_ENABLED']:
app.config['hpfeeds_client'].publish(app.config['HPFEEDS_TOPIC'], p.outputs['log_json'])
if 'template' in p.outputs:
if 'template_vars' in p.outputs:
return render_template(p.outputs['template'], vars=p.outputs['template_vars'])
Expand Down

0 comments on commit e42eeda

Please sign in to comment.