Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nuclei parser: invalid CWEs #11232

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions dojo/tools/nuclei/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ def get_findings(self, filename, test):
cve_ids = classification["cve-id"]
finding.unsaved_vulnerability_ids = [x.upper() for x in cve_ids]
if (
"cwe-id" in classification
and classification["cwe-id"]
and len(classification["cwe-id"]) > 0
classification.get("cwe-id")
):
cwe = classification["cwe-id"][0]
finding.cwe = int(cwe[4:])
try:
finding.cwe = int(cwe[4:])
except ValueError:
"""
ignore CWE if non-int
several older templates such as https://github.com/projectdiscovery/nuclei-templates/blob/6636c0d2dd540645cc3472822beb4b3819ff8322/http/cves/2004/CVE-2004-0519.yaml#L21
"""
if classification.get("cvss-metrics"):
cvss_objects = cvss_parser.parse_cvss_from_text(
classification["cvss-metrics"],
Expand Down
1 change: 1 addition & 0 deletions unittests/scans/nuclei/invalid_cwe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"templateID":"mysql-native-password-bruteforce","info":{"name":"MySQL DB with enabled native password","author":"iamthefrogy","severity":"info","tags":"network,mysql,bruteforce,db","description":"MySQL instance with enabled native password support prone vulnerable for password brute-force attack.", "classification": {"cwe-id": ["nvd-cve-other"]}},"type":"network","host":"https://nuclei-example.com","matched":"nuclei-example.com:3306","ip":"178.21.15.56","timestamp":"2021-05-20T11:12:02.301031+03:00"}
11 changes: 11 additions & 0 deletions unittests/tools/test_nuclei_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,14 @@ def test_parse_many_findings_v3(self):
with self.subTest(i=0):
finding = findings[0]
self.assertEqual("Info", finding.severity)

def test_parse_invalid_cwe(self):
with open("unittests/scans/nuclei/invalid_cwe.json", encoding="utf-8") as testfile:
parser = NucleiParser()
findings = parser.get_findings(testfile, Test())
self.assertEqual(1, len(findings))
for finding in findings:
for endpoint in finding.unsaved_endpoints:
endpoint.clean()
self.assertEqual("nuclei-example.com", finding.unsaved_endpoints[0].host)
self.assertEqual(0, finding.cwe)
Loading