Lesson 3 of 14 · 20m
PowerShell Logging and Script Blocks
Script Block Logging (EID 4104) records the decoded script the `-enc` flag exists to hide — enable it, join split blocks, and alert on the `-version 2` downgrade.
A 4688 event lands in your SIEM: powershell.exe -enc SQBFAFgA… followed by four hundred characters of base64. The attacker is betting you can't read it, and without Script Block Logging, they're right. With it, the decoded script — every IEX, DownloadString, and FromBase64String — arrives in your logs in plain text. Command lines are what the attacker typed. Script blocks are what the engine ran.
Turn it on
Enable Turn on PowerShell Script Block Logging under Computer Configuration → Administrative Templates → Windows Components → Windows PowerShell (registry equivalent: HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging, EnableScriptBlockLogging = 1). Events land in Microsoft-Windows-PowerShell/Operational as EID 4104.
Two details that matter at query time. First, long scripts are split across multiple 4104 events sharing one ScriptBlockId — join on ScriptBlockId and order by MessageNumber/MessageTotal before you pattern-match, or a rule matching a string that spans the split never fires. Second, PowerShell 5+ automatically logs script blocks containing suspicious commands even without the policy — you get the worst fragments for free, but only fragments. Enable the policy anyway.
One gotcha:
pwsh.exe(PowerShell 7) does not read the Windows PowerShell policy keys — it logs 4104 toPowerShellCore/Operationaland needs Script Block Logging enabled through its own settings and policy paths. Most orgs forget pwsh entirely.
The rest of the logging stack
Module Logging (EID 4103, same channel) records pipeline execution detail per named module — Microsoft.PowerShell.*, Netsecurity, whatever you list in the GPO. It's the deepest visibility PowerShell offers and it's extremely noisy: enable it for a hunting window, not as permanent posture.
Transcription writes full session transcripts to files on disk. Useful forensically, but the transcript sits where the attacker can read and delete it — treat it as evidence that can be tampered with, not telemetry. Microsoft-Windows-PowerShell/Operational 4104s are the durable record.
AMSI (Antimalware Scan Interface) is built into PowerShell 5+: before a script executes, its content is scanned in memory — including content that never touched disk. It catches obfuscated payloads that no command-line rule could. Bypasses exist and are public — AmsiScanBuffer patching, amsiInitFailed coercion — but every published bypass is a distinctive string, which means bypass attempts are themselves detection opportunities. Alert on amsi artifacts in 4104 content.
The downgrade play
powershell.exe -version 2 asks for the .NET 2.0-era engine, which has no Script Block Logging, no AMSI, nothing — the attacker types -enc garbage and your fancy logging stack watches version 2 execute it blind. It only works where the PowerShell 2.0 optional feature is still enabled, which is exactly why you alert on it: nobody has a legitimate reason. Match -v, -ve, -ver, -version followed by 2 in the command line, and watch the classic Windows PowerShell log's EID 400 — its EngineVersion field reports which engine started.
Remoting changes where the telemetry lands
Invoke-Command and Enter-PSSession don't execute code on the source host — the commands run inside wsmprovhost.exe on the target, and the script blocks land in the target's 4104 stream. On the target, WinRM's Operational log adds EID 91 (shell creation) and 168 (authorization). If you only collect PowerShell logs from endpoints users sit at, remoting-based lateral movement — which is most of it — happens off-camera.
Two adjacent hardening facts shape what the logs can tell you. Constrained Language Mode — enforced by AppLocker/WDAC policy — removes the .NET surface attackers lean on (Add-Type, COM, P/Invoke), and enforcement drops ScriptBlock warnings into the log when code demands full language. And JEA (Just Enough Administration) endpoints constrain remoting to whitelisted commands — the 4104 stream from a JEA endpoint is short and predictable, so anything unusual there is loud.
The practice
Enable Script Block Logging by GPO on every managed host; enable it for pwsh separately. Alert on three things in 4104 content: encoding/decoding primitives (FromBase64String, IEX wrapping a variable), AMSI tampering strings, and network cradles (DownloadString, Invoke-WebRequest, Net.WebClient). Alert on -version 2 anywhere. Forward Microsoft-Windows-PowerShell/Operational from servers with the same priority as workstations — lateral movement lands there.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Immich Had Fourteen Advisories and One Bug It Fixed Three Times
Immich's 2026 security record runs to fourteen advisories, and they cluster hard: the sharing features, the OAuth plumbing, and one login redirect parameter that took three separate fixes across eighty-three days. Plus the 3.0 migration traps still waiting for anyone who hasn't jumped yet.
Jellyfin's Threat Model Is Your Brother-in-Law
Four Jellyfin CVEs landed in 2026 and not one of them needs an admin account. One needs only the ability to name a file. Meanwhile Jellyfin 12 shipped in September, the version numbers stopped starting with 10, and every "am I patched" check you wrote is now wrong.
Node.js Fixed 16 Flaws in One Release. Most of Them Live in HTTP/2 and TLS.
The November 11 Node.js security releases fix 16 CVEs across the 26, 24 and 22 lines, seven of them rated high. Nearly all sit in HTTP/2 and TLS, where a remote client can crash a server, leak memory, or get past per-host client-certificate checks.
Next.js Shipped Seven Advisories and Six of Them Are the Cache
The November 2026 Next.js security release patches seven issues, and six live in the new Cache Components layer, the feature meant to make your app faster by remembering more. Three hit self-hosted next start specifically: the ones Vercel's own platform quietly absorbs.