Theory · 8 min · Windows endpoint monitoring
PowerShell logging and encoded commands
Decode an encoded command and find the script that actually ran.
powershell.exe -EncodedCommand (often shortened to -enc or -e) takes a Base64 string of the command in UTF-16LE. Attackers use it to dodge simple string matching; admins sometimes use it to avoid quoting problems.
Decode it before judging: Base64 to bytes, then read the bytes as UTF-16LE. "SQBFAFgA" at the start decodes to "IEX", Invoke-Expression, a common start of a download cradle.
Script block logging writes event 4104 in Microsoft-Windows-PowerShell/Operational with the script text as PowerShell runs it, after decoding. PowerShell also logs suspicious script blocks on its own, even without the policy enabled.
The user’s PSReadLine history (ConsoleHost_history.txt) shows what was typed interactively, which helps tell hands-on-keyboard activity from a script.
Your turn: decide on a scenario. An alert shows "powershell -enc SQBFAFgAIAAoAE4AZQB3AC0ATwBiAGoAZQBjAHQA...". What is the best next step?
Do the interactive check Free, in the browser.
Sources
- about_PowerShell_exe (-EncodedCommand) Microsoft Learn
- about_Logging_Windows (script block logging, event 4104) Microsoft Learn
- ATT&CK T1059.001: Command and Scripting Interpreter: PowerShell MITRE ATT&CK v20