0

I'm using mitmproxy with python as a http proxy

I run the proxy with following command:

mitmdump -s proxy.py -U http://upstreamproxy

The proxy.py is like following:

#!/usr/bin/mitmdump
from __future__ import print_function
import pprint
import datetime
import os
import re


pp = pprint.PrettyPrinter(indent=4)

def request(context, flow):
    print("DEBUG")
    oldhost = flow.request.host
    flow.request.url = re.sub(r"www.verycd.com",r"115.182.66.26",flow.request.url)
    # flow.request.host = oldhost   #<---This will modify the url also
    print("DEBUG")

What I expect is to change the www.verycd.com to IP in url but keep the host field still using www.verycd.com, like following:

GET http://115.182.66.26/ HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh,en-US;q=0.5
Host: www.verycd.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0

But the mitmproxy always change the url and host at the same time I got following which the server does not accept

GET http://115.182.66.26/ HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh,en-US;q=0.5
Host: 115.182.66.26
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
Boying
  • 1,404
  • 13
  • 20

1 Answers1

1

Already answered by project owner

https://github.com/mitmproxy/mitmproxy/issues/890

Boying
  • 1,404
  • 13
  • 20