Beispiel #1
0
 def setUp(self):
     self.meta = {}
     run_args = argparse.ArgumentParser()
     run_args.add_argument("--tanner")
     run_args.add_argument("--page-dir")
     run_args.add_argument("--no-dorks")
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.content = '''
                       <html>
                             <body>
                             <p style="color:red;">A paragraph to be tested</p>
                             </body>
                       </html>
                    '''
     self.expected_content = '<html>\n <body>\n  <p style="color: red">\n'
     self.expected_content += '   <a href="test_dork1" style="color:red;text-decoration:none;cursor:text;">\n'
     self.expected_content += '    A\n   </a>\n   paragraph to be tested\n  </p>\n </body>\n</html>\n'
     self.no_dorks_content = '<html>\n <body>\n  <p style="color:red;">\n   A paragraph to be tested\n'
     self.no_dorks_content += '  </p>\n </body>\n</html>\n'
     self.args = run_args.parse_args(['--page-dir', self.page_dir])
     self.loop = asyncio.new_event_loop()
     self.handler = HttpRequestHandler(self.meta, self.args)
     self.handler.dir = self.main_page_path
Beispiel #2
0
 def setUp(self):
     self.meta = {}
     run_args = argparse.ArgumentParser()
     run_args.add_argument("--tanner")
     run_args.add_argument("--page-dir")
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.args = run_args.parse_args(['--page-dir', self.page_dir])
     self.loop = asyncio.new_event_loop()
     self.status = 500
     self.message = "test"
     self.payload = "test"
     self.exc = "[Errno 0] test"
     self.headers = "test"
     self.reason = "test"
     self.data = dict(method='GET',
                      path='/',
                      headers="test_headers",
                      uuid="test_uuid",
                      peer="test_peer",
                      status="test_status",
                      error=self.exc)
     aiohttp.server.ServerHttpProtocol.handle_error = Mock()
     self.handler = HttpRequestHandler(self.meta, self.args)
     self.handler.create_data = Mock(return_value=self.data)
     self.handler.submit_data = AsyncMock()
Beispiel #3
0
 def setUp(self):
     run_args = argparse.ArgumentParser()
     run_args.add_argument("--tanner")
     run_args.add_argument("--page-dir")
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.meta_content = {
         "/index.html": {
             "hash": "hash_name",
             "content_type": "text/html"
         }
     }
     self.page_content = "<html><body></body></html>"
     self.content_type = "text/html"
     with open(os.path.join(self.main_page_path, "hash_name"), 'w') as f:
         f.write(self.page_content)
     with open(os.path.join(self.main_page_path, "meta.json"), 'w') as f:
         json.dump(self.meta_content, f)
     self.args = run_args.parse_args(['--page-dir', self.page_dir])
     self.requested_name = '/'
     self.loop = asyncio.new_event_loop()
     self.handler = HttpRequestHandler(self.meta_content, self.args)
     self.handler.run_args.index_page = '/index.html'
     self.handler.handle_html_content = AsyncMock(
         return_value=self.page_content)
Beispiel #4
0
 def setUp(self):
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.content = '<html><head>title</head><body>sample</body></html>'
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.index_page = "index.html"
     with open(os.path.join(self.main_page_path, 'index.html'), 'w') as f:
         f.write(self.content)
Beispiel #5
0
 def setUp(self):
     self.meta = {}
     run_args = argparse.ArgumentParser()
     run_args.add_argument("--tanner")
     run_args.add_argument("--page-dir")
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.args = run_args.parse_args(['--page-dir', self.page_dir])
     snare.snare_uuid = (
         '9c10172f-7ce2-4fb4-b1c6-abc70141db56').encode('utf-8')
     self.handler = HttpRequestHandler(self.meta, self.args)
     self.headers = {
         'Host': 'test_host',
         'status': 200,
         'Cookie': 'sess_uuid=prev_test_uuid; test_cookie=test'
     }
     self.request = aiohttp.protocol.RawRequestMessage(
         method='POST',
         path='/',
         version=HttpVersion(major=1, minor=1),
         headers=self.headers,
         raw_headers=None,
         should_close=None,
         compression=None)
     self.response_status = "test_status"
     self.expected_data = {
         'method': 'POST',
         'path': '/',
         'headers': {
             'Host': 'test_host',
             'status': 200,
             'Cookie': 'sess_uuid=prev_test_uuid; test_cookie=test'
         },
         'uuid': '9c10172f-7ce2-4fb4-b1c6-abc70141db56',
         'peer': {
             'ip': 'test_ip',
             'port': 'test_port'
         },
         'status': 'test_status',
         'cookies': {
             'sess_uuid': 'prev_test_uuid',
             ' test_cookie': 'test'
         }
     }
     asyncio.BaseTransport = Mock()
     self.handler.transport = asyncio.BaseTransport()
     self.handler.transport.get_extra_info = Mock(
         return_value=['test_ip', 'test_port'])
Beispiel #6
0
 def setUp(self):
     self.meta = {}
     run_args = argparse.ArgumentParser()
     run_args.add_argument("--tanner")
     run_args.add_argument("--page-dir")
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.args = run_args.parse_args(['--page-dir', self.page_dir])
     self.dorks = dict(response={'dorks': "test_dorks"})
     self.loop = asyncio.new_event_loop()
     aiohttp.ClientSession.get = AsyncMock(
         return_value=aiohttp.ClientResponse(
             url=yarl.URL("http://www.example.com"), method="GET"))
     self.handler = HttpRequestHandler(self.meta, self.args)
     self.handler.run_args.tanner = "tanner.mushmush.org"
Beispiel #7
0
 def setUp(self):
     self.meta = {}
     run_args = argparse.ArgumentParser()
     run_args.add_argument("--tanner")
     run_args.add_argument("--page-dir")
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.args = run_args.parse_args(['--page-dir', self.page_dir])
     self.loop = asyncio.new_event_loop()
     self.handler = HttpRequestHandler(self.meta, self.args)
     self.handler.run_args.server_header = "test_server"
     self.handler.run_args.slurp_enabled = True
     self.data = {
         'method': 'GET', 'path': '/',
         'headers': {
             'Host': 'test_host', 'status': 200
         },
         'cookies': {
             'sess_uuid': 'prev_test_uuid'
         }
     }
     self.content = '<html><body></body></html>'
     self.content_type = 'test_type'
     self.event_result = dict(response=dict(message=dict(detection={'type': 1}, sess_uuid="test_uuid")))
     self.request = aiohttp.protocol.RawRequestMessage(
         method='POST', path='/', version=HttpVersion(major=1, minor=1), headers=self.data['headers'],
         raw_headers=None, should_close=None, compression=None)
     self.handler.create_data = Mock(return_value=self.data)
     self.handler.submit_data = AsyncMock(return_value=self.event_result)
     self.handler.submit_slurp = AsyncMock()
     self.payload = aiohttp.streams.EmptyStreamReader()
     aiohttp.Response.add_header = Mock()
     aiohttp.Response.write = Mock()
     aiohttp.Response.send_headers = Mock()
     aiohttp.Response.write_eof = AsyncMock()
     aiohttp.streams.EmptyStreamReader.read = AsyncMock(return_value=b'con1=test1&con2=test2')
     self.handler.parse_tanner_response = AsyncMock(
         return_value=(self.content, self.content_type, self.data['headers'], self.data['headers']['status']))
Beispiel #8
0
 def setUp(self):
     self.meta = {}
     run_args = argparse.ArgumentParser()
     run_args.add_argument("--tanner")
     run_args.add_argument("--page-dir")
     self.main_page_path = generate_unique_path()
     os.makedirs(self.main_page_path)
     self.page_dir = self.main_page_path.rsplit('/')[-1]
     self.args = run_args.parse_args(['--page-dir', self.page_dir])
     self.loop = asyncio.new_event_loop()
     self.data = {
         'method': 'GET',
         'path': '/',
         'headers': {
             'Host': 'test_host',
             'Connection': 'keep-alive',
             'Upgrade-Insecure-Requests': '1',
             'User-Agent': 'test_agent',
             'Accept': 'text/html',
             'Accept-Encoding': 'test_encoding',
             'Accept-Language': 'test_lang',
             'Cookie': 'test_cookie',
             'uuid': 'test_uuid',
             'peer': {
                 'ip': '::1',
                 'port': 80
             },
             'status': 200,
             'cookies': 'test_cookies',
             ' sess_uuid': 'test_uuid'
         }
     }
     aiohttp.ClientSession.post = AsyncMock(
         return_value=aiohttp.ClientResponse(
             url=yarl.URL("http://www.example.com"), method="GET"))
     self.handler = HttpRequestHandler(self.meta, self.args)
     self.handler.run_args.tanner = "tanner.mushmush.org"