0

I am trying to use mitmproxy behind a company proxy that requires a user/password login.

The setup is: Local PC's browser -> mitmproxy (on local PC) -> company proxy -> internet.

Based on this SO thread, this is how you use mitmproxy within a Python program. This example works fine when there's no proxy.

from mitmproxy.options import Options
from mitmproxy.proxy.config import ProxyConfig
from mitmproxy.proxy.server import ProxyServer
from mitmproxy.tools.dump import DumpMaster

class Addon(object):
    def __init__(self):
        pass

    def request(self, flow):
        # examine request here 
        pass

    def response(self, flow):
        # examine response here
        pass


if __name__ == "__main__":

    options = Options(listen_host='0.0.0.0', listen_port=8080, http2=True)
    m = DumpMaster(options, with_termlog=False, with_dumper=False)
    config = ProxyConfig(options)

    m.server = ProxyServer(config)
    m.addons.add(Addon())

    try:
        print('starting mitmproxy')
        m.run()
    except KeyboardInterrupt:
        m.shutdown()

Assuming the company proxy is at IP "1.2.3.4" port 3128 and requires a login USER and PASSWORD, how can I change this script to have mitproxy use that proxy instead of going to the internet directly?

Addition info: I am not using mitmdump with the script-parameter to run this script. The goal is to run this from Python 3.8 with a pip-installed mitmproxy

576i
  • 7,579
  • 12
  • 55
  • 92
  • For the proxy you should be able to configure it with an additional option: `mode='upstream:http://1.2.3.4:3128'`. and for the authentication `upstream_auth='USER:PASSWORD'`. – Robert Sep 25 '20 at 09:58
  • @Robert - where exactly should I add those parameters, in `Options`? – 576i Sep 25 '20 at 18:59
  • You have an `Option` with already three options set, just add them at the end? – Robert Sep 26 '20 at 10:18
  • @Robert - adding these options to Options causes the error `Key error, unknown options: upstream_auth` – 576i Oct 08 '20 at 15:26
  • Then try it after adding your addon using `options .update(mode='upstream:http://1.2.3.4:3128')` and `options.update(upstream_auth='USER:PASSWORD')` – Robert Oct 08 '20 at 15:38

0 Answers0