PowerShell Attack & Detection Techniques
Overview
PowerShell is a robust task automation framework built into Windows. Its deep system integration, .NET access, and remote execution capabilities make it an essential tool for both system administrators and attackers. This guide covers offensive techniques mapped to MITRE ATT&CK tactics with comprehensive detection and defence strategies.
Learning Workflow
Phase 1: Foundations — PowerShell internals, security controls, logging Phase 2: Reconnaissance — Network/AD enumeration, service discovery Phase 3: Initial Access — Download cradles, payload delivery, phishing Phase 4: Execution — Script execution, fileless attacks, AMSI bypass Phase 5: Persistence — Registry, scheduled tasks, WMI subscriptions Phase 6: Privilege Escalation — UAC bypass, token manipulation Phase 7: Defence Evasion — Obfuscation, logging bypass, AMSI evasion Phase 8: Credential Access — Mimikatz, SAM dumping, credential harvesting Phase 9: Discovery — System/network/AD enumeration Phase 10: Lateral Movement — PSRemoting, WMI, DCOM, SMB Phase 11: Collection — Data staging, clipboard, keylogging Phase 12: Command & Control — C2 frameworks, reverse shells Phase 13: Exfiltration — Data transfer, covert channels
Phase 1: PowerShell Foundations
PowerShell Versions & Locations
2.0
Win 7/2008 R2
Basic, often used for downgrade attacks
3.0
Win 8/2012
Workflows, scheduled jobs
4.0
Win 8.1/2012 R2
Desired State Configuration
5.0
Win 10/2016
Classes, Script Block Logging
5.1
Win 10/2016+
Latest Windows PowerShell
7.x
Cross-platform
PowerShell Core (pwsh.exe)
# Check PowerShell version
$PSVersionTable.PSVersion
$host.Version
# PowerShell locations
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe # 64-bit
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe # 32-bit
C:\Program Files\PowerShell\7\pwsh.exe # PS Core
# Force specific version (downgrade attack)
powershell.exe -Version 2 -Command "Get-Host"Execution Policies
Restricted
No scripts allowed (default on clients)
AllSigned
Only signed scripts
RemoteSigned
Local scripts run; remote need signing
Unrestricted
All scripts run (warning for remote)
Bypass
Nothing blocked, no warnings
Undefined
Remove policy at this scope
Security Controls
AMSI (Antimalware Scan Interface)
Constrained Language Mode
Script Block Logging
Transcription Logging
Important Event IDs
4103
PowerShell/Operational
Module logging
4104
PowerShell/Operational
Script block logging
4105
PowerShell/Operational
Script block start
4106
PowerShell/Operational
Script block stop
400
Windows PowerShell
Engine start
403
Windows PowerShell
Engine stop
500
Windows PowerShell
Command start
501
Windows PowerShell
Command stop
600
Windows PowerShell
Provider start
800
Windows PowerShell
Pipeline execution
Phase 2: Reconnaissance
Attack Techniques
Network Reconnaissance
Active Directory Reconnaissance
Service Enumeration
Detection Strategies
Log Analysis
Network Detection
Detection Script
Phase 3: Initial Access
Attack Techniques
Download Cradles
Encoded Commands
File Download Methods
Phishing Payloads
Detection Strategies
Log Indicators
Network Detection
Detection Script
Defensive Measures
Phase 4: Execution
Attack Techniques
Script Execution Methods
Fileless Execution
Alternative Execution Hosts
AMSI Bypass Techniques
Detection Strategies
Log Analysis
Process Detection
Detection Script
Phase 5: Persistence
Attack Techniques
Registry Persistence
Scheduled Tasks
WMI Event Subscriptions
Service Persistence
Startup Folder
Detection Strategies
Registry Monitoring
Scheduled Task Monitoring
WMI Subscription Detection
Detection Script
Phase 6: Privilege Escalation
Attack Techniques
UAC Bypass Methods
Token Manipulation
Service Exploitation
AlwaysInstallElevated
DLL Hijacking
Detection Strategies
UAC Bypass Detection
Token Detection
Detection Script
Phase 7: Defense Evasion
Attack Techniques
Obfuscation Methods
Logging Evasion
AMSI Bypass Techniques
Process Injection
Living Off the Land
Detection Strategies
Obfuscation Detection
Logging Evasion Detection
Detection Script
Phase 8: Credential Access
Attack Techniques
Mimikatz via PowerShell
SAM/SYSTEM Dump
LSASS Dump
Credential Harvesting
Kerberos Attacks
Detection Strategies
Credential Dumping Detection
Detection Script
Phase 9: Discovery
Attack Techniques
System Enumeration
Network Enumeration
Active Directory Enumeration
Detection Strategies
Log Analysis
Detection Script
Phase 10: Lateral Movement
Attack Techniques
PowerShell Remoting
WMI Execution
SMB Execution
DCOM Execution
Pass the Hash/Ticket
Detection Strategies
Log Analysis
Detection Script
Phase 11: Collection
Attack Techniques
Data Staging
Clipboard Capture
Keylogging
Screenshot Capture
Detection Strategies
Phase 12: Command & Control
Attack Techniques
PowerShell Reverse Shells
HTTP/HTTPS C2
DNS C2
C2 Frameworks (PowerShell agents)
Detection Strategies
C2 Detection Script
Phase 13: Exfiltration
Attack Techniques
HTTP/HTTPS Exfiltration
DNS Exfiltration
Cloud Exfiltration
Email Exfiltration
Detection Strategies
Exfiltration Detection Script
Comprehensive Detection Script
Quick Reference Card
Common Attack Patterns
Download cradle
IEX (New-Object Net.WebClient).DownloadString(...)
Event 4104 + network indicators
Encoded command
powershell -EncodedCommand <base64>
Event 4104 + 4688
Persistence
Register-ScheduledTask, Run keys
Task Scheduler logs, registry audit
Credential dump
Invoke-Mimikatz, LSASS access
Event 4663, 4688
Lateral movement
Invoke-Command -ComputerName
WinRM logs, network logon events
C2 beacon
while($true){...Sleep...}
Network connections, Event 4104
Critical Event IDs
4104
PowerShell/Operational
Script block logging
4103
PowerShell/Operational
Module logging
400/403
Windows PowerShell
Engine start/stop
4688
Security
Process creation
4624
Security
Logon events
4663
Security
Object access
7045
System
Service creation
Defensive Controls
MITRE ATT&CK Mapping
Reconnaissance
T1595
Port scanning, AD queries
Initial Access
T1566
Phishing payloads, download cradles
Execution
T1059.001
PowerShell scripts, fileless malware
Persistence
T1053.005
Scheduled tasks
Persistence
T1547.001
Registry run keys
Privilege Escalation
T1548.002
UAC bypass
Defense Evasion
T1027
Obfuscation
Defense Evasion
T1562.001
Disable logging
Credential Access
T1003
Mimikatz, LSASS dump
Discovery
T1087
User/group enumeration
Lateral Movement
T1021.006
WinRM/PSRemoting
Collection
T1560
Archive/compress data
C2
T1071.001
HTTP/HTTPS channels
Exfiltration
T1041
Exfil over C2 channel
Last updated