How do I connect mitmproxy to another proxy outside of my control?
Asked Answered
L

4

8

The process would be that the browser send a request to MITMproxy and then generate a request that gets sent to target proxy server which isn't controlled by us. The proxy server would send a response to MITMproxy which would then relay that response to the browser.

How would I go about doing this?

Loxodrome answered 6/3, 2014 at 9:14 Comment(0)
K
5

You can do this with the -F flag to mitmproxy, which forwards proxy requests to an upstream server. Take a look at the docs here:

http://mitmproxy.org/doc/features/forwardproxy.html

Killick answered 6/3, 2014 at 19:39 Comment(0)
M
21

I was able to achieve what you ask with the following. You need to enable the upstream mode and upstream auth (in case you have some username/password for your proxy):

mitmproxy --mode upstream:https://HOSTNAME:PORT --upstream-auth USER:PASSWORD

Then you can check it's working with a simple curl:

curl -x http://localhost:8080 -k https://api.ipify.org/

This will forward your request to mitmproxy which will forward it to your other proxy.

Hope it helps!

Mamelon answered 12/6, 2019 at 21:20 Comment(1)
FYI for others, most of the other answers seem to be for very old versions of mitmproxy. For anything recent (v3+), this --mode upstream: option is the way it's done. See docs.mitmproxy.org/stable/concepts-optionsGrainy
K
5

You can do this with the -F flag to mitmproxy, which forwards proxy requests to an upstream server. Take a look at the docs here:

http://mitmproxy.org/doc/features/forwardproxy.html

Killick answered 6/3, 2014 at 19:39 Comment(0)
H
1

If you'd like to do this not from the script, you can change the upstream server with get_upstream_server from server.config see [mitmproxy config] (https://github.com/mitmproxy/mitmproxy/blob/42d4a2fae96b8b4ba35d3a88e20f278d79a0ccc6/libmproxy/proxy.py). For example:

self.server.config.get_upstream_server = proxy.ConstUpstreamServerResolver(cmdline.parser_server_spec("http://upstreamserver:port"))
Hydroscope answered 18/8, 2014 at 21:34 Comment(2)
how do I use upstream server with script?Governorship
if u want to solve this via addons: https://mcmap.net/q/1321976/-how-to-make-a-network-request-inside-a-mitmproxy-addonTiphanie
N
0

I think it's the -U option:

command-line    -U http://hostname[:port]

source: http://docs.mitmproxy.org/en/stable/features/upstreamproxy.html

Namecalling answered 11/10, 2017 at 3:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.