Skip to content

Commit

Permalink
move factory initialization to startFactory instead of __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
micheloosterhof committed Jul 9, 2015
1 parent 6b0965a commit 9a30430
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions cowrie/core/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def logDispatch(self, *msg, **args):
output.logDispatch(*msg, **args)

def __init__(self, cfg):

self.cfg = cfg

def startFactory(self):

# protocol^Wwhatever instances are kept here for the interact feature
self.sessions = {}

Expand All @@ -107,18 +108,18 @@ def __init__(self, cfg):

# load db loggers
self.dbloggers = []
for x in cfg.sections():
for x in self.cfg.sections():
if not x.startswith('database_'):
continue
engine = x.split('_')[1]
dbengine = 'database_' + engine
lcfg = ConfigParser.ConfigParser()
lcfg.add_section(dbengine)
for i in cfg.options(x):
lcfg.set(dbengine, i, cfg.get(x, i))
for i in self.cfg.options(x):
lcfg.set(dbengine, i, self.cfg.get(x, i))
lcfg.add_section('honeypot')
for i in cfg.options('honeypot'):
lcfg.set('honeypot', i, cfg.get('honeypot', i))
for i in self.cfg.options('honeypot'):
lcfg.set('honeypot', i, self.cfg.get('honeypot', i))
log.msg('Loading dblog engine: %s' % (engine,))
dblogger = __import__(
'cowrie.dblog.%s' % (engine,),
Expand All @@ -128,25 +129,27 @@ def __init__(self, cfg):

# load new output modules
self.output_plugins = [];
for x in cfg.sections():
for x in self.cfg.sections():
if not x.startswith('output_'):
continue
engine = x.split('_')[1]
output = 'output_' + engine
lcfg = ConfigParser.ConfigParser()
lcfg.add_section(output)
for i in cfg.options(x):
lcfg.set(output, i, cfg.get(x, i))
for i in self.cfg.options(x):
lcfg.set(output, i, self.cfg.get(x, i))
lcfg.add_section('honeypot')
for i in cfg.options('honeypot'):
lcfg.set('honeypot', i, cfg.get('honeypot', i))
for i in self.cfg.options('honeypot'):
lcfg.set('honeypot', i, self.cfg.get('honeypot', i))
log.msg('Loading output engine: %s' % (engine,))
output = __import__(
'cowrie.output.%s' % (engine,)
,globals(), locals(), ['output']).Output(lcfg)
log.addObserver(output.emit)
self.output_plugins.append(output)

factory.SSHFactory.startFactory(self)

def buildProtocol(self, addr):
"""
Create an instance of the server side of the SSH protocol.
Expand Down

0 comments on commit 9a30430

Please sign in to comment.