The Command Line Told A Different Story
The process name looked normal.
The file was signed. The path was expected. The alert severity was not even high.
Then someone expanded ProcessCommandLine.
Hidden switches appeared. An encoded command appeared. A remote download appeared.
The executable looked ordinary.
The command line did not.
Command-Line Investigation
The alert named the process. The command line explained what the process was actually instructed to do.
The process looked ordinary. The arguments did not.
Why command lines matter
Find suspicious PowerShell command lines
- 1
- 2
- 3
- 4
- 5
- 6
- 7
DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where ProcessCommandLine has_any ("-enc", "-encodedcommand", "-windowstyle hidden", "-executionpolicy bypass", "downloadstring", "invoke-webrequest")
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine
| order by Timestamp descHunt for unusually long command lines
- 1
- 2
- 3
- 4
- 5
- 6
- 7
DeviceProcessEvents | where Timestamp > ago(7d) | extend CommandLineLength = strlen(ProcessCommandLine) | where CommandLineLength > 300 | project Timestamp, DeviceName, FileName, InitiatingProcessFileName, CommandLineLength, ProcessCommandLine | order by CommandLineLength desc
Find suspicious parent-child context
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
DeviceProcessEvents
| where Timestamp > ago(7d)
| where InitiatingProcessFileName in~ ("winword.exe", "excel.exe", "outlook.exe", "chrome.exe", "msedge.exe")
| where FileName in~ ("powershell.exe", "cmd.exe", "mshta.exe", "rundll32.exe", "regsvr32.exe")
| project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, InitiatingProcessCommandLine, FileName, ProcessCommandLine
| order by Timestamp descCorrelate the command with network activity
- 1
- 2
- 3
- 4
- 5
- 6
- 7
DeviceNetworkEvents
| where Timestamp > ago(7d)
| where InitiatingProcessFileName in~ ("powershell.exe", "pwsh.exe", "mshta.exe", "rundll32.exe")
| where InitiatingProcessCommandLine has_any ("-enc", "downloadstring", "invoke-webrequest", "http://", "https://")
| project Timestamp, DeviceName, InitiatingProcessFileName, InitiatingProcessCommandLine, RemoteUrl, RemoteIP, RemotePort
| order by Timestamp desc
