From 1f98c7be4f3fa6eb56e7760fb99dfaaadbf0f541 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 3 Aug 2017 16:44:17 +0200 Subject: [PATCH 1/2] improve docstring for rawtcp --- mitmproxy/options.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 20151c194..1ecdd6a63 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -173,7 +173,7 @@ class Options(optmanager.OptManager): ) self.add_option( "server", bool, True, - "Start a proxy server." + "Start a proxy server. Enabled by default." ) self.add_option( "server_replay_nopop", bool, False, @@ -406,8 +406,9 @@ class Options(optmanager.OptManager): ) self.add_option( "rawtcp", bool, False, - "Enable/disable experimental raw TCP support. " - "Disabled by default. " + "Enable/disable experimental raw TCP support. TCP connections starting with non-ascii " + "bytes are treated as if they would match tcp_hosts. The heuristic is very rough, use " + "with caution. Disabled by default. " ) self.add_option( From 9ca6785d40ebe0293f36683250d72998f438bba9 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 3 Aug 2017 16:46:53 +0200 Subject: [PATCH 2/2] Revert "Remove promotion to raw TCP based on heuristics" This reverts commit fbaade429845546d751110caa0f886f7b1a62717 for the following reasons: - The commit only removed the proxy logic, while keeping the corresponding command line options etc. intact. That is quite confusing. - The switch is (and has been) off-by-default and the option help now clearly states that this needs to be used with caution. I'd argue that constrains the potential danger. - I have a specific use case that needs this, and implementing it as an addon is rather difficult at the moment. That being said, this revert is a rather pragmatic temporary decision, the functionality should clearly be made more explicit and protocol switching should be moved to an addon. --- mitmproxy/proxy/root_context.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mitmproxy/proxy/root_context.py b/mitmproxy/proxy/root_context.py index 3d21b13c3..c0ec64c97 100644 --- a/mitmproxy/proxy/root_context.py +++ b/mitmproxy/proxy/root_context.py @@ -104,7 +104,16 @@ class RootContext: if alpn == b'http/1.1': return protocol.Http1Layer(top_layer, http.HTTPMode.transparent) - # 6. Assume HTTP1 by default + # 6. Check for raw tcp mode + is_ascii = ( + len(d) == 3 and + # expect A-Za-z + all(65 <= x <= 90 or 97 <= x <= 122 for x in d) + ) + if self.config.options.rawtcp and not is_ascii: + return protocol.RawTCPLayer(top_layer) + + # 7. Assume HTTP1 by default return protocol.Http1Layer(top_layer, http.HTTPMode.transparent) def log(self, msg, level, subs=()):