aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorsmill <smill@cuckoo.sh>2016-09-03 12:22:09 +0000
committersmill <smill@cuckoo.sh>2016-09-03 12:22:09 +0000
commita6e0c7e8f0c20276f2f7cb2d9332a806e8493c18 (patch)
treef27a3db89f2697582a5a81cfb19e64248e907643 /netlib
parentb476966a45a6f77b1a819867dbbc943af9a57ef0 (diff)
downloadmitmproxy-a6e0c7e8f0c20276f2f7cb2d9332a806e8493c18.tar.gz
mitmproxy-a6e0c7e8f0c20276f2f7cb2d9332a806e8493c18.tar.bz2
mitmproxy-a6e0c7e8f0c20276f2f7cb2d9332a806e8493c18.zip
Introduced the capability to spoof the source address
of outgoing sessions + an accompanying shim loader.
Diffstat (limited to 'netlib')
-rw-r--r--netlib/tcp.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index e5c84165..aaea9459 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -605,7 +605,7 @@ class ConnectionCloser(object):
class TCPClient(_Connection):
- def __init__(self, address, source_address=None):
+ def __init__(self, address, source_address=None, spoof_source_address=None):
super(TCPClient, self).__init__(None)
self.address = address
self.source_address = source_address
@@ -613,6 +613,7 @@ class TCPClient(_Connection):
self.server_certs = []
self.ssl_verification_error = None # type: Optional[exceptions.InvalidCertificateException]
self.sni = None
+ self.spoof_source_address = spoof_source_address
@property
def address(self):
@@ -729,6 +730,11 @@ class TCPClient(_Connection):
def connect(self):
try:
connection = socket.socket(self.address.family, socket.SOCK_STREAM)
+ if self.spoof_source_address:
+ if os.geteuid() != 0:
+ raise RuntimeError("Insufficient privileges to set socket option")
+ else:
+ connection.setsockopt(socket.SOL_IP, 19, 1)
if self.source_address:
connection.bind(self.source_address())
connection.connect(self.address())