From c0e892da25ad66a8b67016b4f8cf2d898e984c7d Mon Sep 17 00:00:00 2001 From: Suraj Tripathi Date: Sat, 30 Dec 2017 02:40:06 +0530 Subject: [PATCH] Fix #220 (#222) * Check emulator if true * change to bool type in config and test_config * update * update * update * update * update * update * update --- bin/tanner | 2 +- tanner/config.py | 13 +++++++------ tanner/emulators/base.py | 2 +- tanner/reporting/log_hpfeeds.py | 2 +- tanner/server.py | 8 ++++---- tanner/tests/test_config.py | 11 ++++++----- tanner/tests/test_server.py | 1 + 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/bin/tanner b/bin/tanner index 8c8b6bef..a47aea7e 100644 --- a/bin/tanner +++ b/bin/tanner @@ -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() diff --git a/tanner/config.py b/tanner/config.py index c8929146..1b0d0ae2 100644 --- a/tanner/config.py +++ b/tanner/config.py @@ -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} } @@ -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] diff --git a/tanner/emulators/base.py b/tanner/emulators/base.py index b3c20c20..b57a3c47 100644 --- a/tanner/emulators/base.py +++ b/tanner/emulators/base.py @@ -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']: diff --git a/tanner/reporting/log_hpfeeds.py b/tanner/reporting/log_hpfeeds.py index 6a2d16bf..99ce97df 100644 --- a/tanner/reporting/log_hpfeeds.py +++ b/tanner/reporting/log_hpfeeds.py @@ -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') diff --git a/tanner/server.py b/tanner/server.py index a97490e0..cf92432e 100644 --- a/tanner/server.py +++ b/tanner/server.py @@ -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() @@ -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) diff --git a/tanner/tests/test_config.py b/tanner/tests/test_config.py index a4e8b0dd..9e78083d 100644 --- a/tanner/tests/test_config.py +++ b/tanner/tests/test_config.py @@ -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 = { @@ -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: diff --git a/tanner/tests/test_server.py b/tanner/tests/test_server.py index 6668db39..c9835f7c 100644 --- a/tanner/tests/test_server.py +++ b/tanner/tests/test_server.py @@ -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):