From 078bd532c343d15e534cc0a0769d4354ac7b7279 Mon Sep 17 00:00:00 2001 From: Doug Freed Date: Sat, 12 Nov 2016 00:41:00 -0500 Subject: [PATCH 1/3] options: add upstream_bind_address Add upstream_bind_address to the options object --- mitmproxy/options.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 497914006..45f183726 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -69,6 +69,7 @@ class Options(optmanager.OptManager): ignore_hosts: Sequence[str] = (), listen_host: str = "", listen_port: int = LISTEN_PORT, + upstream_bind_address: str = "", mode: str = "regular", no_upstream_cert: bool = False, rawtcp: bool = False, @@ -131,6 +132,7 @@ class Options(optmanager.OptManager): self.ignore_hosts = ignore_hosts self.listen_host = listen_host self.listen_port = listen_port + self.upstream_bind_address = upstream_bind_address self.mode = mode self.no_upstream_cert = no_upstream_cert self.rawtcp = rawtcp From f89671a33b4ce7e861e16fe2d245f0df5919d6fa Mon Sep 17 00:00:00 2001 From: Doug Freed Date: Sat, 12 Nov 2016 00:52:14 -0500 Subject: [PATCH 2/3] tools/cmdline: add upstream bind address option Allow specifying the upstream bind address on the command line. --- mitmproxy/tools/cmdline.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py index 8b5799524..4be107a8e 100644 --- a/mitmproxy/tools/cmdline.py +++ b/mitmproxy/tools/cmdline.py @@ -251,6 +251,7 @@ def get_common_options(args): ignore_hosts = args.ignore_hosts, listen_host = args.addr, listen_port = args.port, + upstream_bind_address = args.upstream_bind_address, mode = mode, no_upstream_cert = args.no_upstream_cert, spoof_source_address = args.spoof_source_address, @@ -486,6 +487,11 @@ def proxy_options(parser): action="store_true", dest="spoof_source_address", help="Use the client's IP for server-side connections" ) + group.add_argument( + "--upstream-bind-address", + action="store", type=str, dest="upstream_bind_address", default='', + help="Address to bind upstream requests to (defaults to none)" + ) def proxy_ssl_options(parser): From 4cfda51c37d314c4706e93ae627189f3792b9623 Mon Sep 17 00:00:00 2001 From: Doug Freed Date: Sat, 12 Nov 2016 00:59:55 -0500 Subject: [PATCH 3/3] proxy/protocol/base: use upstream_bind_address Use the upstream_bind_address option, instead of listen_host. --- mitmproxy/proxy/protocol/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/proxy/protocol/base.py b/mitmproxy/proxy/protocol/base.py index 4d67bb71a..783d1cc8d 100644 --- a/mitmproxy/proxy/protocol/base.py +++ b/mitmproxy/proxy/protocol/base.py @@ -114,7 +114,7 @@ class ServerConnectionMixin: server_address, (self.ctx.client_conn.address.host, 0), True) else: self.server_conn = connections.ServerConnection( - server_address, (self.config.options.listen_host, 0)) + server_address, (self.config.options.upstream_bind_address, 0)) self.__check_self_connect()