aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/complex/dns_spoofing.py12
1 files changed, 5 insertions, 7 deletions
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<host>[^:]+|\[.+\])(?::(?P<port>\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