Skip to main content

Captures Sysmon events and converts the output into a pandas DataFrames / CSV

Project description

Captures Sysmon events and converts the output into a pandas DataFrames / CSV

pip install sysmon2df

Tested against Windows 10 / Python 3.10 / Anaconda

The function start_observing prepares for the observation by uninstalling any existing Sysmon installation and removing the old event log file (if specified). It installs Sysmon using the provided or default configuration XML (capture every event). It starts an infinite loop where it sleeps for 1 second until a keyboard interrupt is received. After the observation is stopped, it copies the Sysmon event log (EVTX file) to the specified or temporary output path. It uninstalls Sysmon again to clean up. It generates a pandas DataFrame from the Sysmon event log using the dataframe_from_evtx function. If specified, it saves the DataFrame as a CSV file at the specified path. Finally, it returns the DataFrame.

How to use it:

start_observing(
    uninstall: int | bool = 1,
    uninstall_force: int | bool = 1,
    evtx_path: str | None = None,
    remove_old_evtx: int | bool = 1,
    configxml: str | None = None,
    evtx_output_path: str | None = None,
    csv_output_path: str | None = None,
) -> pd.DataFrame:
    r"""
    Starts observing system events using Sysmon and returns a pandas DataFrame containing the recorded events.

    Args:
        uninstall (int | bool, optional): Flag indicating whether to uninstall Sysmon after/before observation. Defaults to 1.
        uninstall_force (int | bool, optional): Flag indicating whether to force uninstall Sysmon. Defaults to 1.
        evtx_path (str | None, optional): Path to the Sysmon event log (EVTX file). If not provided, the default path ("System32\Winevt\Logs\Microsoft-Windows-Sysmon%4Operational.evtx") will be used. Defaults to None.
        remove_old_evtx (int | bool, optional): Flag indicating whether to remove the existing Sysmon event log before starting observation. Defaults to 1.
        configxml (str | None, optional): Path to the Sysmon configuration XML file. If not provided, a temporary file will be created. Defaults to None.
        evtx_output_path (str | None, optional): Path to save the Sysmon event log (EVTX file) after observation. If not provided, a temporary file will be created. Defaults to None.
        csv_output_path (str | None, optional): Path to save the recorded events as a CSV file. If not provided, no CSV file will be created. Defaults to None.

    Returns:
        pd.DataFrame: A pandas DataFrame containing the recorded system events.

        Example of CSV output:
        ,aa_value,aa_key_0,aa_key_1,aa_key_2,aa_key_3,aa_key_4,aa_event_record_id,aa_timestamp,aa_kind_of_event
        0,http://schemas.microsoft.com/win/2004/08/events/event,Event,#attributes,xmlns,,,32,2023-05-18 14:11:16.815117+00:00,
        1,C:\Windows\SYSTEM32\ntdll.dll+9d364|C:\Windows\system32\basesrv.DLL+2fba|C:\Windows\SYSTEM32\CSRSRV.dll+5af4|C:\Windows\SYSTEM32\ntdll.dll+6d72f,Event,EventData,CallTrace,,,32,2023-05-18 14:11:16.815117+00:00,
        2,0x1fffff,Event,EventData,GrantedAccess,,,32,2023-05-18 14:11:16.815117+00:00,
        3,-,Event,EventData,RuleName,,,32,2023-05-18 14:11:16.815117+00:00,
        4,C:\Windows\system32\csrss.exe,Event,EventData,SourceImage,,,32,2023-05-18 14:11:16.815117+00:00,
        

from sysmon2df import start_observing  
df = start_observing(
    uninstall=True,
    uninstall_force=True,
    evtx_path=None,
    remove_old_evtx=True,
    configxml=None,
    evtx_output_path="c:\\backupsysmon2.evtx",
    csv_output_path="c:\\backupsysmon2.csv",
)
        

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sysmon2df-0.10.tar.gz (4.8 MB view details)

Uploaded Source

Built Distribution

sysmon2df-0.10-py3-none-any.whl (4.8 MB view details)

Uploaded Python 3

File details

Details for the file sysmon2df-0.10.tar.gz.

File metadata

  • Download URL: sysmon2df-0.10.tar.gz
  • Upload date:
  • Size: 4.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for sysmon2df-0.10.tar.gz
Algorithm Hash digest
SHA256 a995bfb37d579d7b07fc496c821a412509d5153fdc78842c728aa769eb6dd630
MD5 e5ab5728ed05113782dfb1d2763a5cb9
BLAKE2b-256 2194cfb4b3e00b97a222300a3961481b558cb2bd60fbb42a2c1a65d73dfb6f10

See more details on using hashes here.

File details

Details for the file sysmon2df-0.10-py3-none-any.whl.

File metadata

  • Download URL: sysmon2df-0.10-py3-none-any.whl
  • Upload date:
  • Size: 4.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for sysmon2df-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 d1798960a66da4db4b88bdfcee1a87be817e1f34aa52d33bd5f4d4a693bcf160
MD5 46069723cfa72136b8b3fd3773464a44
BLAKE2b-256 9ec64a85977b1e684c282a67a8142e0c651fe935f39e652d3c5c4c20fc2b3811

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page