This script parses Windows Event Log (EVTX) files and extracts the XML representation of each event record.
The script utilizes the python-evtx library to read and process EVTX files. It iterates through each record in the log file and extracts its XML content. The XML data is then written to a designated output file.
- EVTX Parsing: Reads and parses EVTX files.
- XML Extraction: Extracts the XML representation of each event record.
- Output to File: Writes the extracted XML data to a specified output file.
- Error Handling: Includes error handling for file not found and other exceptions.
-
Python 3: This script is written in Python 3.
-
python-evtx Library: You need to install the
python-evtxlibrary. You can install it using pip:pip install python-evtx
- Clone the repository: Clone it to your local machine using HTTPS or SSH.
- Install the dependency: Run
pip install python-evtx
-
Place your EVTX file: Place the EVTX file you want to parse in a location you can access.
-
Modify the script:
- Unless you want to parse the default file (which will result in an error), modify the
input_pathvariable in the main block ofcore.pyto point to your EVTX file. - Redefine the
output_pathvariable to change the name of the output file.
- Unless you want to parse the default file (which will result in an error), modify the
-
Run the script: Execute the
core.pyscript from your terminal:python core.py
-
Check the output: After the script finishes, you'll find the output XML file (default:
output_file.xml) in the same directory where you ran the script. This file will contain the XML representation of each event record from the EVTX file.
FYI: The script, by default, will print an error to the console.
This is because there is no "sample" EVTX file to parse through.
core.py:parse_evtx(file_path, output_path): This function handles the core logic of parsing the EVTX file and writing the XML output.if __name__ == "__main__":: This block defines the entry point of the script, sets the default input and output paths, and callsparse_evtxif the input file exists.
The script also includes some basic error handling:
FileNotFoundError: If the specified input EVTX file is not found, an error message is printed to the standard error stream.Exception: If any other error occurs during the parsing process, a general error message is printed.
- The script assumes that the EVTX file is a valid Windows Event Log file.
- The output XML file can be quite large, depending on the size of the input EVTX file.
- The script WILL overwrite the output file if it already exists!
- You will need to change the default input path to point to a valid path on your system.
If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request!