diff --git a/snare/cloner.py b/snare/cloner.py index 6b4ed491..f6639b06 100644 --- a/snare/cloner.py +++ b/snare/cloner.py @@ -19,7 +19,7 @@ def __init__(self, root, max_depth, css_validate): self.max_depth = max_depth self.moved_root = None if len(self.root.host) < 4: - sys.exit('invalid taget {}'.format(self.root.host)) + sys.exit('invalid target {}'.format(self.root.host)) self.target_path = '/opt/snare/pages/{}'.format(self.root.host) if not os.path.exists(self.target_path): @@ -157,7 +157,7 @@ async def get_body(self, session): if not carved_url.is_absolute(): carved_url = self.root.join(carved_url) if carved_url.human_repr() not in self.visited_urls: - await self.new_urls.put((carved_url, level+1)) + await self.new_urls.put((carved_url, level + 1)) async def get_root_host(self): try: diff --git a/snare/middlewares.py b/snare/middlewares.py index a8875e3c..afa1765a 100644 --- a/snare/middlewares.py +++ b/snare/middlewares.py @@ -28,6 +28,7 @@ async def error_middleware(request, handler): if override: return await override(request) raise + return error_middleware def setup_middlewares(self, app): diff --git a/snare/tanner_handler.py b/snare/tanner_handler.py index c8810612..574b8900 100644 --- a/snare/tanner_handler.py +++ b/snare/tanner_handler.py @@ -38,7 +38,7 @@ def create_data(self, request, response_status): data['method'] = request.method data['headers'] = header data['path'] = request.path_qs - if ('Cookie' in header): + if 'Cookie' in header: data['cookies'] = { cookie.split('=')[0]: cookie.split('=')[1] for cookie in header['Cookie'].split(';') } @@ -123,4 +123,4 @@ async def parse_tanner_response(self, requested_name, detection): payload_content = detection['payload'] status_code = payload_content['status_code'] - return (content, content_type, headers, status_code) + return content, content_type, headers, status_code diff --git a/snare/tests/test_add_meta_tag.py b/snare/tests/test_add_meta_tag.py old mode 100644 new mode 100755 diff --git a/snare/tests/test_converter.py b/snare/tests/test_converter.py index 20dfedc2..4859add8 100644 --- a/snare/tests/test_converter.py +++ b/snare/tests/test_converter.py @@ -25,8 +25,8 @@ def test_converter(self): s = json.load(f) self.hname1 = s['index.html']['hash'] self.hname2 = s['depth/page.html']['hash'] - assert(os.path.exists(self.page_path + self.hname1) and - os.path.exists(self.page_path + self.hname2)) + assert (os.path.exists(self.page_path + self.hname1) and + os.path.exists(self.page_path + self.hname2)) def tearDown(self): shutil.rmtree('/tmp/test') diff --git a/snare/tests/test_create_data.py b/snare/tests/test_create_data.py index c89e1db7..f1c48b50 100644 --- a/snare/tests/test_create_data.py +++ b/snare/tests/test_create_data.py @@ -22,7 +22,7 @@ def setUp(self): os.makedirs(self.main_page_path) page_dir = self.main_page_path.rsplit('/')[-1] args = run_args.parse_args(['--page-dir', page_dir]) - snare_uuid = ('9c10172f-7ce2-4fb4-b1c6-abc70141db56').encode('utf-8') + snare_uuid = '9c10172f-7ce2-4fb4-b1c6-abc70141db56'.encode('utf-8') args.no_dorks = True self.handler = TannerHandler(args, meta, snare_uuid) headers = { diff --git a/snare/tests/test_get_dorks.py b/snare/tests/test_get_dorks.py index 4fe98d72..f1e9a9ef 100644 --- a/snare/tests/test_get_dorks.py +++ b/snare/tests/test_get_dorks.py @@ -21,7 +21,7 @@ def setUp(self): timer=None, request_info=None, traces=None, loop=self.loop, session=None ) - ) + ) no_dorks = True tanner = "tanner.mushmush.org" self.handler = HtmlHandler(no_dorks, tanner) @@ -32,6 +32,7 @@ def test_get_dorks(self): async def test(): self.data = await self.handler.get_dorks() + self.loop.run_until_complete(test()) aiohttp.ClientSession.get.assert_called_with('http://tanner.mushmush.org:8090/dorks', timeout=10.0) @@ -40,6 +41,7 @@ def test_return_dorks(self): async def test(): self.data = await self.handler.get_dorks() + self.loop.run_until_complete(test()) self.assertEquals(self.data, self.dorks['response']['dorks']) @@ -48,6 +50,7 @@ def test_return_dorks_exception(self): async def test(): self.data = await self.handler.get_dorks() + with self.assertRaises(Exception): self.loop.run_until_complete(test()) diff --git a/snare/tests/test_handle_html_content.py b/snare/tests/test_handle_html_content.py index 984a6b22..7ab200bf 100644 --- a/snare/tests/test_handle_html_content.py +++ b/snare/tests/test_handle_html_content.py @@ -36,6 +36,7 @@ def test_handle_content(self): async def test(): self.return_content = await self.handler.handle_content(self.content) + self.loop.run_until_complete(test()) soup = BeautifulSoup(self.return_content, "html.parser") return_content = soup.decode("utf-8") @@ -46,6 +47,7 @@ def test_handle_content_no_dorks(self): async def test(): self.return_content = await self.handler.handle_content(self.content) + self.loop.run_until_complete(test()) soup = BeautifulSoup(self.return_content, "html.parser") self.return_content = soup.decode("utf-8") @@ -57,6 +59,7 @@ def test_handle_content_exception(self): async def test(): self.return_content = await self.handler.handle_content(self.content) + with self.assertRaises(IndexError): self.loop.run_until_complete(test()) diff --git a/snare/tests/test_handle_request.py b/snare/tests/test_handle_request.py index 18f7590e..5a2763f6 100644 --- a/snare/tests/test_handle_request.py +++ b/snare/tests/test_handle_request.py @@ -24,7 +24,7 @@ def setUp(self): os.makedirs(self.main_page_path) self.page_dir = self.main_page_path.rsplit('/')[-1] args = run_args.parse_args(['--page-dir', self.page_dir]) - uuid = ('9c10172f-7ce2-4fb4-b1c6-abc70141db56').encode('utf-8') + uuid = '9c10172f-7ce2-4fb4-b1c6-abc70141db56'.encode('utf-8') args.tanner = 'tanner.mushmush.org' args.no_dorks = True args.server_header = "test_server" @@ -66,30 +66,30 @@ def setUp(self): return_value=(self.content, self.content_type, self.data['headers'], self.data['headers']['status'])) def test_create_request_data(self): - async def test(): await self.handler.handle_request(self.request) + self.loop.run_until_complete(test()) self.handler.tanner_handler.create_data.assert_called_with(self.request, 200) def test_submit_request_data(self): - async def test(): await self.handler.handle_request(self.request) + self.loop.run_until_complete(test()) self.handler.tanner_handler.submit_data.assert_called_with(self.data) def test_submit_request_slurp(self): - async def test(): await self.handler.handle_request(self.request) + self.loop.run_until_complete(test()) self.handler.submit_slurp.assert_called_with(self.request.path_qs) def test_parse_response(self): - async def test(): await self.handler.handle_request(self.request) + self.loop.run_until_complete(test()) self.handler.tanner_handler.parse_tanner_response.assert_called_with(self.request.path_qs, {'type': 1}) diff --git a/snare/tests/test_parse_tanner_response.py b/snare/tests/test_parse_tanner_response.py index 6219526a..b932cfe8 100644 --- a/snare/tests/test_parse_tanner_response.py +++ b/snare/tests/test_parse_tanner_response.py @@ -48,6 +48,7 @@ def test_parse_type_one(self): async def test(): (self.res1, self.res2, self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + self.loop.run_until_complete(test()) real_result = [self.res1, self.res2, self.res3, self.res4] expected_result = [self.page_content, self.content_type, {}, 200] @@ -66,6 +67,7 @@ def test_parse_type_two(self): async def test(): (self.res1, self.res2, self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + self.loop.run_until_complete(test()) real_result = [self.res1, self.res2, self.res3, self.res4] expected_result = [self.expected_content, self.content_type, {}, 200] @@ -85,6 +87,7 @@ def test_parse_type_three(self): async def test(): (self.res1, self.res2, self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + self.loop.run_until_complete(test()) real_result = [self.res1, self.res2, self.res3, self.res4] expected_result = [self.expected_content, None, {}, 200] @@ -98,6 +101,7 @@ def test_call_handle_html(self): async def test(): (self.res1, self.res2, self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + self.loop.run_until_complete(test()) self.handler.html_handler.handle_content.assert_called_with(self.call_content) @@ -109,6 +113,7 @@ def test_parse_exception(self): async def test(): (self.res1, self.res2, self.res3, self.res4) = await self.handler.parse_tanner_response(self.requested_name, self.detection) + with self.assertRaises(KeyError): self.loop.run_until_complete(test()) diff --git a/snare/tests/test_submit_data.py b/snare/tests/test_submit_data.py index d3e61133..2d7283a0 100644 --- a/snare/tests/test_submit_data.py +++ b/snare/tests/test_submit_data.py @@ -38,7 +38,7 @@ def setUp(self): timer=None, request_info=None, traces=None, loop=self.loop, session=None ) - ) + ) uuid = "test_uuid" args.tanner = "tanner.mushmush.org" args.no_dorks = True @@ -50,6 +50,7 @@ def test_post_data(self): async def test(): self.result = await self.handler.submit_data(self.data) + self.loop.run_until_complete(test()) aiohttp.ClientSession.post.assert_called_with( 'http://tanner.mushmush.org:8090/event', data=json.dumps(self.data), timeout=10.0 @@ -60,6 +61,7 @@ def test_event_result(self): async def test(): self.result = await self.handler.submit_data(self.data) + self.loop.run_until_complete(test()) self.assertEquals(self.result, dict(detection={'type': 1}, sess_uuid="test_uuid")) @@ -68,6 +70,7 @@ def test_event_result_exception(self): async def test(): self.result = await self.handler.submit_data(self.data) + with self.assertRaises(Exception): self.loop.run_until_complete(test()) diff --git a/snare/utils/page_path_generator.py b/snare/utils/page_path_generator.py index f73623d6..da9cfc3e 100644 --- a/snare/utils/page_path_generator.py +++ b/snare/utils/page_path_generator.py @@ -9,6 +9,6 @@ def directory_generator(size=9, chars=string.ascii_lowercase + string.digits): def generate_unique_path(): path = '/opt/snare/pages/' + directory_generator() - while(os.path.exists(path)): + while os.path.exists(path): path = '/opt/snare/pages/' + directory_generator() return path diff --git a/snare/utils/snare_helpers.py b/snare/utils/snare_helpers.py old mode 100644 new mode 100755 index 98855847..9aac57d0 --- a/snare/utils/snare_helpers.py +++ b/snare/utils/snare_helpers.py @@ -63,12 +63,12 @@ def add_meta_tag(page_dir, index_page, config): main_page = main.read() soup = BeautifulSoup(main_page, 'html.parser') - if (google_content and soup.find("meta", attrs={"name": "google-site-verification"}) is None): + if google_content and soup.find("meta", attrs={"name": "google-site-verification"}) is None: google_meta = soup.new_tag('meta') google_meta.attrs['name'] = 'google-site-verification' google_meta.attrs['content'] = google_content soup.head.append(google_meta) - if (bing_content and soup.find("meta", attrs={"name": "msvalidate.01"}) is None): + if bing_content and soup.find("meta", attrs={"name": "msvalidate.01"}) is None: bing_meta = soup.new_tag('meta') bing_meta.attrs['name'] = 'msvalidate.01' bing_meta.attrs['content'] = bing_content