Add HTTPFlow.mode to record the HTTP proxy layer mode

This commit is contained in:
Aldo Cortesi 2016-11-12 10:59:57 +13:00
parent 5be35d258f
commit 00492919e7
3 changed files with 13 additions and 4 deletions

View File

@ -53,7 +53,7 @@ class HTTPRequest(http.Request):
def get_state(self): def get_state(self):
state = super().get_state() state = super().get_state()
state.update( state.update(
is_replay=self.is_replay, is_replay=self.is_replay
) )
return state return state
@ -143,7 +143,7 @@ class HTTPFlow(flow.Flow):
transaction. transaction.
""" """
def __init__(self, client_conn, server_conn, live=None): def __init__(self, client_conn, server_conn, live=None, mode="regular"):
super().__init__("http", client_conn, server_conn, live) super().__init__("http", client_conn, server_conn, live)
self.request = None # type: HTTPRequest self.request = None # type: HTTPRequest
@ -163,11 +163,14 @@ class HTTPFlow(flow.Flow):
""":py:class:`ClientConnection` object """ """:py:class:`ClientConnection` object """
self.intercepted = False # type: bool self.intercepted = False # type: bool
""" Is this flow currently being intercepted? """ """ Is this flow currently being intercepted? """
self.mode = mode
""" What mode was the proxy layer in when receiving this request? """
_stateobject_attributes = flow.Flow._stateobject_attributes.copy() _stateobject_attributes = flow.Flow._stateobject_attributes.copy()
_stateobject_attributes.update( _stateobject_attributes.update(
request=HTTPRequest, request=HTTPRequest,
response=HTTPResponse response=HTTPResponse,
mode=str
) )
def __repr__(self): def __repr__(self):

View File

@ -69,6 +69,7 @@ def convert_018_019(data):
data["client_conn"]["sni"] = None data["client_conn"]["sni"] = None
data["client_conn"]["cipher_name"] = None data["client_conn"]["cipher_name"] = None
data["client_conn"]["tls_version"] = None data["client_conn"]["tls_version"] = None
data["mode"] = "regular"
data["metadata"] = dict() data["metadata"] = dict()
return data return data

View File

@ -159,7 +159,12 @@ class HttpLayer(base.Layer):
self.__initial_server_tls = self.server_tls self.__initial_server_tls = self.server_tls
self.__initial_server_conn = self.server_conn self.__initial_server_conn = self.server_conn
while True: while True:
flow = http.HTTPFlow(self.client_conn, self.server_conn, live=self) flow = http.HTTPFlow(
self.client_conn,
self.server_conn,
live=self,
mode=self.mode.name
)
if not self._process_flow(flow): if not self._process_flow(flow):
return return