How to redirect HTTPS traffic to local HTTP server using mitmproxy?

笑着哭i 提交于 2020-08-25 08:26:29

问题


I am trying to setup mitmproxy so that I can make a request from my browser to https://{my-domain} and have it return a response from my local server running at http://localhost:3000 instead, but I cannot get the https request to reach my local server. I see the debugging statements from mitmproxy. Also, I can get it working for http traffic, but not for https.

I read the mitmproxy addon docs and api docs I've installed the cert and I can monitor https through the proxy.

I'm using Mitmproxy: 4.0.4 and Python: 3.7.4

This is my addon (local-redirect.py) and how I run mitmproxy:

from mitmproxy import ctx
import mitmproxy.http

class LocalRedirect:

  def __init__(self):
    print('Loaded redirect addon')

  def request(self, flow: mitmproxy.http.HTTPFlow):
    if 'my-actual-domain-here' in flow.request.pretty_host:
      ctx.log.info("pretty host is: %s" % flow.request.pretty_host)
      flow.request.host = "localhost"
      flow.request.port = 3000
      flow.request.scheme = 'http'

addons = [
  LocalRedirect()
]
$ mitmdump -s local-redirect.py | grep pretty

When I visit the url form my server, I see the logging statement, but my browser hangs on the request and there is no request made to my local server.


回答1:


The above addon was fine, however my local server did not support HTTP2.

Using the --no-http2 option was a quick fix:

mitmproxy -s local-redirect.py --no-http2 --view-filter localhost

or

mitmdump -s local-redirect.py --no-http2 localhost


来源:https://stackoverflow.com/questions/57627156/how-to-redirect-https-traffic-to-local-http-server-using-mitmproxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!