SSZcreate/Pentab_server / .agents/skills/cybersecurity/skills/detecting-suspicious-powershell-execution
detecting-suspicious-powershell-execution
FlaggedHunt for suspicious PowerShell execution (T1059.001) such as encoded commands, download cradles, AMSI bypass, and constrained language mode evasion using EDR telemetry (CrowdStrike, Microsoft Defender for Endpoint), Sysmon, and SIEM queries (Splunk, Elastic). Use when proactively threat hunting, triaging EDR/SIEM alerts, or scoping an incident involving malicious PowerShell activity.
| File | Kind | Size |
|---|---|---|
| LICENSE | other | 11.0 KB |
| SKILL.md | skill md | 3.6 KB |
| assets/template.md | markdown | 2.6 KB |
| references/api-reference.md | markdown | 2.5 KB |
| references/standards.md | markdown | 1.6 KB |
| references/workflows.md | markdown | 2.9 KB |
| scripts/agent.py | script | 5.9 KB |
| scripts/process.py | script | 3.7 KB |
references/api-reference.md
View on GitHub# API Reference: Suspicious PowerShell Execution Detection
## Windows PowerShell Event Logs
### Event IDs
| Event ID | Log | Description |
|----------|-----|-------------|
| 4104 | PowerShell/Operational | Script block logging |
| 4103 | PowerShell/Operational | Module logging |
| 800 | PowerShell | Pipeline execution details |
| 400 | PowerShell | Engine lifecycle (start) |
| 403 | PowerShell | Engine lifecycle (stop) |
### Script Block Logging Query
```powershell
Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-PowerShell/Operational'
Id = 4104
} -MaxEvents 100
```
### Event 4104 Properties
| Index | Field | Description |
|-------|-------|-------------|
| 0 | MessageNumber | Block sequence number |
| 1 | MessageTotal | Total blocks in script |
| 2 | ScriptBlockText | Actual script content |
| 3 | ScriptBlockId | Unique script ID |
| 4 | Path | Script file path |
## Suspicious PowerShell Patterns
### Execution Policy Bypass
```powershell
powershell -ExecutionPolicy Bypass -File script.ps1
powershell -ep bypass -nop -w hidden -enc <base64>
```
### Common Obfuscation Techniques
| Technique | Example |
|-----------|---------|
| Concatenation | `"Inv"+"oke-Ex"+"pression"` |
| Variable substitution | `${I`nv`oke-`Ex`pression}` |
| Encoded commands | `-enc SQBuAHYAbwBrAGUALQA...` |
| Char array | `[char[]]@(73,69,88) -join ''` |
## Sigma Detection Rules
### Suspicious PowerShell Command Line
```yaml
title: Suspicious PowerShell Invocation
logsource:
product: windows
category: process_creation
detection:
selection:
CommandLine|contains:
- '-enc'
- '-EncodedCommand'
- 'FromBase64String'
- 'DownloadString'
- 'Invoke-Expression'
condition: selection
level: high
```
## AMSI (Antimalware Scan Interface)
### AMSI Scan Functions
```c
HRESULT AmsiScanBuffer(
HAMSICONTEXT amsiContext,
PVOID buffer,
ULONG length,
LPCWSTR contentName,
HAMSISESSION amsiSession,
AMSI_RESULT *result
);
```
### AMSI Results
| Value | Meaning |
|-------|---------|
| 0 | Clean |
| 1 | Not Detected |
| 16384 | Blocked by admin |
| 32768 | Detected (malware) |
## Microsoft Defender ATP API
### Advanced Hunting Query
```http
POST https://api.security.microsoft.com/api/advancedqueries/run
Authorization: Bearer {token}
{
"Query": "DeviceProcessEvents | where FileName == 'powershell.exe' | where ProcessCommandLine has_any('encodedcommand','downloadstring','invoke-expression') | project Timestamp, DeviceName, ProcessCommandLine | take 100"
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 466k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 466k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 466k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |