|
4 | 4 |
|
5 | 5 | from aikido_zen.helpers.get_argument import get_argument |
6 | 6 | from aikido_zen.helpers.register_call import register_call |
7 | | -from aikido_zen.sinks import on_import, patch_function, after |
| 7 | +from aikido_zen.sinks import on_import, patch_function, before |
8 | 8 | from aikido_zen.vulnerabilities import run_vulnerability_scan |
| 9 | +from aikido_zen.thread.thread_cache import get_cache |
| 10 | +from aikido_zen.errors import AikidoSSRF |
9 | 11 |
|
10 | 12 |
|
11 | | -@after |
12 | | -def _getaddrinfo(func, instance, args, kwargs, return_value): |
| 13 | +@before |
| 14 | +def _getaddrinfo(func, instance, args, kwargs): |
13 | 15 | host = get_argument(args, kwargs, 0, "host") |
14 | 16 | port = get_argument(args, kwargs, 1, "port") |
15 | 17 |
|
| 18 | + # Check if we should block this outgoing request based on configuration |
| 19 | + cache = get_cache() |
| 20 | + if cache and cache.config: |
| 21 | + if cache.config.should_block_outgoing_request(host): |
| 22 | + raise AikidoSSRF( |
| 23 | + f"Zen has blocked an outbound connection: socket.getaddrinfo to {host}" |
| 24 | + ) |
| 25 | + |
16 | 26 | op = "socket.getaddrinfo" |
17 | 27 | register_call(op, "outgoing_http_op") |
18 | 28 |
|
| 29 | + # Call the original function to get the return value for vulnerability scanning |
| 30 | + return_value = func(*args, **kwargs) |
| 31 | + |
| 32 | + # Run vulnerability scan after getting the result |
19 | 33 | arguments = (return_value, host, port) # return_value = dns response |
20 | 34 | run_vulnerability_scan(kind="ssrf", op=op, args=arguments) |
21 | 35 |
|
| 36 | + return return_value |
| 37 | + |
22 | 38 |
|
23 | 39 | @on_import("socket") |
24 | 40 | def patch(m): |
|
0 commit comments