diff options
author | Aldo Cortesi <aldo@corte.si> | 2018-05-27 11:47:25 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-27 11:47:25 +1200 |
commit | 69aa5a0d2f799cc91ab5a7d5d75c55aa40ae58b8 (patch) | |
tree | 2df00f2812a7bd68e6ac1b3f481d69cf8bcc9fb9 | |
parent | dbf01cd34db98350732062fac9e7e1bd64a17ea9 (diff) | |
parent | a38d2d7b0ee436c84855ef584b19b65c314c57ce (diff) | |
download | mitmproxy-69aa5a0d2f799cc91ab5a7d5d75c55aa40ae58b8.tar.gz mitmproxy-69aa5a0d2f799cc91ab5a7d5d75c55aa40ae58b8.tar.bz2 mitmproxy-69aa5a0d2f799cc91ab5a7d5d75c55aa40ae58b8.zip |
Merge pull request #3164 from cortesi/ip6scope
addons/block: teach block about IPv6 scope suffixes
-rw-r--r-- | mitmproxy/addons/block.py | 16 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_block.py | 4 |
2 files changed, 13 insertions, 7 deletions
diff --git a/mitmproxy/addons/block.py b/mitmproxy/addons/block.py index a484f5c4..91f9f709 100644 --- a/mitmproxy/addons/block.py +++ b/mitmproxy/addons/block.py @@ -21,17 +21,19 @@ class Block: ) def clientconnect(self, layer): - address = ipaddress.ip_address(layer.client_conn.address[0]) + astr = layer.client_conn.address[0] + + parts = astr.rsplit("%", 1) + address = ipaddress.ip_address(parts[0]) if isinstance(address, ipaddress.IPv6Address): address = address.ipv4_mapped or address - ipa = ipaddress.ip_address(address) - if ipa.is_loopback: + if address.is_loopback: return - if ctx.options.block_private and ipa.is_private: - ctx.log.warn("Client connection from %s killed by block_private" % address) + if ctx.options.block_private and address.is_private: + ctx.log.warn("Client connection from %s killed by block_private" % astr) layer.reply.kill() - if ctx.options.block_global and ipa.is_global: - ctx.log.warn("Client connection from %s killed by block_global" % address) + if ctx.options.block_global and address.is_global: + ctx.log.warn("Client connection from %s killed by block_global" % astr) layer.reply.kill()
\ No newline at end of file diff --git a/test/mitmproxy/addons/test_block.py b/test/mitmproxy/addons/test_block.py index 4446d89c..4466ad23 100644 --- a/test/mitmproxy/addons/test_block.py +++ b/test/mitmproxy/addons/test_block.py @@ -17,6 +17,7 @@ from mitmproxy.test import taddons (True, False, False, ("::ffff:172.20.0.1",)), (True, False, False, ("::ffff:192.168.1.1",)), (True, False, False, ("fe80::",)), + (True, False, False, (r"::ffff:192.168.1.1%scope",)), # block_global: global (True, False, True, ("1.1.1.1",)), (True, False, True, ("8.8.8.8",)), @@ -25,6 +26,7 @@ from mitmproxy.test import taddons (True, False, True, ("::ffff:8.8.8.8",)), (True, False, True, ("::ffff:216.58.207.174",)), (True, False, True, ("2001:4860:4860::8888",)), + (True, False, True, (r"2001:4860:4860::8888%scope",)), # block_private: loopback @@ -37,6 +39,7 @@ from mitmproxy.test import taddons (False, True, True, ("::ffff:10.0.0.1",)), (False, True, True, ("::ffff:172.20.0.1",)), (False, True, True, ("::ffff:192.168.1.1",)), + (False, True, True, (r"::ffff:192.168.1.1%scope",)), (False, True, True, ("fe80::",)), # block_private: global (False, True, False, ("1.1.1.1",)), @@ -45,6 +48,7 @@ from mitmproxy.test import taddons (False, True, False, ("::ffff:1.1.1.1",)), (False, True, False, ("::ffff:8.8.8.8",)), (False, True, False, ("::ffff:216.58.207.174",)), + (False, True, False, (r"::ffff:216.58.207.174%scope",)), (False, True, False, ("2001:4860:4860::8888",)), ]) @pytest.mark.asyncio |