|
| 1 | + |
| 2 | +import json |
| 3 | + |
| 4 | +from dojo.models import Finding |
| 5 | + |
| 6 | + |
| 7 | +class N0s1Parser: |
| 8 | + def get_scan_types(self): |
| 9 | + return ["n0s1 Scanner"] |
| 10 | + |
| 11 | + def get_label_for_scan_types(self, scan_type): |
| 12 | + return scan_type |
| 13 | + |
| 14 | + def get_description_for_scan_types(self, scan_type): |
| 15 | + return "JSON output from the n0s1 scanner." |
| 16 | + |
| 17 | + def get_findings(self, filename, test): |
| 18 | + findings = [] |
| 19 | + tree = filename.read() |
| 20 | + try: |
| 21 | + data = json.loads(str(tree, "utf-8")) |
| 22 | + except Exception: |
| 23 | + data = json.loads(tree) |
| 24 | + |
| 25 | + # Load global regex rules |
| 26 | + regex_configs = {} |
| 27 | + if "regex_config" in data and "rules" in data["regex_config"]: |
| 28 | + for rule in data["regex_config"]["rules"]: |
| 29 | + regex_configs[rule["id"]] = rule |
| 30 | + |
| 31 | + # Iterate over findings |
| 32 | + for finding_id, finding_data in data.get("findings", {}).items(): |
| 33 | + details = finding_data.get("details", {}) |
| 34 | + regex_ref = details.get("matched_regex_config", {}) |
| 35 | + regex_id = regex_ref.get("id") |
| 36 | + |
| 37 | + # Merge global config with local override |
| 38 | + regex_info = regex_configs.get(regex_id, {}) |
| 39 | + merged_regex = { |
| 40 | + "id": regex_id, |
| 41 | + "description": regex_ref.get("description", regex_info.get("description", "N/A")), |
| 42 | + "regex": regex_ref.get("regex", regex_info.get("regex", "N/A")), |
| 43 | + "keywords": regex_info.get("keywords", []), |
| 44 | + "tags": regex_info.get("tags", []), |
| 45 | + } |
| 46 | + |
| 47 | + title = merged_regex["id"] or "n0s1 Finding" |
| 48 | + description = f"**URL:** {finding_data.get('url', 'N/A')}\n" |
| 49 | + description += f"**Secret:** {finding_data.get('secret', 'N/A')}\n" |
| 50 | + description += f"**Platform:** {details.get('platform', 'N/A')}\n" |
| 51 | + description += f"**Ticket Field:** {details.get('ticket_field', 'N/A')}\n" |
| 52 | + description += f"**Regex ID:** {merged_regex['id']}\n" |
| 53 | + description += f"**Regex Description:** {merged_regex['description']}\n" |
| 54 | + description += f"**Regex Pattern:** {merged_regex['regex']}\n" |
| 55 | + if merged_regex["keywords"]: |
| 56 | + description += f"**Keywords:** {', '.join(merged_regex['keywords'])}\n" |
| 57 | + if merged_regex["tags"]: |
| 58 | + description += f"**Tags:** {', '.join(merged_regex['tags'])}\n" |
| 59 | + |
| 60 | + find = Finding( |
| 61 | + title=title, |
| 62 | + test=test, |
| 63 | + description=description, |
| 64 | + severity="High", # You can adjust this based on your logic |
| 65 | + dynamic_finding=True, |
| 66 | + static_finding=False, |
| 67 | + unique_id_from_tool=finding_data.get("id", finding_id), |
| 68 | + ) |
| 69 | + findings.append(find) |
| 70 | + |
| 71 | + return findings |
0 commit comments