Skip to content

Commit 0c995f3

Browse files
Fix KeyError on missing EventData or System sections in evtx logs
Modified dictionary lookups in evtx_dump_json.py to use the .get() method with empty dictionary fallbacks. This prevents the script from crashing with a "KeyError: 'EventData'" when parsing specific EVTX events that lack an "EventData" or "System" key.
1 parent 1a1357a commit 0c995f3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

evtx_scripts/evtx_dump_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main():
3535
data_dict = xmltodict.parse(record.xml())
3636

3737
# Loop through each key,value pair of the System section of the evtx logs and extract the EventRecordID
38-
for event_system_key, event_system_value in data_dict["Event"]["System"].items():
38+
for event_system_key, event_system_value in data_dict.get("Event",{}).get("System",{}).items():
3939
if event_system_key == "EventRecordID":
4040
json_subline = {}
4141
firstline = {event_system_key: event_system_value}
@@ -44,7 +44,7 @@ def main():
4444
json_subline.update(firstline) # add the event ID to JSON subline
4545

4646
# Loop through each key, value pair of the EventData section of the evtx logs
47-
for event_data_key, event_data_value in data_dict["Event"]["EventData"].items():
47+
for event_data_key, event_data_value in data_dict.get("Event",{}).get("EventData",{}).items():
4848
for values in event_data_value:
4949

5050
# Loop through each subvalue within the EvenData section to extract necessary information

0 commit comments

Comments
 (0)