From c2c6050df398ecb922cf040ea7c5c3ab8cdeac03 Mon Sep 17 00:00:00 2001 From: Ammonite Date: Sun, 29 Jan 2017 14:33:53 +0100 Subject: Store original host in flow metadata --- examples/complex/dns_spoofing.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/complex/dns_spoofing.py b/examples/complex/dns_spoofing.py index 1d703537..5e6cf978 100644 --- a/examples/complex/dns_spoofing.py +++ b/examples/complex/dns_spoofing.py @@ -29,15 +29,12 @@ parse_host_header = re.compile(r"^(?P[^:]+|\[.+\])(?::(?P\d+))?$") class Rerouter: - def __init__(self): - self.host_header = None - def requestheaders(self, flow): """ The original host header is retrieved early before flow.request is replaced by mitmproxy new outgoing request """ - self.host_header = flow.request.headers.get('host') + flow.metadata["original_host"] = flow.request.headers["Host"] def request(self, flow): if flow.client_conn.ssl_established: @@ -49,13 +46,14 @@ class Rerouter: sni = None port = 80 - m = parse_host_header.match(self.host_header) + host_header = flow.metadata["original_host"] + m = parse_host_header.match(host_header) if m: - self.host_header = m.group("host").strip("[]") + host_header = m.group("host").strip("[]") if m.group("port"): port = int(m.group("port")) - flow.request.host = sni or self.host_header + flow.request.host = sni or host_header flow.request.port = port -- cgit v1.2.3