What it does. 'Hunt for malicious PowerShell activity by analyzing Script Block Logging Part of mukul975/Anthropic-Cybersecurity-Skills (817 security skills) (mukul975/Anthropic-Cybersecurity-Skills).
Install
npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill hunting-for-anomalous-powershell-execution, or copy the skill folder into ~/.claude/skills/hunting-for-anomalous-powershell-execution/.
- Raw file:
curl -sL https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/HEAD/skills/hunting-for-anomalous-powershell-execution/SKILL.md
SKILL.md (verbatim)
name: hunting-for-anomalous-powershell-execution
description: 'Hunt for malicious PowerShell activity by analyzing Script Block Logging
(Event 4104), Module Logging (Event 4103), and process creation events. The analyst
parses Windows Event Log EVTX files to detect obfuscated commands, AMSI bypass attempts,
encoded payloads, credential dumping keywords, and suspicious download cradles.
Activates for requests involving PowerShell threat hunting, script block analysis,
encoded command detection, or AMSI bypass identification.
'
domain: cybersecurity
subdomain: threat-hunting
tags:
- powershell
- script-block-logging
- event-4104
- amsi
- threat-hunting
- evtx
- obfuscation
version: '1.0'
author: mahipal
license: Apache-2.0
nist_csf:
- DE.CM-01
- DE.AE-02
- DE.AE-07
- ID.RA-05
mitre_attack:
- T1046
- T1057
- T1082
- T1083
- T1003
Hunting for Anomalous PowerShell Execution
Overview
PowerShell Script Block Logging (Event ID 4104) records the full deobfuscated script text
executed on a Windows endpoint, making it the primary data source for hunting malicious
PowerShell. Combined with Module Logging (4103) and process creation events, analysts can
detect encoded commands, AMSI bypass patterns, download cradles, credential theft tools,
and fileless attack techniques even when the attacker uses obfuscation layers.
When to Use
- When investigating security incidents that require hunting for anomalous powershell execution
- 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
- Windows Event Log exports (.evtx) from Microsoft-Windows-PowerShell/Operational
- Python 3.8+ with python-evtx and lxml libraries
- Script Block Logging enabled via Group Policy
- Understanding of common PowerShell attack techniques
Steps
- Parse EVTX files extracting Event 4104 script block text and metadata
- Reassemble multi-part script blocks using ScriptBlock ID correlation
- Scan script text for AMSI bypass indicators and obfuscation patterns
- Detect encoded command execution and base64 payloads
- Identify download cradles, credential dumping, and lateral movement commands
- Score and prioritize findings by threat severity
Expected Output
{
"total_events": 1247,
"suspicious_events": 23,
"amsi_bypass_attempts": 2,
"encoded_commands": 8,
"download_cradles": 5,
"credential_access": 3
}
Other files in this skill
references/api-reference.md (verbatim)
Hunting for Anomalous PowerShell Execution — API Reference
Windows Event Log IDs
| Event ID |
Log Source |
Description |
| 4104 |
Microsoft-Windows-PowerShell/Operational |
Script Block Logging — full deobfuscated script text |
| 4103 |
Microsoft-Windows-PowerShell/Operational |
Module Logging — pipeline execution details |
| 4688 |
Security |
Process Creation with command line auditing |
| 800 |
Windows PowerShell |
Pipeline execution (classic log) |
Event 4104 XML Fields
| Field |
Path |
Description |
| ScriptBlockText |
EventData/Data[@Name='ScriptBlockText'] |
Full script block content |
| ScriptBlockId |
EventData/Data[@Name='ScriptBlockId'] |
GUID linking multi-part blocks |
| MessageNumber |
EventData/Data[@Name='MessageNumber'] |
Part number for split blocks |
| MessageTotal |
EventData/Data[@Name='MessageTotal'] |
Total parts in split block |
| Path |
EventData/Data[@Name='Path'] |
Script file path (if applicable) |
AMSI Bypass Indicators
| Indicator |
Context |
System.Management.Automation.AmsiUtils |
Reflection access to AMSI internals |
amsiInitFailed |
Setting AMSI init flag to bypass scanning |
AmsiScanBuffer |
Patching the scan buffer function |
amsi.dll |
Direct DLL manipulation |
VirtualProtect |
Memory protection change for AMSI patching |
Marshal::Copy |
Overwriting AMSI function bytes in memory |
Suspicious PowerShell Keywords
| Keyword |
Category |
Invoke-Mimikatz |
Credential Dumping |
Invoke-Kerberoast |
Credential Access |
Invoke-ShellCode |
Code Injection |
Invoke-ReflectivePEInjection |
Process Injection |
PowerView |
Active Directory Enumeration |
SharpHound / BloodHound |
AD Attack Path Mapping |
Rubeus |
Kerberos Ticket Manipulation |
Out-Minidump |
LSASS Memory Dumping |
Download Cradle Patterns
| Pattern |
Example |
Net.WebClient |
(New-Object Net.WebClient).DownloadString(...) |
Invoke-WebRequest |
IWR -Uri http://... -OutFile ... |
DownloadString |
$wc.DownloadString('http://...') |
Start-BitsTransfer |
Start-BitsTransfer -Source http://... |
Invoke-RestMethod |
IRM http://... | IEX |
Obfuscation Indicators
| Pattern |
Description |
-EncodedCommand / -enc |
Base64-encoded PowerShell command |
IEX / Invoke-Expression |
Dynamic execution of string content |
[Convert]::FromBase64String |
Base64 decoding in script |
-join [char[]] |
Character array concatenation obfuscation |
.Replace() chaining |
String substitution for keyword evasion |
python-evtx Library Usage
import Evtx.Evtx as evtx
from lxml import etree
with evtx.Evtx("PowerShell-Operational.evtx") as log:
for record in log.records():
xml = record.xml()
root = etree.fromstring(xml.encode("utf-8"))
# Extract EventID, EventData fields
CLI Usage
# Hunt for suspicious PowerShell in EVTX file
python agent.py --evtx /path/to/PowerShell-Operational.evtx
# Limit events parsed
python agent.py --evtx logs.evtx --max-events 5000
# Save report to JSON
python agent.py --evtx logs.evtx --output hunt_report.json
Group Policy Settings for Script Block Logging
Computer Configuration > Administrative Templates > Windows Components
> Windows PowerShell > Turn on PowerShell Script Block Logging
-> Enabled
-> Log script block invocation start / stop events: Checked
External References
Back to mukul975/Anthropic-Cybersecurity-Skills (817 security skills) or Agent skills.