From 9a30430da4ebbf2f7ff76086dc744d99ee5ca024 Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Thu, 9 Jul 2015 15:50:14 +0400 Subject: [PATCH] move factory initialization to startFactory instead of __init__ --- cowrie/core/ssh.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cowrie/core/ssh.py b/cowrie/core/ssh.py index 371e6e6..7fd4063 100644 --- a/cowrie/core/ssh.py +++ b/cowrie/core/ssh.py @@ -88,9 +88,10 @@ class HoneyPotSSHFactory(factory.SSHFactory): 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 = {} @@ -107,18 +108,18 @@ class HoneyPotSSHFactory(factory.SSHFactory): # 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,), @@ -128,18 +129,18 @@ class HoneyPotSSHFactory(factory.SSHFactory): # 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,) @@ -147,6 +148,8 @@ class HoneyPotSSHFactory(factory.SSHFactory): 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.