Chapter 15 · Reading 2 of 3
Injected and fileless code
CHFI domains 1, 4, 5, 6
Process 6120 on the library workstation calls itself svchost.exe, but the file it was started from has been deleted, and its parent was a script. Much of what it is doing may exist only in memory. This kind of activity is designed to leave as little as possible on the disk, which is exactly why memory and a few specific disk locations matter so much.
What “fileless” means
Fileless malware is a loose term for malicious activity that avoids writing a conventional executable to disk. It uses legitimate tools already on the system, such as PowerShell, the Windows Script Host, WMI and rundll32, keeps its payloads in memory or in the registry and often deletes its initial files. Very little is truly fileless. Something usually starts it and something usually keeps it running across reboots, and those are the traces the examiner hunts.
Find injected code with malfind
Process injection places code into another process’s memory and runs it there, hiding inside a trusted process. Windows describes each process’s memory regions with virtual address descriptors (VADs), which record each region’s protection and whether it is mapped from a file. Normal executable code comes from mapped image files and is not writable. Volatility’s windows.malfind flags regions that are private (not backed by a file), executable and often writable, and shows their first bytes.
PID Process Start VPN Tag Protection 6120 svchost.exe 0x1f0000 VadS PAGE_EXECUTE_READWRITE 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 MZ..............
- VadS marks private memory, not mapped from a file.
- Readable, writable and executable at once, which normal code rarely needs.
- The region begins with MZ, the signature of a Windows executable.
A whole executable sitting in private memory suggests it was written there directly. Variations include process hollowing, in which a legitimate process is started suspended, its code replaced with malicious code and then resumed, so the process keeps its innocent name and path while running something else, and reflective DLL loading, in which a DLL loads itself from memory without the Windows loader. Just-in-time compilers in browsers and .NET applications also create executable private memory, so malfind produces false positives. Each hit is checked for content, such as a PE header, shellcode patterns or known strings. The region can be dumped with --dump and scanned with YARA or antivirus engines.
GOOTLOADER: a case study
The command line from Reading 1, a .js file named like a legal document template, fits a well-documented loader family. GOOTLOADER spreads through search-engine poisoning: compromised websites, often running WordPress, are made to rank for searches for legal agreements and templates. A victim who downloads the “template” receives a ZIP archive containing a JavaScript file. Double-clicking it runs the script in wscript.exe. Reported behavior includes creating a scheduled task for persistence, launching PowerShell, storing later-stage code in the registry and loading payloads directly into memory, which have included post-exploitation frameworks used to prepare ransomware. Details change between versions, so the examiner uses public reporting as a guide to where to look, not as a substitute for the evidence.
- Delivery
- Browser history and downloads: a search for “library lease agreement template”, a ZIP from a small business website. Zone.Identifier on the extracted .js file.
- Execution
- Memory: wscript.exe running the .js file. Prefetch for WSCRIPT.EXE. Event logs for PowerShell 4104 script blocks.
- Persistence
- A scheduled task registered at 14:08 (Task Scheduler 106), running wscript.exe with a renamed .js file in the user’s AppData.
- In memory only
- The injected executable in PID 6120 and its connection to 203.0.113.61. Dumped from the image for analysis.
Check the persistence locations
Whatever the family, fileless activity usually persists in a short list of places, which the examiner checks in both memory and the disk image: Run and RunOnce registry keys, scheduled tasks (the Task Scheduler log and the task files in C:\Windows\System32\Tasks\), services (event 7045 and the SYSTEM hive), WMI event subscriptions (stored in the WMI repository), startup folders and large or encoded values in user registry hives. Volatility’s registry plugins, such as windows.registry.printkey, read keys straight from memory, including recently written values not yet flushed to disk.
On the exam, PAGE_EXECUTE_READWRITE in private memory with an MZ header suggests injection, hollowing keeps a legitimate process name while replacing its code, and fileless malware still needs something to start and persist it. The next reading, Static and dynamic malware examination, examines the samples safely.
Inspect the three records, then use the evidence to answer the question.
1. Protection
PAGE_EXECUTE_READWRITE
2. Type
Private memory (VadS), not mapped from a file
3. First bytes
4D 5A 90 00 03 00 00 00
Apply the reading
malfind reports a region with PAGE_EXECUTE_READWRITE protection in explorer.exe that begins with MZ. Why is that significant?
Compare your reasoning
Normal code is loaded from mapped image files and is not usually both writable and executable. A private, executable and writable region starting with an MZ header suggests a PE file was written into the process directly, a common sign of injection.