Esempio n. 1
0
def test_base_ctor() -> None:
    message = RawRequestMessage('GET', '/path/to?a=1&b=2', HttpVersion(1, 1),
                                CIMultiDictProxy(CIMultiDict()), (), False,
                                False, False, False, URL('/path/to?a=1&b=2'))

    req = BaseRequest(message, mock.Mock(), mock.Mock(), mock.Mock(),
                      mock.Mock(), mock.Mock())

    assert 'GET' == req.method
    assert HttpVersion(1, 1) == req.version
    assert req.host == socket.getfqdn()
    assert '/path/to?a=1&b=2' == req.path_qs
    assert '/path/to' == req.path
    assert 'a=1&b=2' == req.query_string
    assert CIMultiDict() == req.headers
    assert () == req.raw_headers

    get = req.query
    assert MultiDict([('a', '1'), ('b', '2')]) == get
    # second call should return the same object
    assert get is req.query

    assert req.keep_alive

    assert req
 def setUp(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)
     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')
     args.no_dorks = True
     self.handler = TannerHandler(args, meta, snare_uuid)
     headers = {
         'Host': 'test_host',
         'status': 200,
         'Cookie': 'sess_uuid=prev_test_uuid; test_cookie=test'
     }
     message = RawRequestMessage(method='POST',
                                 path='/',
                                 version=HttpVersion(major=1, minor=1),
                                 headers=headers,
                                 raw_headers=None,
                                 should_close=None,
                                 compression=None,
                                 upgrade=None,
                                 chunked=None,
                                 url=URL('http://test_url/'))
     loop = asyncio.get_event_loop()
     RequestHandler = Mock()
     protocol = RequestHandler()
     self.request = web.Request(message=message,
                                payload=None,
                                protocol=protocol,
                                payload_writer=None,
                                task='POST',
                                loop=loop)
     self.request.transport.get_extra_info = Mock(
         return_value=(['test_ip', 'test_port']))
     self.response_status = "test_status"
     self.data = None
     self.expected_data = {
         'method': 'POST',
         'path': 'http://test_url/',
         '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'
         }
     }
 def setUp(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)
     page_dir = self.main_page_path.rsplit("/")[-1]
     args = run_args.parse_args(["--page-dir", page_dir])
     args_dict = vars(args)
     args_dict["full_page_path"] = self.main_page_path
     snare_uuid = "9c10172f-7ce2-4fb4-b1c6-abc70141db56".encode("utf-8")
     args.no_dorks = True
     self.handler = TannerHandler(args, meta, snare_uuid)
     headers = {
         "Host": "test_host",
         "status": 200,
         "Cookie": "sess_uuid=prev_test_uuid; test_cookie=test",
     }
     message = RawRequestMessage(
         method="POST",
         path="/",
         version=HttpVersion(major=1, minor=1),
         headers=headers,
         raw_headers=None,
         should_close=None,
         compression=None,
         upgrade=None,
         chunked=None,
         url=URL("http://test_url/"),
     )
     loop = asyncio.get_event_loop()
     RequestHandler = Mock()
     protocol = RequestHandler()
     self.request = web.Request(
         message=message,
         payload=None,
         protocol=protocol,
         payload_writer=None,
         task="POST",
         loop=loop,
     )
     self.request.transport.get_extra_info = Mock(return_value=(["test_ip", "test_port"]))
     self.response_status = "test_status"
     self.data = None
     self.expected_data = {
         "method": "POST",
         "path": "http://test_url/",
         "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"},
     }
 def setUp(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]
     args = run_args.parse_args(['--page-dir', self.page_dir])
     args_dict = vars(args)
     args_dict['full_page_path'] = self.main_page_path
     uuid = '9c10172f-7ce2-4fb4-b1c6-abc70141db56'.encode('utf-8')
     args.tanner = 'tanner.mushmush.org'
     args.no_dorks = True
     args.server_header = "test_server"
     args.slurp_enabled = True
     self.handler = HttpRequestHandler(meta, args, uuid)
     self.request_data = {
         'method': 'GET',
         'path': '/',
         'headers': {
             'Host': 'test_host',
             'Content-Type': 'test_type',
         },
         'status': 200,
         'cookies': {
             'sess_uuid': 'prev_test_uuid',
         },
     }
     self.loop = asyncio.new_event_loop()
     self.response_content = '<html><body></body></html>'
     self.response_headers = multidict.CIMultiDict([("Content-Type", "text/html")])
     self.response_status = 200
     event_result = dict(response=dict(message=dict(detection={'type': 1}, sess_uuid="test_uuid")))
     RequestHandler = Mock()
     protocol = RequestHandler()
     message = RawRequestMessage(
         method='POST', path='/', version=HttpVersion(major=1, minor=1), headers=self.request_data['headers'],
         raw_headers=None, should_close=None, compression=None, upgrade=None, chunked=None,
         url=URL('http://test_url/')
     )
     self.request = web.Request(
         message=message, payload=None, protocol=protocol, payload_writer=None,
         task='POST', loop=self.loop
     )
     self.handler.tanner_handler.create_data = Mock(return_value=self.request_data)
     self.handler.tanner_handler.submit_data = AsyncMock(return_value=event_result)
     self.handler.submit_slurp = AsyncMock()
     web.Response.add_header = Mock()
     web.Response.write = Mock()
     web.Response.send_headers = Mock()
     web.Response.write_eof = AsyncMock()
     aiohttp.streams.EmptyStreamReader.read = AsyncMock(
         return_value=b'con1=test1&con2=test2')
     self.handler.tanner_handler.parse_tanner_response = AsyncMock(
         return_value=(self.response_content, self.response_headers, self.response_status))
Esempio n. 5
0
def test_base_ctor() -> None:
    message = RawRequestMessage(
        "GET",
        "/path/to?a=1&b=2",
        HttpVersion(1, 1),
        CIMultiDictProxy(CIMultiDict()),
        (),
        False,
        False,
        False,
        False,
        URL("/path/to?a=1&b=2"),
    )

    req = web.BaseRequest(message, mock.Mock(), mock.Mock(), mock.Mock(),
                          mock.Mock(), mock.Mock())

    assert "GET" == req.method
    assert HttpVersion(1, 1) == req.version
    # MacOS may return CamelCased host name, need .lower()
    # FQDN can be wider than host, e.g.
    # 'fv-az397-495' in 'fv-az397-495.internal.cloudapp.net'
    assert req.host.lower() in socket.getfqdn().lower()
    assert "/path/to?a=1&b=2" == req.path_qs
    assert "/path/to" == req.path
    assert "a=1&b=2" == req.query_string
    assert CIMultiDict() == req.headers
    assert () == req.raw_headers

    get = req.query
    assert MultiDict([("a", "1"), ("b", "2")]) == get
    # second call should return the same object
    assert get is req.query

    assert req.keep_alive

    assert "__dict__" not in dir(req)

    assert req
Esempio n. 6
0
def test_base_ctor() -> None:
    message = RawRequestMessage(
        "GET",
        "/path/to?a=1&b=2",
        HttpVersion(1, 1),
        CIMultiDictProxy(CIMultiDict()),
        (),
        False,
        False,
        False,
        False,
        URL("/path/to?a=1&b=2"),
    )

    req = web.BaseRequest(
        message, mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock()
    )

    assert "GET" == req.method
    assert HttpVersion(1, 1) == req.version
    assert req.host == socket.getfqdn()
    assert "/path/to?a=1&b=2" == req.path_qs
    assert "/path/to" == req.path
    assert "a=1&b=2" == req.query_string
    assert CIMultiDict() == req.headers
    assert () == req.raw_headers

    get = req.query
    assert MultiDict([("a", "1"), ("b", "2")]) == get
    # second call should return the same object
    assert get is req.query

    assert req.keep_alive

    assert "__dict__" not in dir(req)

    assert req
 def setUp(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]
     args = run_args.parse_args(["--page-dir", self.page_dir])
     args_dict = vars(args)
     args_dict["full_page_path"] = self.main_page_path
     uuid = "9c10172f-7ce2-4fb4-b1c6-abc70141db56".encode("utf-8")
     args.tanner = "tanner.mushmush.org"
     args.no_dorks = True
     args.server_header = "test_server"
     args.slurp_enabled = True
     self.handler = HttpRequestHandler(meta, args, uuid)
     self.request_data = {
         "method": "GET",
         "path": "/",
         "headers": {
             "Host": "test_host",
             "Content-Type": "test_type",
         },
         "status": 200,
         "cookies": {
             "sess_uuid": "prev_test_uuid",
         },
     }
     self.loop = asyncio.new_event_loop()
     self.response_content = "<html><body></body></html>"
     self.response_headers = multidict.CIMultiDict([("Content-Type",
                                                     "text/html")])
     self.response_status = 200
     event_result = dict(response=dict(
         message=dict(detection={"type": 1}, sess_uuid="test_uuid")))
     RequestHandler = Mock()
     protocol = RequestHandler()
     message = RawRequestMessage(
         method="POST",
         path="/",
         version=HttpVersion(major=1, minor=1),
         headers=self.request_data["headers"],
         raw_headers=None,
         should_close=None,
         compression=None,
         upgrade=None,
         chunked=None,
         url=URL("http://test_url/"),
     )
     self.request = web.Request(
         message=message,
         payload=None,
         protocol=protocol,
         payload_writer=None,
         task="POST",
         loop=self.loop,
     )
     self.handler.tanner_handler.create_data = Mock(
         return_value=self.request_data)
     self.handler.tanner_handler.submit_data = AsyncMock(
         return_value=event_result)
     self.handler.submit_slurp = AsyncMock()
     web.Response.add_header = Mock()
     web.Response.write = Mock()
     web.Response.send_headers = Mock()
     web.Response.write_eof = AsyncMock()
     aiohttp.streams.EmptyStreamReader.read = AsyncMock(
         return_value=b"con1=test1&con2=test2")
     self.handler.tanner_handler.parse_tanner_response = AsyncMock(
         return_value=(
             self.response_content,
             self.response_headers,
             self.response_status,
         ))