diff options
author | Sandor Nemes <sandor.nemes@gmail.com> | 2016-01-08 15:46:59 +0100 |
---|---|---|
committer | Sandor Nemes <sandor.nemes@gmail.com> | 2016-01-08 18:55:13 +0100 |
commit | fe77dd35c67a0dfbd3004fefe97c689f8cfd3291 (patch) | |
tree | bec6c002a4db4ac019d9dfe5cf735db3375378c4 /libmproxy | |
parent | 11215e46ecc5c3a4272893d4b06f71920ff126f5 (diff) | |
download | mitmproxy-fe77dd35c67a0dfbd3004fefe97c689f8cfd3291.tar.gz mitmproxy-fe77dd35c67a0dfbd3004fefe97c689f8cfd3291.tar.bz2 mitmproxy-fe77dd35c67a0dfbd3004fefe97c689f8cfd3291.zip |
Fixed a problem with the bind address not being used as the source address on outgoing TCP packets
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/models/connections.py | 6 | ||||
-rw-r--r-- | libmproxy/protocol/base.py | 7 | ||||
-rw-r--r-- | libmproxy/protocol/http_replay.py | 4 | ||||
-rw-r--r-- | libmproxy/proxy/modes/http_proxy.py | 1 | ||||
-rw-r--r-- | libmproxy/proxy/modes/reverse_proxy.py | 1 | ||||
-rw-r--r-- | libmproxy/proxy/modes/socks_proxy.py | 4 | ||||
-rw-r--r-- | libmproxy/proxy/modes/transparent_proxy.py | 1 |
7 files changed, 17 insertions, 7 deletions
diff --git a/libmproxy/models/connections.py b/libmproxy/models/connections.py index 0991955d..0cfc17d4 100644 --- a/libmproxy/models/connections.py +++ b/libmproxy/models/connections.py @@ -88,8 +88,10 @@ class ClientConnection(tcp.BaseHandler, stateobject.StateObject): class ServerConnection(tcp.TCPClient, stateobject.StateObject): - def __init__(self, address): - tcp.TCPClient.__init__(self, address) + def __init__(self, address, source_address=None): + if source_address: + source_address = (source_address, 0) + tcp.TCPClient.__init__(self, address, source_address) self.via = None self.timestamp_start = None diff --git a/libmproxy/protocol/base.py b/libmproxy/protocol/base.py index af6b1c3b..8a1bea91 100644 --- a/libmproxy/protocol/base.py +++ b/libmproxy/protocol/base.py @@ -109,9 +109,9 @@ class ServerConnectionMixin(object): self.disconnect() """ - def __init__(self, server_address=None): + def __init__(self, server_address=None, source_address=None): super(ServerConnectionMixin, self).__init__() - self.server_conn = ServerConnection(server_address) + self.server_conn = ServerConnection(server_address, source_address) self.__check_self_connect() def __check_self_connect(self): @@ -157,10 +157,11 @@ class ServerConnectionMixin(object): """ self.log("serverdisconnect", "debug", [repr(self.server_conn.address)]) address = self.server_conn.address + source_address = self.server_conn.source_address()[0] self.server_conn.finish() self.server_conn.close() self.channel.tell("serverdisconnect", self.server_conn) - self.server_conn = ServerConnection(address) + self.server_conn = ServerConnection(address, source_address) def connect(self): """ diff --git a/libmproxy/protocol/http_replay.py b/libmproxy/protocol/http_replay.py index b7faad07..409810d5 100644 --- a/libmproxy/protocol/http_replay.py +++ b/libmproxy/protocol/http_replay.py @@ -46,7 +46,7 @@ class RequestReplayThread(threading.Thread): # In all modes, we directly connect to the server displayed if self.config.mode == "upstream": server_address = self.config.upstream_server.address - server = ServerConnection(server_address) + server = ServerConnection(server_address, self.config.host) server.connect() if r.scheme == "https": connect_request = make_connect_request((r.host, r.port)) @@ -68,7 +68,7 @@ class RequestReplayThread(threading.Thread): r.form_out = "absolute" else: server_address = (r.host, r.port) - server = ServerConnection(server_address) + server = ServerConnection(server_address, self.config.host) server.connect() if r.scheme == "https": server.establish_ssl( diff --git a/libmproxy/proxy/modes/http_proxy.py b/libmproxy/proxy/modes/http_proxy.py index c7502c24..27da57dd 100644 --- a/libmproxy/proxy/modes/http_proxy.py +++ b/libmproxy/proxy/modes/http_proxy.py @@ -16,6 +16,7 @@ class HttpProxy(Layer, ServerConnectionMixin): class HttpUpstreamProxy(Layer, ServerConnectionMixin): def __init__(self, ctx, server_address): super(HttpUpstreamProxy, self).__init__(ctx, server_address=server_address) + self.server_conn.source_address = (ctx.config.host, 0) def __call__(self): layer = self.ctx.next_layer(self) diff --git a/libmproxy/proxy/modes/reverse_proxy.py b/libmproxy/proxy/modes/reverse_proxy.py index 28f4e6f8..3ff22b6c 100644 --- a/libmproxy/proxy/modes/reverse_proxy.py +++ b/libmproxy/proxy/modes/reverse_proxy.py @@ -6,6 +6,7 @@ from ...protocol import Layer, ServerConnectionMixin class ReverseProxy(Layer, ServerConnectionMixin): def __init__(self, ctx, server_address, server_tls): super(ReverseProxy, self).__init__(ctx, server_address=server_address) + self.server_conn.source_address = (ctx.config.host, 0) self.server_tls = server_tls def __call__(self): diff --git a/libmproxy/proxy/modes/socks_proxy.py b/libmproxy/proxy/modes/socks_proxy.py index 264c734a..6e0b927b 100644 --- a/libmproxy/proxy/modes/socks_proxy.py +++ b/libmproxy/proxy/modes/socks_proxy.py @@ -8,6 +8,10 @@ from ...protocol import Layer, ServerConnectionMixin class Socks5Proxy(Layer, ServerConnectionMixin): + def __init__(self, ctx): + super(Socks5Proxy, self).__init__(ctx) + self.server_conn.source_address = (ctx.config.host, 0) + def __call__(self): try: # Parse Client Greeting diff --git a/libmproxy/proxy/modes/transparent_proxy.py b/libmproxy/proxy/modes/transparent_proxy.py index da1d4632..995e4bd9 100644 --- a/libmproxy/proxy/modes/transparent_proxy.py +++ b/libmproxy/proxy/modes/transparent_proxy.py @@ -8,6 +8,7 @@ from ...protocol import Layer, ServerConnectionMixin class TransparentProxy(Layer, ServerConnectionMixin): def __init__(self, ctx): super(TransparentProxy, self).__init__(ctx) + self.server_conn.source_address = (ctx.config.host, 0) self.resolver = platform.resolver() def __call__(self): |