Skip to content

Commit edab74b

Browse files
committed
create a unified should_skip_attack_scan
1 parent 73d01d4 commit edab74b

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

aikido_zen/helpers/is_protection_forced_off_cached.py renamed to aikido_zen/helpers/should_skip_attack_scan.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from aikido_zen.thread.thread_cache import get_cache
22
from aikido_zen.helpers.protection_forced_off import protection_forced_off
3+
from aikido_zen.helpers.logging import logger
34
from aikido_zen.context import Context
45

56

6-
def is_protection_forced_off_cached(context: Context) -> bool:
7+
def should_skip_attack_scan(context: Context) -> bool:
78
"""
8-
Check if protection is forced off using cached endpoints.
9+
Check if protection is forced off or IP bypassed using cache stored in the context.
910
This function assumes that the thread cache has already been retrieved
1011
and uses it to determine if protection is forced off for the given context.
1112
"""
@@ -21,9 +22,16 @@ def is_protection_forced_off_cached(context: Context) -> bool:
2122
if not thread_cache:
2223
return False
2324

24-
is_forced_off = protection_forced_off(
25+
is_forced_off = False
26+
# We check for a boolean protectionForcedOff on the matching endpoints, allows users to disable scans on certain routes.
27+
if protection_forced_off(
2528
context.get_route_metadata(), thread_cache.get_endpoints()
26-
)
29+
):
30+
is_forced_off = True
31+
# We check for Bypassed IPs : Allows users to let their DAST not be blocked by Zen
32+
if thread_cache.is_bypassed_ip(context.remote_address):
33+
is_forced_off = True
34+
2735
context.set_force_protection_off(is_forced_off)
2836
context.set_as_current_context()
2937

aikido_zen/vulnerabilities/__init__.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from aikido_zen.helpers.logging import logger
1717
from aikido_zen.helpers.get_clean_stacktrace import get_clean_stacktrace
1818
from aikido_zen.helpers.blocking_enabled import is_blocking_enabled
19-
from aikido_zen.helpers.is_protection_forced_off_cached import (
20-
is_protection_forced_off_cached,
19+
from aikido_zen.helpers.should_skip_attack_scan import (
20+
should_skip_attack_scan,
2121
)
2222
from aikido_zen.thread.thread_cache import get_cache
2323
from .sql_injection.context_contains_sql_injection import context_contains_sql_injection
@@ -37,25 +37,12 @@ def run_vulnerability_scan(kind, op, args):
3737
raises error if blocking is enabled, communicates it with connection_manager
3838
"""
3939
context = get_current_context()
40-
41-
if is_protection_forced_off_cached(context):
40+
if should_skip_attack_scan(context) and kind != "ssrf":
41+
# Make a special exception for SSRF:
42+
# For stored ssrf we don't want to check bypassed IPs or protection forced off.
4243
return
4344

4445
comms = comm.get_comms()
45-
thread_cache = get_cache()
46-
if not context and kind != "ssrf":
47-
# Make a special exception for SSRF, which checks itself if context is set.
48-
# This is because some scans/tests for SSRF do not require a context to be set.
49-
return
50-
51-
if not thread_cache and kind != "ssrf":
52-
# Make a special exception for SSRF, which checks itself if thread cache is set.
53-
# This is because some scans/tests for SSRF do not require a thread cache to be set.
54-
return
55-
if thread_cache and context:
56-
if thread_cache.is_bypassed_ip(context.remote_address):
57-
# This IP is on the bypass list, not scanning
58-
return
5946

6047
error_type = AikidoException # Default error
6148
error_args = tuple()
@@ -87,6 +74,7 @@ def run_vulnerability_scan(kind, op, args):
8774
injection_results = inspect_getaddrinfo_result(dns_results, hostname, port)
8875
error_type = AikidoSSRF
8976

77+
thread_cache = get_cache()
9078
if thread_cache and port > 0:
9179
thread_cache.hostnames.add(hostname, port)
9280
else:
@@ -101,7 +89,10 @@ def run_vulnerability_scan(kind, op, args):
10189

10290
blocked = is_blocking_enabled()
10391
operation = injection_results["operation"]
104-
thread_cache.stats.on_detected_attack(blocked, operation)
92+
93+
thread_cache = get_cache()
94+
if thread_cache:
95+
thread_cache.stats.on_detected_attack(blocked, operation)
10596

10697
stack = get_clean_stacktrace()
10798

aikido_zen/vulnerabilities/ssrf/inspect_getaddrinfo_result.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .find_hostname_in_context import find_hostname_in_context
1414
from .extract_ip_array_from_results import extract_ip_array_from_results
1515
from .is_redirect_to_private_ip import is_redirect_to_private_ip
16+
from aikido_zen.helpers.should_skip_attack_scan import should_skip_attack_scan
1617

1718

1819
# gets called when the result of the DNS resolution has come in
@@ -27,11 +28,7 @@ def inspect_getaddrinfo_result(dns_results, hostname, port):
2728
return
2829

2930
context = get_current_context()
30-
if not context:
31-
return # Context should be set to check user input.
32-
if get_cache() and get_cache().is_bypassed_ip(context.remote_address):
33-
# We check for bypassed ip's here since it is not checked for us
34-
# in run_vulnerability_scan due to the exception for SSRF (see above code)
31+
if should_skip_attack_scan(context):
3532
return
3633

3734
# attack_findings is an object containing source, pathToPayload and payload.

0 commit comments

Comments
 (0)