Skip to content

Commit cd18539

Browse files
🪲 Parse empty machines in Defender (#11844)
* 🪲 Parse empty machines in zip * added docs * see review
1 parent 7825c53 commit cd18539

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

docs/content/en/connecting_your_tools/parsers/file/ms_defender.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ toc_hide: true
55
This parser helps to parse Microsoft Defender Findings and supports two types of imports:
66
- You can import a JSON output file from the api/vulnerabilities/machinesVulnerabilities endpoint of Microsoft defender.
77
- You can upload a custom zip file which include multiple JSON files from two Microsoft Defender Endpoints. For that you have to make your own zip file and include two folders (machines/ and vulnerabilities/) within the zip file. For vulnerabilities/ you can attach multiple JSON files from the api/vulnerabilities/machinesVulnerabilities REST API endpoint of Microsoft Defender. Furthermore, in machines/ you can attach the JSON output from the api/machines REST API endpoint of Microsoft Defender. Then, the parser uses the information in both folders to add more specific information like the affected IP Address to the finding.
8+
<br>However, if you have a fast changing environment with a huge number of vulnerabilities and endpoints, it is recommended to leave the folder machines/ empty. Then, for stability reasons the machine info is skipped and only the machineID is added to the finding.
89

910
### Sample Scan Data
1011
Sample MS Defender Parser scans can be found [here](https://github.com/DefectDojo/django-DefectDojo/tree/master/unittests/scans/ms_defender).

dojo/tools/ms_defender/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_findings(self, file, test):
3232
else:
3333
input_zip = zipfile.ZipFile(file, "r")
3434
zipdata = {name: input_zip.read(name) for name in input_zip.namelist()}
35-
if zipdata.get("machines/") is None or zipdata.get("vulnerabilities/") is None:
35+
if zipdata.get("vulnerabilities/") is None:
3636
return []
3737
vulnerabilityfiles = []
3838
machinefiles = []
1.4 KB
Binary file not shown.

unittests/tools/test_ms_defender_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@ def test_parser_defender_issue_11217(self):
8080
for endpoint in finding.unsaved_endpoints:
8181
endpoint.clean()
8282
self.assertEqual("Max_Mustermann_iPadAir_17zoll__2ndgeneration_", finding.unsaved_endpoints[0].host)
83+
84+
def test_parser_defender_empty_machines(self):
85+
testfile = open(get_unit_tests_scans_path("ms_defender") / "empty_machines.zip", encoding="utf-8")
86+
parser = MSDefenderParser()
87+
findings = parser.get_findings(testfile, Test())
88+
testfile.close()
89+
self.assertEqual(4, len(findings))

0 commit comments

Comments
 (0)