Tag: malware analysis

  • Memory forensics for responders: what Volatility finds that disk forensics misses

    Memory forensics for responders: what Volatility finds that disk forensics misses

    The first time I watched someone pull a memory image off a compromised box before pulling the plug, I thought it was overkill. The disk was right there. Then the disk turned out to be clean. The implant had never been written to it.

    That story is why I care about memory forensics. Disk forensics tells you what was stored. Memory tells you what was running, what it was talking to, and what it had decrypted. For modern intrusions those are often different answers.

    What lives only in RAM

    Comparison chart of what a disk image and a memory image usually contain: memory covers running processes, injected code, command lines, network connections and kernel modules, disk covers installed files.

    The chart above is a hand-built illustration of typical evidence coverage, not measured data.

    Fileless and reflectively loaded malware is the obvious case. A loader that allocates executable memory, copies a payload in and jumps to it leaves nothing for a disk scanner to hash. Process hollowing works the same way: the binary on disk is still a perfectly normal svchost.exe, but the code running under that name isn’t.

    Other things that exist mainly or only in memory:

    • Command lines and environment variables of running processes, including arguments the attacker passed to a tool before deleting the script.
    • Network connections and listening sockets at the moment of capture, with the owning process.
    • Decrypted content. Packed payloads are plaintext once they run, and encrypted volumes are mounted with keys held in RAM.
    • Credentials in use, such as cached tickets and, on older or unprotected Windows setups, secrets in LSASS.
    • Kernel state: loaded drivers and modules, hooked system call tables, hidden processes.

    None of this replaces disk or log evidence. It covers what those two miss, and for kernel state it is the only place to look.

    Capture first

    Memory is the most volatile evidence you have. Every minute the machine runs you lose some of it, and a reboot loses all of it. Capture before you shut anything down. Network isolation is fine and usually right, since it doesn’t touch RAM.

    On Windows, WinPmem writes a raw image. On Linux there are two common options: LiME, a kernel module that has to be built for the running kernel, and AVML, a static binary from Microsoft that reads /proc/kcore or /dev/crash and writes LiME format without a module build.

    # Linux, AVML (run as root, write to external media, not the suspect disk)
    ./avml /mnt/evidence/host01.lime
    
    # Linux, LiME (module must be built for this exact kernel)
    insmod ./lime-$(uname -r).ko "path=/mnt/evidence/host01.lime format=lime"
    
    # Hash it and record who, when and how
    sha256sum /mnt/evidence/host01.lime | tee host01.lime.sha256

    Capturing changes memory. Your tool is now in RAM too. That’s acceptable, but write down what you ran and when.

    First pass with Volatility 3

    Volatility 3 is the current generation, a Python tool you run as vol or python3 vol.py. Windows images pull symbols from Microsoft’s symbol server on first use. Linux images need a symbol table (ISF) matching the exact kernel build, and that is the step that trips people up. If you manage a fleet, build and store symbol files for your standard kernels ahead of time. Doing it during an incident is miserable.

    Start with the process list, and run two plugins that disagree on purpose.

    vol -f host01.raw windows.pslist
    vol -f host01.raw windows.psscan
    vol -f host01.raw windows.pstree
    vol -f host01.raw windows.cmdline

    pslist walks the kernel’s active process list. psscan scans memory for process structures, so it also finds processes that were unlinked from the list or that already exited. A process in psscan and not in pslist deserves a long look, though an exited process isn’t automatically suspicious, so check the exit time first.

    pstree and cmdline give you parentage and arguments. Word spawning PowerShell with an encoded command is the classic, and I still see it more than anything fancier.

    Hunting injected code

    The plugin I reach for next is malfind. It looks for memory regions that are executable and not backed by a file on disk, which is what injected code and reflectively loaded payloads look like.

    vol -f host01.raw windows.malfind
    vol -f host01.raw -o ./dumps windows.malfind --dump
    vol -f host01.raw linux.malfind

    Expect false positives. Just-in-time compilers (browsers, .NET, Java) legitimately create executable anonymous memory, and some security products inject into every process. I treat malfind output as a list of leads: the region’s protection, the first bytes (an MZ header in a private region is hard to explain), and which process owns it. Dump the region and analyze it rather than trusting the plugin’s verdict.

    Network and persistence in memory

    vol -f host01.raw windows.netscan
    vol -f host01.raw windows.svcscan
    vol -f host01.raw windows.registry.hivelist
    vol -f host01.raw linux.sockstat
    vol -f host01.raw linux.lsmod

    netscan can show closed connections as well as live ones that are still resident in memory. That gives you a partial timeline of outbound traffic that firewall logs may not have if the attacker used an allowed port. Matching a remote address to a process you already flagged in the tree is the moment an investigation stops being a hunch.

    On Linux, kernel rootkits are where memory pays for itself. A module hidden from lsmod output can still be found by scanning memory, and a hooked system call table can show up with plugins like check_syscall, depending on kernel version and symbol support. Check the plugin list for your Volatility version, because Linux coverage moves quickly.

    Where it falls short

    Memory images are as large as the machine’s RAM, so you need space and a way to move them, and the capture is a single moment. If the attacker ran something an hour earlier and cleaned up, memory may have been overwritten since. Pages swapped to disk aren’t in the image unless you also collect the pagefile, and Windows hibernation and crash dump files are worth grabbing for the same reason.

    Defenses reduce what you find, too. Credential Guard moves secrets out of the LSASS process into an isolated one. That’s good for defenders even though it makes the forensics less satisfying. Some malware encrypts its payload while idle. And a kernel-level rootkit can lie to your capture tool if you acquire from inside the live OS, which is why hypervisor snapshots of VMs are so valuable: you capture from outside the guest.

    The practical version: if your servers are virtual machines, learn how to take a memory snapshot from the hypervisor before you need one. It is quicker than any agent, and the guest can’t interfere with it.

    What I’d set up now

    Choose a capture tool for each OS and test it on a lab machine. Store Linux symbol files for the kernels you run. Write a one-page procedure covering where the image goes, how it is hashed, and who can authorize a capture on a production host. Then infect a lab VM on purpose, capture it, and run the plugins above. That way the first time you read malfind output isn’t during a real incident.