diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-02-01 15:25:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-01 15:25:51 +0100 |
commit | 212d9f1b9848fe347ef5924c2e7431180c550cb6 (patch) | |
tree | 80028cb6d7b632ea850ac46fa4a6c20e1bbfc012 /examples/complex/dns_spoofing.py | |
parent | cf991ba4e25c59343084b5782f499fbada323f64 (diff) | |
parent | 9e3f06b7f27da778c730bbf912e3f1709ed9f058 (diff) | |
download | mitmproxy-212d9f1b9848fe347ef5924c2e7431180c550cb6.tar.gz mitmproxy-212d9f1b9848fe347ef5924c2e7431180c550cb6.tar.bz2 mitmproxy-212d9f1b9848fe347ef5924c2e7431180c550cb6.zip |
Merge pull request #1948 from amm0nite/fix_dns_spoofing_example
Fix for dns_spoofing.py example
Diffstat (limited to 'examples/complex/dns_spoofing.py')
-rw-r--r-- | examples/complex/dns_spoofing.py | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/examples/complex/dns_spoofing.py b/examples/complex/dns_spoofing.py index c020047f..1fb59f74 100644 --- a/examples/complex/dns_spoofing.py +++ b/examples/complex/dns_spoofing.py @@ -28,22 +28,35 @@ import re parse_host_header = re.compile(r"^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$") -def request(flow): - if flow.client_conn.ssl_established: - flow.request.scheme = "https" - sni = flow.client_conn.connection.get_servername() - port = 443 - else: - flow.request.scheme = "http" - sni = None - port = 80 - - host_header = flow.request.pretty_host - m = parse_host_header.match(host_header) - if m: - host_header = m.group("host").strip("[]") - if m.group("port"): - port = int(m.group("port")) - - flow.request.host = sni or host_header - flow.request.port = port +class Rerouter: + def requestheaders(self, flow): + """ + The original host header is retrieved early + before flow.request is replaced by mitmproxy new outgoing request + """ + flow.metadata["original_host"] = flow.request.headers["Host"] + + def request(self, flow): + if flow.client_conn.ssl_established: + flow.request.scheme = "https" + sni = flow.client_conn.connection.get_servername() + port = 443 + else: + flow.request.scheme = "http" + sni = None + port = 80 + + host_header = flow.metadata["original_host"] + m = parse_host_header.match(host_header) + if m: + host_header = m.group("host").strip("[]") + if m.group("port"): + port = int(m.group("port")) + + flow.request.headers["Host"] = host_header + flow.request.host = sni or host_header + flow.request.port = port + + +def start(): + return Rerouter() |