Event ID 4103
Event ID 4103: PowerShell Module Logging
PowerShell module logging: pipeline execution details
- Log source
- Microsoft-Windows-PowerShell/Operational
- How to enable it
- Group Policy: Turn on Module Logging, with * as the module name
- Category
- Process Execution
- Priority
- Medium
- Typical volume
- High
- MITRE ATT&CK
What Event ID 4103 means
4103 records what PowerShell commands did as they ran. Each event describes a pipeline: which cmdlet was called and which values were bound to its parameters, after variables and string tricks have been resolved.
That is its advantage over 4104. Script block logging shows the code as written, which may be obfuscated. Module logging shows the result, so a script that builds a URL from twenty fragments ends with a plain address in ParameterBinding. Reading both gives intent and effect.
It must be switched on for named modules, and * covers all of them. The output can be large, and it includes whatever was passed as a parameter, sometimes passwords. Collect it, but restrict who can read it.
Key fields to inspect
| Field | Meaning | Suspicious when |
|---|---|---|
Payload | Commands and bound parameters. | Invoke-WebRequest, Start-BitsTransfer, Get-ADUser -Filter *, Set-MpPreference, or Invoke-Command with many computers. |
ContextInfo | Host, user, script name, command type and runspace. | Host Application with -enc or -w hidden, or a script in a temporary folder. |
UserData | Additional data, normally empty. | Any content is unusual. |
UserID | Account SID, from the event header. | A service account, or SYSTEM outside management tools. |
ProcessID | PowerShell's process, from the event header. | Join it with process creation for the parent. |
Detection queries
Find download, discovery and tampering cmdlets with the values that were passed to them. Adjust names and thresholds to your environment. About these queries.
Splunk SPL
index=windows source="XmlWinEventLog:Microsoft-Windows-PowerShell/Operational" EventCode=4103
| regex Payload="(?i)CommandInvocation\((Invoke-WebRequest|Invoke-RestMethod|Start-BitsTransfer|Set-MpPreference|Add-MpPreference|Get-ADUser|Get-ADComputer|Invoke-Command|Enter-PSSession)\)"
| rex field=Payload max_match=10 "ParameterBinding\([^)]+\): name=\"(?<param>[^\"]+)\"; value=\"(?<value>[^\"]+)\""
| rex field=ContextInfo "User = (?<user>[^\r\n]+)"
| table _time Computer user param value Microsoft Sentinel KQL
Event
| where EventLog == "Microsoft-Windows-PowerShell/Operational" and EventID == 4103
| extend Payload = extract(@'Name="Payload">([^<]*)<', 1, EventData)
| extend ContextInfo = extract(@'Name="ContextInfo">([^<]*)<', 1, EventData)
| where Payload matches regex @"(?i)CommandInvocation\((Invoke-WebRequest|Invoke-RestMethod|Start-BitsTransfer|Set-MpPreference|Add-MpPreference|Get-ADUser|Get-ADComputer|Invoke-Command|Enter-PSSession)\)"
| extend User = extract(@"User = ([^\r\n]+)", 1, ContextInfo)
| project TimeGenerated, Computer, User, Payload PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'Microsoft-Windows-PowerShell/Operational'; Id = 4103; StartTime = (Get-Date).AddDays(-1) } |
ForEach-Object { $d = @{ Time = $_.TimeCreated }; ([xml]$_.ToXml()).Event.EventData.Data | ForEach-Object { $d[$_.Name] = $_.'#text' }; [pscustomobject]$d } |
Where-Object { $_.Payload -match 'Invoke-WebRequest|Start-BitsTransfer|MpPreference' } |
Select-Object Time, Payload, ContextInfo | Format-List Attack scenarios
Obfuscated downloader
4104 shows a wall of character codes and joins. 4103 for the same runspace shows Invoke-WebRequest or New-Object with the final URL and file path, ready to block.
Directory discovery
Get-ADUser and Get-ADComputer with wide filters and unusual properties, from an account that never manages the directory, indicate mapping before lateral movement.
Weakening Defender
Set-MpPreference with DisableRealtimeMonitoring, or Add-MpPreference with ExclusionPath, is recorded with its values. It is frequently the step just before malware is placed on the host.
Investigation checklist
- Read Host Application in ContextInfo to see how PowerShell was started.
- Collect every 4103 and 4104 with the same runspace identifier in order.
- Extract addresses, paths and computer names from the parameter values.
- Find the parent process in 4688 or Sysmon event 1.
Common benign causes
- Management agents that run PowerShell every few minutes.
- Administrators and scheduled reports that query the directory.
- Exchange, SQL Server and cloud modules, which are very talkative.
Event ID 4103 FAQ
How do I enable PowerShell module logging?
Enable the policy Turn on Module Logging under Windows Components, Windows PowerShell, and add * to the list of modules. PowerShell 7 has its own policy and its own log, PowerShellCore/Operational.
What is the difference between 4103 and 4104?
4104 holds the text of the script that was compiled. 4103 holds the commands that were executed, with their parameter values. Obfuscation that hides intent in 4104 often disappears in 4103.
Can event 4103 contain passwords?
Yes. Values passed as plain parameters are recorded. Limit access to the log, and use credential objects or secret stores in scripts instead of plain text.