Lion Cipher Lab

Detect malicious PowerShell with Script Block Logging (Event ID 4104)

Why it matters

PowerShell is the attacker's favourite tool on Windows because it is already installed, trusted, and endlessly flexible — and because attackers hide what it does. They base64-encode the command with -EncodedCommand, they build the real payload out of string fragments and hand it to Invoke-Expression (IEX), they pull code off the internet with a DownloadString cradle so nothing malicious ever touches disk. Process-command-line logging (Security log Event ID 4688, or Sysmon Event ID 1) only ever sees the OUTER command line — literally 'powershell.exe -EncodedCommand SQBFAFgA...' — a wall of…

What you'll learn

Steps in this lab

  1. The one idea: 4104 logs the script AS RUN, after it is decoded
  2. When 4104 beats command-line logging — and when it gets loud
  3. Turn it on the Home-friendly way: the registry value
  4. The same switch in Group Policy (Pro/Enterprise), and its noisier siblings
  5. Run benign PowerShell that is SHAPED like the real attacks
  6. Hunt the 4104 records — Event Viewer first, then Get-WinEvent
  7. The payoff: watch 4104 defeat the -EncodedCommand obfuscation
  8. Turn it into a detection: flag the suspicious script blocks
  9. The pro posture: 4104 plus AMSI plus Sysmon, and clean up

Open the full interactive lab →