Skip to content

Commit dd1314e

Browse files
committed
rename to should_block_outbound_domain and rm bypassed ip check
1 parent 4652a66 commit dd1314e

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

aikido_zen/sinks/socket/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""
22
Sink module for `socket`
33
"""
4-
4+
from aikido_zen.errors import AikidoSSRF
55
from aikido_zen.helpers.get_argument import get_argument
66
from aikido_zen.sinks import on_import, patch_function, after
7-
from aikido_zen.sinks.socket.report_and_check_hostname import report_and_check_hostname
7+
from aikido_zen.sinks.socket.normalize_hostname import normalize_hostname
8+
from aikido_zen.sinks.socket.should_block_outbound_domain import should_block_outbound_domain
89
from aikido_zen.vulnerabilities import run_vulnerability_scan
910

1011

@@ -14,7 +15,13 @@ def _getaddrinfo_after(func, instance, args, kwargs, return_value):
1415
host = get_argument(args, kwargs, 0, "host")
1516
port = get_argument(args, kwargs, 1, "port")
1617

17-
report_and_check_hostname(host, port)
18+
# We want a normalized hostname for reporting & blocking outbound domains
19+
# This function decodes the hostname if its written in punycode
20+
hostname = normalize_hostname(host)
21+
22+
# Store hostname and check if we should stop this request from happening
23+
if should_block_outbound_domain(host, port):
24+
raise AikidoSSRF(f"Zen has blocked an outbound connection to {hostname}")
1825

1926
# Run vulnerability scan with the return value (DNS results)
2027
op = "socket.getaddrinfo"

aikido_zen/sinks/socket/report_and_check_hostname.py

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from aikido_zen.context import get_current_context
2+
from aikido_zen.errors import AikidoSSRF
3+
from aikido_zen.sinks.socket.normalize_hostname import normalize_hostname
4+
from aikido_zen.thread.thread_cache import get_cache
5+
6+
7+
def should_block_outbound_domain(hostname, port):
8+
process_cache = get_cache()
9+
if not process_cache:
10+
return False
11+
process_cache.hostnames.add(hostname, port)
12+
13+
return process_cache.config.should_block_outgoing_request(hostname)

0 commit comments

Comments
 (0)