Detection of Suspicious PowerShell WebRequest User-Agent Modification
Adversaries manipulate the User-Agent string in PowerShell web requests to masquerade C2 traffic as legitimate browser or application activity.
Adversaries frequently use PowerShell cmdlets such as Invoke-WebRequest, Invoke-RestMethod, iwr, and irm to perform C2 operations, data exfiltration, or payload delivery. To evade network-based detection, monitoring, or filtering, attackers modify the default PowerShell User-Agent string to match common browsers or legitimate software. By blending their communication patterns with standard HTTP/S traffic, they reduce the effectiveness of simple signatures targeting default PowerShell identifiers. Defenders must monitor PowerShell Script Block Logging for the combination of network-request cmdlets and the usage of the -UserAgent flag to identify potentially unauthorized outbound connections.
Impact
Successful abuse of PowerShell for network communication facilitates C2 channel establishment, lateral movement, and data exfiltration. If left undetected, this technique allows attackers to persist within the environment while remaining concealed within standard web traffic noise.
Recommendation
- Enable PowerShell Script Block Logging (Event ID 4104) to capture the full execution context of scripts containing web request cmdlets.
- Deploy the provided Sigma rule to your SIEM and tune against common internal administrative scripts that perform API calls with custom User-Agents.
- Baseline common internal PowerShell traffic to identify unauthorized use of Invoke-WebRequest or Invoke-RestMethod from non-administrative endpoints.
Immediate actions
Enable PowerShell Script Block Logging (Event ID 4104) across all endpoints
Threat Hunt
Search historical logs for PowerShell scripts containing '-UserAgent' and web request cmdlets
Data: ScriptBlockText
Detection coverage 1
Detect Suspicious PowerShell WebRequest User-Agent Modification
mediumDetects usage of Invoke-WebRequest or Invoke-RestMethod with a custom User-Agent, which is often used to blend C2 traffic with legitimate web activity.
Detection queries are available on the platform. Get full rules →