Skip to content

Commit 88063ee

Browse files
committed
updated contrast parser and added new unittests and scan files
1 parent 43b2238 commit 88063ee

4 files changed

Lines changed: 40 additions & 20 deletions

File tree

dojo/tools/contrast/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get_findings(self, filename, test):
9090
)
9191

9292
dupe_key = hashlib.sha256(
93-
f"{finding.vuln_id_from_tool}".encode(),
93+
f"{finding.unique_id_from_tool}".encode(),
9494
).digest()
9595

9696
if dupe_key in dupes:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Vulnerability Name,Vulnerability ID,Category,Rule Name,Severity,Status,Number of Events,First Seen,First Seen Datetime,Last Seen,Last Seen Datetime,Application Name,Application ID,Application Code,CWE ID,Request Method,Request Port,Request Protocol,Request Version,Request URI,Request Qs,Request Body
2+
LDAP Injection from "username" Parameter,AAAA-1111-BBBB-2222,Injection,ldap-injection,High,Reported,1,1590144840000,2020-05-22T10:54:00.000Z,1600686000000,2020-09-21T11:00:00.000Z,my-app,app-id-001,,https://cwe.mitre.org/data/definitions/90.html,GET,8080,http,HTTP/1.1,/login,,
3+
LDAP Injection from "group" Parameter,CCCC-3333-DDDD-4444,Injection,ldap-injection,High,Reported,1,1590144840000,2020-05-22T10:54:00.000Z,1600686000000,2020-09-21T11:00:00.000Z,my-app,app-id-001,,https://cwe.mitre.org/data/definitions/90.html,GET,8080,http,HTTP/1.1,/admin,,
4+
LDAP Injection from "filter" Parameter,EEEE-5555-FFFF-6666,Injection,ldap-injection,High,Reported,1,1590144840000,2020-05-22T10:54:00.000Z,1600686000000,2020-09-21T11:00:00.000Z,my-app,app-id-001,,https://cwe.mitre.org/data/definitions/90.html,POST,8080,http,HTTP/1.1,/api/users,,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Vulnerability Name,Vulnerability ID,Category,Rule Name,Severity,Status,Number of Events,First Seen,First Seen Datetime,Last Seen,Last Seen Datetime,Application Name,Application ID,Application Code,CWE ID,Request Method,Request Port,Request Protocol,Request Version,Request URI,Request Qs,Request Body
2+
Path Traversal from "file" Parameter,AAAA-1111-BBBB-2222,Injection,path-traversal,High,Reported,1,1590144840000,2020-05-22T10:54:00.000Z,1600686000000,2020-09-21T11:00:00.000Z,my-app,app-id-001,,https://cwe.mitre.org/data/definitions/22.html,GET,8080,http,HTTP/1.1,/download,,
3+
Path Traversal from "file" Parameter,AAAA-1111-BBBB-2222,Injection,path-traversal,High,Reported,1,1590144840000,2020-05-22T10:54:00.000Z,1600686000000,2020-09-21T11:00:00.000Z,my-app,app-id-001,,https://cwe.mitre.org/data/definitions/22.html,GET,8080,http,HTTP/1.1,/upload,,

unittests/tools/test_contrast_parser.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_example_report(self):
1515
parser = ContrastParser()
1616
findings = parser.get_findings(testfile, test)
1717
self.validate_locations(findings)
18-
self.assertEqual(18, len(findings))
18+
self.assertEqual(52, len(findings))
1919
with self.subTest(i=0):
2020
finding = findings[0]
2121
self.assertEqual("Info", finding.severity)
@@ -30,25 +30,38 @@ def test_example_report(self):
3030
self.assertEqual("http", location.protocol)
3131
self.assertEqual("0.0.0.0", location.host) # noqa: S104
3232
self.assertEqual("WebGoat/login.mvc", location.path)
33-
with self.subTest(i=11):
34-
finding = findings[11]
35-
self.assertEqual(datetime.date(2018, 4, 23), finding.date.date())
33+
34+
def test_ldap_multiple_findings(self):
35+
test = Test()
36+
test.engagement = Engagement()
37+
test.engagement.product = Product()
38+
with (get_unit_tests_scans_path("contrast") / "ldap-multiple.csv").open(encoding="utf-8") as testfile:
39+
parser = ContrastParser()
40+
findings = parser.get_findings(testfile, test)
41+
self.assertEqual(3, len(findings))
42+
vuln_ids = [f.unique_id_from_tool for f in findings]
43+
self.assertEqual(len(vuln_ids), len(set(vuln_ids)), "Each finding should have a distinct unique_id_from_tool")
44+
for finding in findings:
45+
self.assertEqual("ldap-injection", finding.vuln_id_from_tool)
3646
self.assertEqual("High", finding.severity)
37-
self.assertEqual("path-traversal", finding.vuln_id_from_tool)
38-
self.assertIsNone(finding.unique_id_from_tool) # aggregated finding
39-
self.assertEqual(4, finding.nb_occurences)
40-
self.assertEqual(22, finding.cwe)
41-
# endpoints
42-
self.assertIsNotNone(self.get_unsaved_locations(finding))
43-
self.assertEqual(4, len(self.get_unsaved_locations(finding)))
44-
location = self.get_unsaved_locations(finding)[0]
45-
self.assertEqual("http", location.protocol)
46-
self.assertEqual("0.0.0.0", location.host) # noqa: S104
47-
self.assertEqual("WebGoat/services/SoapRequest", location.path)
48-
location = self.get_unsaved_locations(finding)[1]
49-
self.assertEqual("http", location.protocol)
50-
self.assertEqual("0.0.0.0", location.host) # noqa: S104
51-
self.assertEqual("WebGoat/attack", location.path)
47+
self.assertIsNotNone(finding.unique_id_from_tool)
48+
49+
def test_duplicate_vuln_id_is_merged(self):
50+
test = Test()
51+
test.engagement = Engagement()
52+
test.engagement.product = Product()
53+
with (get_unit_tests_scans_path("contrast") / "path-traversal-duplicate-vuln-id.csv").open(encoding="utf-8") as testfile:
54+
parser = ContrastParser()
55+
findings = parser.get_findings(testfile, test)
56+
self.assertEqual(1, len(findings))
57+
finding = findings[0]
58+
self.assertEqual("path-traversal", finding.vuln_id_from_tool)
59+
self.assertIsNone(finding.unique_id_from_tool)
60+
self.assertEqual(2, finding.nb_occurences)
61+
self.assertEqual(22, finding.cwe)
62+
self.assertEqual(2, len(self.get_unsaved_locations(finding)))
63+
self.assertEqual("/download", self.get_unsaved_locations(finding)[0].path)
64+
self.assertEqual("/upload", self.get_unsaved_locations(finding)[1].path)
5265

5366
def test_example2_report(self):
5467
test = Test()

0 commit comments

Comments
 (0)