Skip to content
Documentation

Sysmon lab capture

This page is published from the rig repository. Edit on GitHub View source

A procedure to record what the Sysmon event channel carries on a Windows guest, next to what driver-free ETW providers deliver, with tools/windows/capture-sysmon-etw.ps1. It answers which Sysmon event types the agent could read from the channel, at what volume and with which fields, and gives raw samples to build test fixtures from.

Sysmon installs a Windows service and a boot-start kernel driver. Run this procedure only in a disposable Windows VM, never on the host that runs it. Take a VM snapshot first and keep the VM's network restrictions in place.

The configuration

provisioning/sysmon-adr0026.xml enables only the event types the capture is about:

Event IDTypeRule
2File creation time changedAll
9Raw disk readAll
15Alternate data stream created (including Zone.Identifier)All
17, 18Named pipe created, connectedAll
23File deleted, with archiveOnly under C:\Lab\SysmonDeleteTest\
25Process image tamperingAll
26File deleted, no archiveAll

Sysmon's filter semantics are inverted from what the attribute names suggest: an event type with onmatch="exclude" and no rule logs everything, and one with onmatch="include" and no rule logs nothing. The file therefore uses exclude with no rule for each type captured whole. Event 23 is the exception: it archives a copy of every file it logs, so it is limited to one lab folder, and event 26 (the same deletions, no copy) covers the rest.

Events 4 (service state change), 16 (configuration change) and 255 (error) are generated by Sysmon itself and cannot be filtered. The configuration changes Sysmon's event selection only: not Defender, the firewall, the audit policy or any other protection.

Install in the VM

  1. Open an elevated PowerShell inside the VM. Check for an existing Sysmon service or channel first, and do not overwrite one:

    Get-Service -Name '*Sysmon*' -ErrorAction SilentlyContinue
    Get-WinEvent -ListLog '*Sysmon*' -ErrorAction SilentlyContinue |
        Format-Table LogName, IsEnabled, RecordCount
    
  2. Download Sysmon from Microsoft Sysinternals and extract it in the VM, for example to C:\Lab\Sysmon. Copy sysmon-adr0026.xml there.

  3. Check the configuration schema. The file declares schema 4.90; if the binary reports another, adjust only schemaversion:

    Set-Location C:\Lab\Sysmon
    .\Sysmon64.exe -s
    [xml](Get-Content -Raw .\sysmon-adr0026.xml) | Out-Null
    
  4. Install with the configuration:

    .\Sysmon64.exe -accepteula -i .\sysmon-adr0026.xml
    
  5. Enlarge the channel right away. Events 17, 18 and 26 are logged without any rule, so the default 64 MB channel can wrap during the capture, and a wrap drops the oldest records first, which are the rare ones (9, 25, 2, 23). For 1 GiB:

    wevtutil.exe sl 'Microsoft-Windows-Sysmon/Operational' /ms:1073741824
    
  6. Create C:\Lab\SysmonDeleteTest\ and, during the capture, delete a file in it to get an event 23. Watch free disk space: event 23 archives the deleted file's contents.

  7. Check that the filters took effect: .\Sysmon64.exe -c prints the active configuration, and events 2, 9, 15, 17, 18, 25 and 26 should appear within minutes of ordinary use (17 and 18 within seconds). An event type that stays absent is recorded as not seen; it does not prove Windows never emits it.

Capture

Check that the channel exists, then look at the newest records:

Get-WinEvent -ListLog '*Sysmon*' |
    Format-Table LogName, IsEnabled, RecordCount, MaximumSizeInBytes

Get-WinEvent -LogName 'Microsoft-Windows-Sysmon/Operational' -MaxEvents 20 |
    Select-Object TimeCreated, Id, ProviderName, Message

The install already produced a 4 (service started) and a 16 (configuration loaded), and the uninstall will produce a 4 (service stopped). Only 255 needs a deliberate failure, which this procedure does not induce: record it as not captured.

Get-WinEvent -FilterHashtable @{
    LogName = 'Microsoft-Windows-Sysmon/Operational'
    Id = @(4, 16, 255)
    StartTime = (Get-Date).AddHours(-2)
} -MaxEvents 100 | Select-Object TimeCreated, Id, Message

Run the capture from the root of the checkouts, as Administrator, without -SkipSysmon:

.\rig\tools\windows\capture-sysmon-etw.ps1 `
    -OutDir 'C:\Lab\sysmon-capture' `
    -IdleSeconds 60 -BusySeconds 60 -SysmonSample 5000

-SysmonSample analyses the newest events only, so a flood of 17 and 18 can push the rare IDs out of the sample: summary.txt is a view of the tail of the channel. Export the complete channel too, before uninstalling Sysmon or clearing any log:

wevtutil.exe epl 'Microsoft-Windows-Sysmon/Operational' `
    'C:\Lab\sysmon-capture\sysmon-operational.evtx' /ow:true

Keep the whole output directory: summary.txt, the raw Sysmon XML sample, the .etl files (needed to re-check provider data and loss counters with tracerpt or WPA) and the EVTX export. Review it before sharing: it holds the VM's host name, paths and process names.

Uninstall

Once the output is collected, from an elevated PowerShell inside the VM:

Set-Location C:\Lab\Sysmon
.\Sysmon64.exe -u

-u removes the Sysmon service and driver without a reboot. It does not delete the files created for the capture (the download, the configuration, the capture folder, the EVTX export, the event 23 archive), and it is not documented to erase the channel's existing records: export first, and check the channel afterwards rather than assuming it is empty. Restoring the VM snapshot is the cleanest end state.

References