The PowerShell Never Triggered An Alert
Not every suspicious action arrives with a flashing red incident banner. Sometimes Microsoft Defender records exactly what happened, but the behaviour sits quietly in the telemetry until someone asks the right question.
In this Agent Foskett briefing, we look at how suspicious PowerShell activity can hide behind normal administration, browser activity, Office documents, encoded commands and living-off-the-land behaviour. The lesson is simple: no alert does not always mean no activity.
Briefing summary
PowerShell is not bad by itself. Administrators use it every day. Attackers use it for the same reason: it is powerful, trusted, scriptable and often already available.
Why PowerShell deserves attention
First hunt: suspicious PowerShell command lines
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
DeviceProcessEvents | where Timestamp > ago(7d) | where FileName in~ ("powershell.exe", "pwsh.exe") | where ProcessCommandLine has_any ( "-enc", "-encodedcommand", "FromBase64String", "-w hidden", "bypass", "downloadstring", "invoke-webrequest", "iwr", "iex" ) | project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine | order by Timestamp desc
Second hunt: Office or browser spawning PowerShell
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
DeviceProcessEvents | where Timestamp > ago(7d) | where FileName in~ ("powershell.exe", "pwsh.exe") | where InitiatingProcessFileName in~ ( "winword.exe", "excel.exe", "powerpnt.exe", "outlook.exe", "chrome.exe", "msedge.exe" ) | project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, FileName, ProcessCommandLine, InitiatingProcessCommandLine | order by Timestamp desc
Third hunt: LOLBins and suspicious script chains
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
DeviceProcessEvents | where Timestamp > ago(7d) | where FileName in~ ( "powershell.exe", "pwsh.exe", "cmd.exe", "mshta.exe", "rundll32.exe", "regsvr32.exe", "wscript.exe", "cscript.exe" ) | project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, FileName, ProcessCommandLine, FolderPath | order by Timestamp desc
Fourth hunt: suspicious outbound activity after script execution
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
DeviceNetworkEvents | where Timestamp > ago(7d) | where InitiatingProcessFileName in~ ( "powershell.exe", "pwsh.exe", "cmd.exe", "mshta.exe", "rundll32.exe", "wscript.exe" ) | project Timestamp, DeviceName, InitiatingProcessAccountName, InitiatingProcessFileName, InitiatingProcessCommandLine, RemoteIP, RemotePort, RemoteUrl | order by Timestamp desc
What to lock down after the hunt
Final thought
Continue the investigation with the KQL Threat Hunting Guide, Microsoft Defender KQL Guide and Microsoft Security Operations.
Develop IT. Protect IT. GEMXIT PTY LTD | GEMXIT UK LTD