Shuzheng
Shuzheng

Reputation: 13840

How to redirect all mitmproxy HTTP traffic to a specific HTTP server?

I want to redirect all HTTP traffic intercepted by mitmproxy to a particular HTTP server, regardless of where the HTTP traffic was destined too.

I know how to set an upstream proxy server for mitmserver, but in this case I don't want another proxy server, but a (destination) HTTP server instead.

Any ideas?

Upvotes: 2

Views: 2020

Answers (1)

Ivan Balepin
Ivan Balepin

Reputation: 487

One way to do this would be inject a python script that overwrites the destination of every request. You add a -s script.py parameter to the mitmproxy/mitmdump command (or call master.addons.add(script.Script('script.py')) if you are using mitmproxy library) and add for example the following into your script:

from mitmproxy import http

def request(self, flow: http.HTTPFlow) -> None:
    flow.request.host = 'google.com'
    flow.request.path = '/'

... further customize request method, cookies, etc etc as needed

Upvotes: 2

Related Questions