The PowerShell Command Was Base64 Encoded
Everything looked normal at first.
There was no obvious malware name. No dramatic ransomware alert. No strange executable sitting on the desktop.
Just PowerShell, a long command line and a string of characters that looked meaningless.
But meaningless-looking command lines can still tell a very clear story.
In this Agent Foskett investigation, we look at how a Base64 encoded PowerShell command can hide activity from casual review, and how Microsoft Defender XDR with KQL can help defenders find the evidence.
Investigation focus
Learn how encoded PowerShell activity can be hunted through command-line evidence, parent processes and endpoint telemetry.
The suspicious detail
That does not automatically prove malicious activity. Administrators and scripts can use encoding for legitimate reasons.
But in an investigation, encoded PowerShell deserves attention because it can hide download commands, credential access attempts, payload staging, persistence logic or suspicious execution chains.
First hunt: find encoded PowerShell
- 1
- 2
- 3
- 4
- 5
- 6
- 7
DeviceProcessEvents | where Timestamp > ago(7d) | where FileName in~ ("powershell.exe", "pwsh.exe") | where ProcessCommandLine has_any ("-EncodedCommand", "-enc", "/enc") | project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessFileName | order by Timestamp desc
Show me recent PowerShell executions where the command line appears to use an encoded command.
What Agent Foskett checks next
Second hunt: suspicious parent processes
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
DeviceProcessEvents | where Timestamp > ago(7d) | where FileName in~ ("powershell.exe", "pwsh.exe") | where ProcessCommandLine has_any ("-EncodedCommand", "-enc", "/enc") | where InitiatingProcessFileName in~ ("winword.exe", "excel.exe", "outlook.exe", "wscript.exe", "mshta.exe") | project Timestamp, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine | order by Timestamp desc
Third hunt: look for network activity after execution
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
DeviceNetworkEvents | where Timestamp > ago(7d) | where InitiatingProcessFileName in~ ("powershell.exe", "pwsh.exe") | project Timestamp, DeviceName, RemoteUrl, RemoteIP, RemotePort, InitiatingProcessCommandLine | order by Timestamp desc
The investigation lesson
A strong Defender XDR investigation does not stop at the encoded string. It follows the process, the parent process, the user, the device, the command line and the network activity that followed.
Common mistakes
Related Agent Foskett investigations and KQL guides
Continue with Rundll32 Looked Legitimate, The Process Was Signed By Microsoft, KQL Threat Hunting Guide, Agent Foskett Academy, Microsoft Security and the GEMXIT Security Review.
Develop IT. Protect IT. GEMXIT PTY LTD | GEMXIT UK LTD