aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-08-04 04:02:12 +0200
committerGitHub <noreply@github.com>2017-08-04 04:02:12 +0200
commite0ca9c3a982a460c675865cd798840f51f4321f1 (patch)
tree8a1d6aa4cb236b30491aa7bba350dc6dd9f62fd1
parent79354235a687ce8cd4b855b3b292fe3c432660c7 (diff)
parent9ca6785d40ebe0293f36683250d72998f438bba9 (diff)
downloadmitmproxy-e0ca9c3a982a460c675865cd798840f51f4321f1.tar.gz
mitmproxy-e0ca9c3a982a460c675865cd798840f51f4321f1.tar.bz2
mitmproxy-e0ca9c3a982a460c675865cd798840f51f4321f1.zip
Merge pull request #2499 from mhils/rawtcp
Re-add rawtcp mode.
-rw-r--r--mitmproxy/options.py7
-rw-r--r--mitmproxy/proxy/root_context.py11
2 files changed, 14 insertions, 4 deletions
diff --git a/mitmproxy/options.py b/mitmproxy/options.py
index 20151c19..1ecdd6a6 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(
diff --git a/mitmproxy/proxy/root_context.py b/mitmproxy/proxy/root_context.py
index 3d21b13c..c0ec64c9 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=()):