analyzing-powershell-script-block-logging — Claude Code skill: parse
This skill parses PowerShell Script Block Logging events from EVTX files and flags obfuscated commands, Base64 payloads and AMSI bypass attempts.
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-powershell-script-block-logging -a claude-codeWhat analyzing-powershell-script-block-logging does
The skill reads Microsoft-Windows-PowerShell%4Operational.evtx and pulls out Event ID 4104 entries. From each one it takes the script block text, the ScriptBlockId, and the MessageNumber and MessageTotal values. Scripts split across several events share a ScriptBlockId, so the skill concatenates the blocks in message order to recover the full command instead of a fragment.
Pattern matching then covers -EncodedCommand and FromBase64String, download cradles built on DownloadString, DownloadFile, Invoke-WebRequest and Net.WebClient, and AMSI bypass strings such as AmsiUtils and amsiInitFailed. Entropy scoring, tick-mark insertion and string concatenation catch the quieter obfuscation tricks. Output is a report with reconstructed scripts, risk scores and MITRE ATT&CK mappings.
You need Python 3.8 or newer plus python-evtx and lxml: pip install python-evtx lxml. The run line is python scripts/agent.py --evtx-file /path/to/PowerShell-Operational.evtx --output ps_analysis.json. If PowerShell Operational logging was never turned on for the host, there are no 4104 events in the file at all — check that before you dig in.
What it helps with
- rebuild a script split across several 4104 events
- decode a command hidden in Base64
- catch a download cradle built on
Net.WebClient - spot an AMSI bypass attempt in the log
- produce a report with MITRE ATT&CK mappings
Example prompts for the agent
- parse
PowerShell-Operational.evtxand list the reconstructed scripts with risk scores - find 4104 events with
-EncodedCommandand decode them - check the log for AMSI bypass patterns and
DownloadStringcradles
How to install analyzing-powershell-script-block-logging
1Skills CLI (Vercel)
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-powershell-script-block-logging -a claude-code2Manually: put the files in place
~/.claude/skills/analyzing-powershell-script-block-logging/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/analyzing-powershell-script-block-logging/
1Skills CLI (Vercel)
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-powershell-script-block-logging -a codex2Manually: put the files in place
.agents/skills/analyzing-powershell-script-block-logging/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-powershell-script-block-logging -a cursor2Manually: put the files in place
.cursor/skills/analyzing-powershell-script-block-logging/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install mukul975/Anthropic-Cybersecurity-Skills analyzing-powershell-script-block-logging2Manually: put the files in place
.github/skills/analyzing-powershell-script-block-logging/SKILL.md1Skills CLI (Vercel)
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-powershell-script-block-logging -a gemini-cli2Platform CLI
gemini skills install https://github.com/mukul975/Anthropic-Cybersecurity-Skills --path skills/analyzing-powershell-script-block-loggingManually: put the files in place
.devin/skills/analyzing-powershell-script-block-logging/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-powershell-script-block-logging -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about analyzing-powershell-script-block-logging
How do I install analyzing-powershell-script-block-logging in Claude?
Run npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill analyzing-powershell-script-block-logging -a claude-code. The skill lands in ~/.claude/skills/analyzing-powershell-script-block-logging/SKILL.md.
What does analyzing-powershell-script-block-logging do?
It parses PowerShell Script Block Logging (Event ID 4104) entries from EVTX files, reconstructs multi-block scripts and looks for obfuscation, encoded commands, download cradles and AMSI bypass attempts.
What do I need to run it?
Python 3.8 or newer with python-evtx and lxml installed. You also need the PowerShell Operational log file itself — without it there are no 4104 events to parse.
Source text
SKILL.md · Apache-2.0
---
name: analyzing-powershell-script-block-logging
description: Parse Windows PowerShell Script Block Logs (Event ID 4104) from EVTX
files to detect obfuscated commands, encoded payloads, and living-off-the-land techniques.
Uses python-evtx to extract and reconstruct multi-block scripts, applies entropy
analysis and pattern matching for Base64-encoded commands, Invoke-Expression abuse,
download cradles, and AMSI bypass attempts.
domain: cybersecurity
subdomain: security-operations
tags:
- powershell
- script-block-logging
- event-id-4104
- obfuscation-detection
- windows-forensics
- endpoint-security
version: '1.0'
author: mahipal
license: Apache-2.0
nist_csf:
- DE.CM-01
- RS.MA-01
- GV.OV-01
- DE.AE-02
mitre_attack:
- T1059.001
- T1027.010
- T1140
- T1105
---
# Analyzing PowerShell Script Block Logging
## When to Use
- When investigating security incidents that require analyzing powershell script block logging
- When building detection rules or threat hunting queries for this domain
- When SOC analysts need structured procedures for this analysis type
- When validating security monitoring coverage for related attack techniques
## Prerequisites
- Familiarity with security operations concepts and tools
- Access to a test or lab environment for safe execution
- Python 3.8+ with required dependencies installed
- Appropriate authorization for any testing activities
## Instructions
1. Install dependencies: `pip install python-evtx lxml`
2. Collect PowerShell Operational logs: `Microsoft-Windows-PowerShell%4Operational.evtx`
3. Parse Event ID 4104 entries using python-evtx to extract ScriptBlockText, ScriptBlockId, and MessageNumber/MessageTotal for multi-part script reconstruction.
4. Apply detection heuristics:
- Base64-encoded commands (`-EncodedCommand`, `FromBase64String`)
- Download cradles (`DownloadString`, `DownloadFile`, `Invoke-WebRequest`, `Net.WebClient`)
- AMSI bypass patterns (`AmsiUtils`, `amsiInitFailed`)
- Obfuscation indicators (high entropy, tick-mark insertion, string concatenation)
5. Generate a report with reconstructed scripts, risk scores, and MITRE ATT&CK mappings.
```bash
python scripts/agent.py --evtx-file /path/to/PowerShell-Operational.evtx --output ps_analysis.json
```
## Examples
### Detect Encoded Command Execution
```python
import base64
if "-encodedcommand" in script_text.lower():
encoded = script_text.split()[-1]
decoded = base64.b64decode(encoded).decode("utf-16-le")
```
### Reconstruct Multi-Block Script
Scripts split across multiple 4104 events share a `ScriptBlockId`. Concatenate blocks ordered by `MessageNumber` to recover the full script.
© mahipal · Apache-2.0 · mukul975/Anthropic-Cybersecurity-Skills