diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-07-01 17:17:16 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-07-01 17:17:16 -0700 |
commit | fa7246279817b7c01448fd4059c8d2be34e84f8b (patch) | |
tree | c223573d8b3fd24c2e5dbe037df3f0bf35265884 /mitmproxy | |
parent | 536c7acd13426d42dc863ae8b50e6c3a4cb2e858 (diff) | |
download | mitmproxy-fa7246279817b7c01448fd4059c8d2be34e84f8b.tar.gz mitmproxy-fa7246279817b7c01448fd4059c8d2be34e84f8b.tar.bz2 mitmproxy-fa7246279817b7c01448fd4059c8d2be34e84f8b.zip |
fix tcp message handling
Diffstat (limited to 'mitmproxy')
-rw-r--r-- | mitmproxy/console/master.py | 14 | ||||
-rw-r--r-- | mitmproxy/contentviews.py | 2 | ||||
-rw-r--r-- | mitmproxy/dump.py | 21 | ||||
-rw-r--r-- | mitmproxy/flow/master.py | 9 |
4 files changed, 33 insertions, 13 deletions
diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 5fd51f4b..95c9704d 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -30,7 +30,7 @@ from mitmproxy.console import palettes from mitmproxy.console import signals from mitmproxy.console import statusbar from mitmproxy.console import window -from netlib import tcp +from netlib import tcp, strutils EVENTLOG_SIZE = 500 @@ -798,6 +798,18 @@ class ConsoleMaster(flow.FlowMaster): return f @controller.handler + def tcp_message(self, f): + super(ConsoleMaster, self).tcp_message(f) + message = f.messages[-1] + direction = "->" if message.from_client else "<-" + self.add_event("{client} {direction} tcp {direction} {server}".format( + client=repr(f.client_conn.address), + server=repr(f.server_conn.address), + direction=direction, + ), "info") + self.add_event(strutils.bytes_to_escaped_str(message.content), "debug") + + @controller.handler def script_change(self, script): if super(ConsoleMaster, self).script_change(script): signals.status_message.send(message='"{}" reloaded.'.format(script.filename)) diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py index 7c9e4ba1..de88c9ea 100644 --- a/mitmproxy/contentviews.py +++ b/mitmproxy/contentviews.py @@ -600,7 +600,7 @@ def safe_to_print(lines, encoding="utf8"): try: text = strutils.clean_bin(text.decode(encoding, "strict")) except UnicodeDecodeError: - text = strutils.clean_bin(text).decode(encoding, "strict") + text = strutils.clean_bin(text) clean_line.append((style, text)) yield clean_line diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index cc6896ed..6670be9b 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -178,7 +178,7 @@ class DumpMaster(flow.FlowMaster): click.secho(text, file=self.outfile, **style) def _echo_message(self, message): - if self.o.flow_detail >= 2: + if self.o.flow_detail >= 2 and hasattr(message, "headers"): headers = "\r\n".join( "{}: {}".format( click.style(strutils.bytes_to_escaped_str(k), fg="blue", bold=True), @@ -196,7 +196,7 @@ class DumpMaster(flow.FlowMaster): type, lines = contentviews.get_content_view( contentviews.get("Auto"), message.content, - headers=message.headers + headers=getattr(message, "headers", None) ) except exceptions.ContentViewException: s = "Content viewer failed: \n" + traceback.format_exc() @@ -204,7 +204,7 @@ class DumpMaster(flow.FlowMaster): type, lines = contentviews.get_content_view( contentviews.get("Raw"), message.content, - headers=message.headers + headers=getattr(message, "headers", None) ) styles = dict( @@ -352,6 +352,21 @@ class DumpMaster(flow.FlowMaster): self._process_flow(f) return f + @controller.handler + def tcp_message(self, f): + super(DumpMaster, self).tcp_message(f) + + if self.o.flow_detail == 0: + return + message = f.messages[-1] + direction = "->" if message.from_client else "<-" + self.echo("{client} {direction} tcp {direction} {server}".format( + client=repr(f.client_conn.address), + server=repr(f.server_conn.address), + direction=direction, + )) + self._echo_message(message) + def run(self): # pragma: no cover if self.o.rfile and not self.o.keepserving: self.unload_scripts() # make sure to trigger script unload events. diff --git a/mitmproxy/flow/master.py b/mitmproxy/flow/master.py index 289102a1..efb5d013 100644 --- a/mitmproxy/flow/master.py +++ b/mitmproxy/flow/master.py @@ -499,15 +499,8 @@ class FlowMaster(controller.Master): @controller.handler def tcp_message(self, flow): + # type: (TCPFlow) -> None self.run_scripts("tcp_message", flow) - message = flow.messages[-1] - direction = "->" if message.from_client else "<-" - self.add_event("{client} {direction} tcp {direction} {server}".format( - client=repr(flow.client_conn.address), - server=repr(flow.server_conn.address), - direction=direction, - ), "info") - self.add_event(strutils.clean_bin(message.content), "debug") @controller.handler def tcp_error(self, flow): |