Audit process creation events

Using standard Windows auditing mechanisms, you can log all process creation events. This also works in the Home editions of Windows.

  1. Enable auditing for process creation events:
    %windir%\system32\auditpol.exe /set /subcategory:"Process Creation" /success:enable /failure:enable
  2. Enable the Include command line in process creation events feature:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit]
    "ProcessCreationIncludeCmdLine_Enabled"=dword:00000001
    

    Download enable-command-line.reg

Every log message will contain this very verbose explanation:

Token Elevation Type indicates the type of token that was assigned to the new process in accordance with User Account Control policy.

Type 1 is a full token with no privileges removed or groups disabled.  A full token is only used if User Account Control is disabled or if the user is the built-in Administrator account or a service account.

Type 2 is an elevated token with no privileges removed or groups disabled.  An elevated token is used when User Account Control is enabled and the user chooses to start the program using Run as administrator.  An elevated token is also used when an application is configured to always require administrative privilege or to always require maximum privilege, and the user is a member of the Administrators group.

Type 3 is a limited token with administrative privileges removed and administrative groups disabled.  The limited token is used when User Account Control is enabled, the application does not require administrative privilege, and the user does not choose to start the program using Run as administrator.

This is particularly distracting when querying the event log from PowerShell. This PowerShell function therefore removes this explanation from each message:

function Get-ProcessAuditEvents
{
    param (
        [Parameter( Mandatory=$false )]
        [int]
        $MaxEvents = 10
    )

    Get-WinEvent -LogName Security -MaxEvents $MaxEvents | Where-Object { 
        $_.Id -eq 4688
    } | Sort-Object -Property TimeCreated | ForEach-Object {
        [pscustomobject] @{
            TimeCreated = $_.TimeCreated;
            Message     = [regex]::Replace( $_.Message, '\s+Token Elevation Type indicates.+$', 
                [string]::Empty, [System.Text.RegularExpressions.RegexOptions]::Singleline );
        };
    };
}

Use this function as follows:

PS> Get-ProcessAuditEvents -MaxEvents 1 | Format-List

TimeCreated : 2019-03-14 14:58:14
Message     : A new process has been created.

              Creator Subject:
                Security ID:            S-1-5-21-1863409349-3254288413-4204074520-1002
                Account Name:           Christoph
                Account Domain:         DESKTOP-ODVT8FN
                Logon ID:               0x63772

              Target Subject:
                Security ID:            S-1-0-0
                Account Name:           -
                Account Domain:         -
                Logon ID:               0x0

              Process Information:
                New Process ID:         0x874
                New Process Name:       C:\Windows\System32\notepad.exe
                Token Elevation Type:   %%1936
                Mandatory Label:                S-1-16-8192
                Creator Process ID:     0x1928
                Creator Process Name:   C:\Windows\explorer.exe
                Process Command Line:   "C:\Windows\system32\notepad.exe" c:\windows\system32\drivers\etc\hosts

You can also easily filter the events:

PS> Get-ProcessAuditEvents | Where-Object -Property Message -Match notepad | Format-List