CG
SkillsAnalyzing PowerShell Script Block Logging
Start Free
Back to Skills Library
Security Operations🟡 Intermediate

Analyzing PowerShell Script Block Logging

Parse Windows PowerShell Script Block Logs (Event ID 4104) from EVTX files to detect obfuscated commands, encoded payloads, and living-off-the-land techniques.

3 min read2 code examples

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)
  1. Generate a report with reconstructed scripts, risk scores, and MITRE ATT&CK mappings.
python scripts/agent.py --evtx-file /path/to/PowerShell-Operational.evtx --output ps_analysis.json

Examples

Detect Encoded Command Execution

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.

Verification Criteria

Confirm successful execution by validating:

  • [ ] All prerequisite tools and access requirements are satisfied
  • [ ] Each workflow step completed without errors
  • [ ] Output matches expected format and contains expected data
  • [ ] No security warnings or misconfigurations detected
  • [ ] Results are documented and evidence is preserved for audit

Compliance Framework Mapping

This skill supports compliance evidence collection across multiple frameworks:

  • SOC 2: CC7.1 (Monitoring), CC7.2 (Anomaly Detection), CC7.3 (Incident Identification)
  • ISO 27001: A.12.4 (Logging & Monitoring), A.16.1 (Security Incident Management)
  • NIST 800-53: AU-6 (Audit Review), SI-4 (System Monitoring), IR-5 (Incident Monitoring)
  • NIST CSF: DE.AE (Anomalies & Events), DE.CM (Continuous Monitoring)

Claw GRC Tip: When this skill is executed by a registered agent, compliance evidence is automatically captured and mapped to the relevant controls in your active frameworks.

Deploying This Skill with Claw GRC

Agent Execution

Register this skill with your Claw GRC agent for automated execution:

# Install via CLI
npx claw-grc skills add analyzing-powershell-script-block-logging

# Or load dynamically via MCP
grc.load_skill("analyzing-powershell-script-block-logging")

Audit Trail Integration

When executed through Claw GRC, every step of this skill generates tamper-evident audit records:

  • SHA-256 chain hashing ensures no step can be modified after execution
  • Evidence artifacts (configs, scan results, logs) are automatically attached to relevant controls
  • Trust score impact — successful execution increases your agent's trust score

Continuous Compliance

Schedule this skill for recurring execution to maintain continuous compliance posture. Claw GRC monitors for drift and alerts when re-execution is needed.

Use with Claw GRC Agents

This skill is fully compatible with Claw GRC's autonomous agent system. Deploy it to any registered agent via MCP, and every execution will be logged in the tamper-evident audit trail.

// Load this skill in your agent
npx claw-grc skills add analyzing-powershell-script-block-logging
// Or via MCP
grc.load_skill("analyzing-powershell-script-block-logging")

Tags

analyzingpowershellscriptblock

Related Skills

Security Operations

Analyzing API Gateway Access Logs

3m·intermediate
Security Operations

Analyzing Azure Activity Logs for Threats

3m·intermediate
Security Operations

Analyzing Cobalt Strike Malleable Profiles

3m·intermediate
Security Operations

Analyzing TLS Certificate Transparency Logs

3m·intermediate
Security Operations

Analyzing Web Server Logs for Intrusion

3m·intermediate
Security Operations

Analyzing Memory Forensics with LiME and Volatility

3m·advanced

Skill Details

Domain
Security Operations
Difficulty
intermediate
Read Time
3 min
Code Examples
2

On This Page

InstructionsExamplesVerification CriteriaCompliance Framework MappingDeploying This Skill with Claw GRC

Deploy This Skill

Add this skill to your Claw GRC agent and start automating.

Get Started Free →