Memory Forensics
A running machine tells an investigator things its disk never will: which keys are loaded, which code is executing without a file behind it, which commands were typed into a tool that never wrote to disk, and which processes are hiding from the operating system's own view. Memory forensics is the discipline of capturing that state defensibly and reading it systematically. Because volatile evidence disappears at the first reboot, this branch of forensics is also the one where sequencing mistakes are unrecoverable â you cannot come back for memory you failed to collect.
Why memory comes first
Modern intrusion techniques were designed against disk-centric defenses. Fileless loaders, reflective DLL injection, process hollowing, and living-off-the-land binaries all operate in memory, and their artifacts are mapping inconsistencies rather than files. A compromised host with a clean disk image is entirely possible; a compromised host whose memory is pristine is not. Beyond malware, RAM holds decrypted credentials, Kerberos tickets, SSH keys, cloud tokens and the plaintext of applications that only ever touch disk through an encrypted container.
| Volatile artifact | What it reveals | Why disk cannot supply it |
|---|---|---|
| Process list with mappings | Hollowed or replaced processes | Disk shows only the original image |
| Network sockets and owners | Live C2 channels and their process | Connections vanish on shutdown |
| Injected code regions | Shellcode and reflected loaders | Never written to a file |
| Cleared command history | Operator activity | Cleared before imaging |
| Hibernation and pagefile | Partial snapshots of past memory | Written on schedule, not on demand |
| Key material and tickets | Credentials usable right now | Unavailable once the machine stops |
The practical consequence: capture order is fixed. Network state and authentication sessions first, then a memory image, then disk â powering off a machine "to keep it safe" is the most common way an investigation destroys its own best evidence.
Acquisition done right
A defensible memory image is acquired with a tool designed for the job â WinPmem, LiME on Linux, OSXPMEM on macOS â written to a location outside the suspect host, and hashed at the moment of collection. Live response commands run before acquisition to capture what acquisition alone will not, such as open files, connection ownership and loaded drivers.
#!/usr/bin/env bash
# Live acquisition sequence for a Linux host under investigation.
set -euo pipefail
STAMP=$(date -u +%Y%m%dT%H%M%SZ)
OUT=/evidence/case/memory-$STAMP
mkdir -p "$OUT"
# 1) Volatile state that is cheap to collect and easy to lose.
ss -tunap | tee "$OUT/connections.txt"
ps auxwf | tee "$OUT/processes.txt"
lsof -n | tee "$OUT/open-files.txt"
lsmod | tee "$OUT/modules.txt"
last -Fai | tee "$OUT/logins.txt"
# 2) Memory image before anything else runs the risk of a reboot.
sudo insmod lime.ko "path=$OUT/memory.lime format=lime" || \
sudo cp /proc/kcore "$OUT/kcore.raw"
# 3) Hash immediately: hash-at-collection is what survives challenge later.
sha256sum "$OUT"/* | tee "$OUT/HASHES.txt"
# 4) Preserve logs before an attacker can rotate or truncate them.
tar -C /var -czf "$OUT/var-log.tgz" log
journalctl --since "30 days ago" --no-pager | gzip > "$OUT/journal.gz"
# 5) Record who did what, so the acquisition itself is defensible.
{
echo "operator: $(whoami)"
echo "acquired: $STAMP"
echo "host: $(hostname)"
echo "tool: lime.ko / coreutils sha256sum"
} | tee "$OUT/PROVENANCE.txt"
Storage location deserves thought: writing a 32 GB image onto the suspect's own filesystem changes evidence and may fail halfway. Prefer an external device or a network mount on an isolated forensic VLAN, and confirm free space before you start.
The triage sequence
Full analysis of every artifact is slow, and triage exists to answer a prioritized set of questions quickly: is anything running that should not be, is anything hooked, where is the machine connected, and did anything execute from a location that should never execute. Working that order means a busy responder gets a defensible answer in twenty minutes and knows where to spend the next two hours.
#!/usr/bin/env bash
# Volatility 3 triage â ordered so each command answers one question.
set -euo pipefail
IMG=memory.lime
CASE=case204
vol -f "$IMG" windows.info | tee "$CASE/01-info.txt"
vol -f "$IMG" windows.pslist | tee "$CASE/02-processes.txt"
vol -f "$IMG" windows.pstree | tee "$CASE/03-tree.txt"
vol -f "$IMG" windows.cmdline | tee "$CASE/04-cmdlines.txt"
vol -f "$IMG" windows.netscan | tee "$CASE/05-network.txt"
vol -f "$IMG" windows.malfind | tee "$CASE/06-injected.txt"
vol -f "$IMG" windows.handles | tee "$CASE/07-handles.txt"
vol -f "$IMG" windows.dlllist | tee "$CASE/08-dlls.txt"
vol -f "$IMG" windows.registry.hivelist | tee "$CASE/09-hives.txt"
# Hunt for unsigned or out-of-path executables referenced by live processes.
grep -Ei 'temp|appdata|recycle|\\users\\public' "$CASE/04-cmdlines.txt" \
> "$CASE/suspicious-paths.txt" || true
# Extract any process memory region flagged as injected for offline detonation.
vol -f "$IMG" windows.malfind --dump --output-dir "$CASE/dumps"
The output files are working copies derived from a hashed original, which is what lets another examiner reproduce the triage and reach the same conclusions.
Detecting injection from the image
The core signal of injection is inconsistency between what the operating system believes and what the process's memory actually contains: a private memory region containing executable code with no corresponding mapped file, a thread starting inside the heap, or an entry point in a DLL that does not match the file on disk. Those conditions are mechanical to detect once you know which structures to compare.
"""Flag process memory regions whose mapping and file-backed state disagree."""
def find_injected_regions(processes):
"""processes: iterable of dicts with name, pid, regions and mapped_modules."""
findings = []
for proc in processes:
mapped = {m["base"] for m in proc.get("mapped_modules", [])}
for region in proc.get("regions", []):
executable = region.get("protect", "").endswith("EXECUTE")
private = region.get("allocation_protect", "").endswith("PAGE_EXECUTE_READWRITE")
file_backed = region.get("mapped_file") is not None
if executable and private and not file_backed:
findings.append({
"pid": proc["pid"],
"process": proc["name"],
"type": "executable private memory with no backing file",
"range": f"{region['start']:#x}-{region['end']:#x}",
"severity": "high",
})
elif region.get("mapped_file") and region["mapped_file"] not in mapped:
findings.append({
"pid": proc["pid"],
"process": proc["name"],
"type": "mapped file not present in module list (unlinked module)",
"range": f"{region['start']:#x}-{region['end']:#x}",
"severity": "medium",
})
return findings
if __name__ == "__main__":
sample = [{
"name": "svchost.exe", "pid": 880,
"mapped_modules": [{"base": 0x7ff000000000}],
"regions": [
{"start": 0x1a0000, "end": 0x1b0000, "protect": "PAGE_EXECUTE_READWRITE",
"allocation_protect": "PAGE_EXECUTE_READWRITE", "mapped_file": None},
],
}]
for hit in find_injected_regions(sample):
print(hit["severity"], hit["process"], hit["type"])
A high-severity hit on a system process is a strong lead but not yet a finding: confirm it against the disk image, check whether the region contains a recognizable payload, and look for the network connection owned by the same process.
Reading process trees and command history
Triage outputs are only useful if you know what a healthy machine looks like, so the reading order is deliberate. Start with the process tree: legitimate processes have expected parents, and an orphan whose parent has exited, or a system binary spawned from a user profile path, is a lead worth thirty seconds immediately. Then read command lines, because operators are usually less careful than malware authors â an encoded PowerShell payload, a certificate download from a raw IP address, or a credential utility invoked with a dump switch will appear there in plain text even when the binary itself is gone.
Network output answers the third question: which processes own external connections, whether those destinations match the host's normal behavior, and whether a listener exists that no installer accounts for. Handles and loaded modules add the fourth: which files, registry keys and devices are held open, and which DLLs are mapped from unusual locations. Each of these four questions has a fixed answer pattern on a healthy host, and once those patterns are internalized, anomalies surface in seconds rather than through exhaustive reading of every line.
Timing matters too. Memory captures state at one instant, so correlate process creation times with logon sessions and with the disk timeline: a process that appeared minutes after an anomalous authentication is a far stronger lead than the same process in isolation.
High-value artifacts worth pulling early
Beyond injection, memory carries artifacts that accelerate an investigation far more than file recovery does: plaintext credentials for systems the machine was connected to, Kerberos tickets reusable elsewhere, browser sessions, cloud access tokens in environment blocks, and the command lines of tools such as Mimikatz or living-off-the-land binaries executed only in memory. Screenshot and console contents frequently show the attacker's own view of the environment.
đĄKnow what memory cannot give you
Full-disk encryption and post-lock screens limit what a live capture will reveal: on a locked machine with a cold hibernation file, you may recover less than expected. Record the machine's lock and power state at acquisition, because the absence of evidence means something different on a machine that was awake for eight hours versus one just woken from sleep.
Limits, and what to do next
Memory is a snapshot, not a history. It shows what is resident at acquisition; a DLL loaded and then freed, a file deleted an hour earlier, or a process that exited before collection will not appear. It also degrades interpretation when acquisition is delayed, when the image is truncated, or when the profile used by the analysis tool mismatches the kernel.
That is why memory work leads straight into disk analysis: registry hives give persistence and user activity, prefetch and amcache give execution evidence, event logs give authentication history, and together they build the timeline that memory alone cannot. The strongest cases pair a memory finding â injected code inside a process â with the disk artifact that explains how it arrived.
Common Mistakes
Powering off a suspect machine to preserve it
Fix: Capture volatile state and memory first, isolate at the network layer, then image the disk.
Writing the memory image to the suspect host
Fix: Acquire to external storage or an isolated forensic network with confirmed free space.
Running analysis before hashing
Fix: Hash at collection and re-verify after every transfer of the image.
Treating an injected region as proof of compromise on its own
Fix: Corroborate with disk artifacts, network connections and the process's actual behavior.
Skipping provenance notes during a rushed acquisition
Fix: Record operator, time, host and tool while collecting; reconstruction afterwards is guesswork.
Best Practices
- Follow order of volatility strictly: network state, memory, then disk.
- Use a purpose-built acquisition tool per platform and write off-host.
- Run a fixed triage command sequence so results are comparable across cases.
- Pair every memory finding with corroborating disk or network evidence.
- Document lock state, uptime and environment at the time of acquisition.
Key Takeaways
- Memory is irreplaceable evidence; rebooting destroys it permanently.
- Injection shows up as inconsistency between mappings and file-backed modules.
- A consistent triage order gets a defensible answer fast and tells you where to look next.
- Memory holds live credentials and command history that no disk artifact will contain.
- A snapshot without provenance and hashes is difficult to defend; hash at collection.
- Memory findings must be corroborated with disk, log and network evidence.