Skip to content

Commit

Permalink
Fix #220 (#222)
Browse files Browse the repository at this point in the history
* Check emulator if true

* change to bool type in config and test_config

* update

* update

* update

* update

* update

* update

* update
  • Loading branch information
surajt97 authored and afeena committed Dec 29, 2017
1 parent 0218a0d commit c0e892d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bin/tanner
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main():
logger.Logger.create_logger(debug_log_file_name, error_log_file_name, __package__)
print("Debug logs will be stored in", debug_log_file_name)
print("Error logs will be stored in", error_log_file_name)
if TannerConfig.get('LOCALLOG', 'enabled') == 'True':
if TannerConfig.get('LOCALLOG', 'enabled') == True:
print("Data logs will be stored in", TannerConfig.get('LOCALLOG', 'PATH'))
tanner = server.TannerServer()
tanner.start()
Expand Down
13 changes: 7 additions & 6 deletions tanner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
'API': {'host': '0.0.0.0', 'port': 8092},
'REDIS': {'host': 'localhost', 'port': 6379, 'poolsize': 80, 'timeout': 1},
'EMULATORS': {'root_dir': '/opt/tanner'},
'EMULATOR_ENABLED': {'sqli': 'True', 'rfi': 'True', 'lfi': 'True', 'xss': 'True', 'cmd_exec': 'True'},
'EMULATOR_ENABLED': {'sqli': True, 'rfi': True, 'lfi': True, 'xss': True, 'cmd_exec': True},
'SQLI': {'type':'SQLITE', 'db_name': 'tanner_db', 'host':'localhost', 'user':'root', 'password':'user_pass'},
'DOCKER': {'host_image': 'busybox:latest'},
'LOGGER': {'log_debug': '/opt/tanner/tanner.log', 'log_err': '/opt/tanner/tanner.err'},
'MONGO': {'enabled': 'False', 'URI': 'mongodb://localhost'},
'HPFEEDS': {'enabled': 'False', 'HOST': 'localhost', 'PORT': '10000', 'IDENT': '', 'SECRET': '', 'CHANNEL': 'tanner.events'},
'LOCALLOG': {'enabled': 'False', 'PATH': '/tmp/tanner_report.json'},
'CLEANLOG': {'enabled': 'False'}
'MONGO': {'enabled': False, 'URI': 'mongodb://localhost'},
'HPFEEDS': {'enabled': False, 'HOST': 'localhost', 'PORT': 10000, 'IDENT': '', 'SECRET': '', 'CHANNEL': 'tanner.events'},
'LOCALLOG': {'enabled': False, 'PATH': '/tmp/tanner_report.json'},
'CLEANLOG': {'enabled': False}
}


Expand All @@ -39,7 +39,8 @@ def set_config(config_path):
def get(section, value):
if TannerConfig.config is not None:
try:
res = TannerConfig.config.get(section, value)
convert_type = type(config_template[section][value])
res = convert_type(TannerConfig.config.get(section, value))
except (configparser.NoOptionError, configparser.NoSectionError):
LOGGER.warning("Error in config, default value will be used. Section: %s Value: %s", section, value)
res = config_template[section][value]
Expand Down
2 changes: 1 addition & 1 deletion tanner/emulators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def get_emulation_result(self, session, data, target_emulators):
attack_params = {}
for param_id, param_value in data.items():
for emulator in target_emulators:
if TannerConfig.get('EMULATOR_ENABLED', emulator):
if TannerConfig.get('EMULATOR_ENABLED', emulator):
possible_detection = self.emulators[emulator].scan(param_value) if param_value else None
if possible_detection:
if detection['order'] < possible_detection['order']:
Expand Down
2 changes: 1 addition & 1 deletion tanner/reporting/log_hpfeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Reporting():
def __init__(self):
# Create the connection
self.host = config.TannerConfig.get('HPFEEDS', 'HOST')
self.port = int(config.TannerConfig.get('HPFEEDS', 'PORT'))
self.port = config.TannerConfig.get('HPFEEDS', 'PORT')
self.ident = config.TannerConfig.get('HPFEEDS', 'IDENT')
self.secret = config.TannerConfig.get('HPFEEDS', 'SECRET')
self.channel = config.TannerConfig.get('HPFEEDS', 'CHANNEL')
Expand Down
8 changes: 4 additions & 4 deletions tanner/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
self.base_handler = base.BaseHandler(base_dir, db_name)
self.logger = logging.getLogger(__name__)
self.redis_client = None
if TannerConfig.get('HPFEEDS', 'enabled') == 'True':
if TannerConfig.get('HPFEEDS', 'enabled') == True:
self.hpf = hpfeeds_report()
self.hpf.connect()

Expand Down Expand Up @@ -71,17 +71,17 @@ async def handle_event(self, request):
session_data['response_msg'] = response_msg

# Log to Mongo
if TannerConfig.get('MONGO', 'enabled') == 'True':
if TannerConfig.get('MONGO', 'enabled') == True:
db = mongo_report()
session_id = db.create_session(session_data)
self.logger.info("Writing session to DB: {}".format(session_id))

# Log to hpfeeds
if TannerConfig.get('HPFEEDS', 'enabled') == 'True':
if TannerConfig.get('HPFEEDS', 'enabled') == True:
if self.hpf.connected():
self.hpf.create_session(session_data)

if TannerConfig.get('LOCALLOG', 'enabled') == 'True':
if TannerConfig.get('LOCALLOG', 'enabled') == True:
lr = local_report()
lr.create_session(session_data)
return web.json_response(response_msg)
Expand Down
11 changes: 6 additions & 5 deletions tanner/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def test_get_when_file_exists(self):
for section in self.d:
for value, assertion_data in self.d[section].items():
data = config.TannerConfig.get(section, value)
self.assertEqual(data, assertion_data)
convert_type = type(data)
self.assertEqual(data, convert_type(assertion_data))

def test_get_when_file_dont_exists(self):
config_template = {
Expand All @@ -63,13 +64,13 @@ def test_get_when_file_dont_exists(self):
'API': {'host': '0.0.0.0', 'port': 8092},
'REDIS': {'host': 'localhost', 'port': 6379, 'poolsize': 80, 'timeout': 1},
'EMULATORS': {'root_dir': '/opt/tanner'},
'EMULATOR_ENABLED': {'sqli': 'True', 'rfi': 'True', 'lfi': 'True', 'xss': 'True', 'cmd_exec': 'True'},
'EMULATOR_ENABLED': {'sqli': True, 'rfi': True, 'lfi': True, 'xss': True, 'cmd_exec': True},
'SQLI': {'type':'SQLITE', 'db_name': 'tanner_db', 'host':'localhost', 'user':'root', 'password':'user_pass'},
'DOCKER': {'host_image': 'busybox:latest'},
'LOGGER': {'log_debug': '/opt/tanner/tanner.log', 'log_err': '/opt/tanner/tanner.err'},
'MONGO': {'enabled': 'False', 'URI': 'mongodb://localhost'},
'LOCALLOG': {'enabled': 'False', 'PATH': '/tmp/tanner_report.json'},
'CLEANLOG': {'enabled': 'False'}
'MONGO': {'enabled': False, 'URI': 'mongodb://localhost'},
'LOCALLOG': {'enabled': False, 'PATH': '/tmp/tanner_report.json'},
'CLEANLOG': {'enabled': False}
}

for section in config_template:
Expand Down
1 change: 1 addition & 0 deletions tanner/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def setUp(self):
m.__getitem__.side_effect = d.__getitem__
m.__iter__.side_effect = d.__iter__
TannerConfig.config = m
TannerConfig.get = m.get

with mock.patch('tanner.dorks_manager.DorksManager', mock.Mock()):
with mock.patch('tanner.emulators.base.BaseHandler', mock.Mock(), create=True):
Expand Down

0 comments on commit c0e892d

Please sign in to comment.