Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit b12c452

Browse files
author
floyd
committed
Make sure global matcher issues are only reported once per host. Additionally, improve debug output on stdout for timeouts that could only be produced once
1 parent 5781d59 commit b12c452

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

UploadScanner.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ def processHttpMessage(self, _, messageIsRequest, base_request_response):
869869

870870
# As the matcher was now triggered, we can remove it as it should not trigger again,
871871
# because every attack defines its own matcher
872-
self.dl_matchers.remove(url, matcher)
872+
self.dl_matchers.remove_reported(url, matcher)
873873

874874
# At maximum there will be 1 scan issue per message, as it is unlikely that there is more than 1
875875
# download in a HTTP message. Therefore we can use "return" after adding a scan issue.
@@ -4123,7 +4123,9 @@ def _send_sleep_based(self, injector, basename, content, types, sleep_time, issu
41234123
resp = self._make_http_request(injector, req, throttle=False)
41244124
if resp and time.time() - start > timeout_detection_time:
41254125
# found a timeout, let's confirm with a changed request so it doesn't get a cached response
4126-
print "TIMEOUT DETECTED! Now checking if really a timeout or just a random timeout"
4126+
print "TIMEOUT DETECTED! Now checking if really a timeout or just a random timeout. " \
4127+
"Request leading to first timeout was:"
4128+
print repr(req)
41274129
if randomize:
41284130
number = str(i) + ''.join(random.sample(string.ascii_letters, 3))
41294131
else:
@@ -4146,6 +4148,8 @@ def _send_sleep_based(self, injector, basename, content, types, sleep_time, issu
41464148
self._add_scan_issue(csi)
41474149
# Returning here is an option, but actually knowing all different kind of injections is nicer
41484150
# return
4151+
else:
4152+
print "Unfortunately, this seems to be a false positive... not reporting"
41494153

41504154
def _create_issue_template(self, base_request_response, name, detail, confidence, severity):
41514155
service = base_request_response.getHttpService()
@@ -6839,10 +6843,16 @@ def _create_globals(self):
68396843
dl_matcher = DownloadMatcher(issue, filecontent="tEXtdate:create")
68406844
self._global_matchers.add(dl_matcher)
68416845

6842-
def with_global(self, matchers):
6846+
def with_global(self, name, matchers):
68436847
g = set()
68446848
g.update(matchers)
6845-
g.update(self._global_matchers)
6849+
for m in self._global_matchers:
6850+
if not name in m.reported_for:
6851+
for alt_name in self._scope_mapping[name]:
6852+
if alt_name in m.reported_for:
6853+
break
6854+
else:
6855+
g.add(m)
68466856
return g
68476857

68486858
def add_scope(self, brr_url, url):
@@ -6865,12 +6875,12 @@ def get_matchers_for_url(self, url):
68656875
with self._thread_lock:
68666876
if hostport in self._collection:
68676877
# print "Found DownloadMatchers", hostport, "that correspond to", url
6868-
return self.with_global(self._collection[hostport])
6878+
return self.with_global(hostport, self._collection[hostport])
68696879

68706880
name = self.get_scope(hostport)
68716881
if name:
68726882
# print "Found DownloadMatchers for", name, "that can be used for", url
6873-
return self.with_global(self._collection[name])
6883+
return self.with_global(name, self._collection[name])
68746884
return []
68756885

68766886
def get_scope(self, hostport):
@@ -6879,17 +6889,22 @@ def get_scope(self, hostport):
68796889
if name in self._collection:
68806890
return name
68816891

6882-
def remove(self, url, matcher):
6892+
def remove_reported(self, url, matcher):
68836893
with self._thread_lock:
68846894
hostport = self._get_host(url)
6895+
if matcher in self._global_matchers:
6896+
matcher.reported_for.append(hostport)
6897+
return
68856898
if hostport in self._collection:
68866899
if matcher in self._collection[hostport]:
68876900
self._collection[hostport].remove(matcher)
6901+
return
68886902
else:
68896903
name = self.get_scope(hostport)
68906904
if name and name in self._collection:
68916905
if matcher in self._collection[name]:
68926906
self._collection[name].remove(matcher)
6907+
return
68936908

68946909
def _get_host(self, url):
68956910
if not url:
@@ -6980,6 +6995,9 @@ def __init__(self, issue,
69806995
self.content_type_header_marker = "content-type:"
69816996
self.content_disposition_header_marker = "content-disposition: attachment"
69826997

6998+
# Special case to keep track where global matchers were reported already
6999+
self.reported_for = []
7000+
69837001
def __hash__(self):
69847002
return hash((self.issue.name,
69857003
self.issue.urlPy,

0 commit comments

Comments
 (0)