Linux Memory Forensics with Volatility 3: Detect Hidden Malware and Process Injection

Security tutorial - IT technology blog
Security tutorial - IT technology blog

Setting Up Volatility 3 in Under 5 Minutes

Standard administrative utilities fail the moment an adversary gets root access. If an attacker installs an LKM rootkit like Diamorphine, running ps aux, top, or netstat simply returns whatever filtered output the attacker wants you to see. Analyzing physical memory bypasses these hooked system calls entirely. What ran on the CPU leaves artifacts in RAM that userland tools cannot hide.

Volatility 3 replaces the legacy Python 2 framework with a modular Python 3 architecture. It also eliminates the headache of compiling monolithic profile zip files on exact kernel matches. Instead, it parses raw symbols from DWARF and ELF debug data, then stores them in compact Intermediate Symbol Format (ISF) JSON tables.

Clone the core repository and set up an isolated Python environment on your analysis rig:

# Install system build dependencies on Debian 12 or Ubuntu 22.04 LTS
sudo apt update && sudo apt install -y python3 python3-pip python3-venv git dwarfdump build-essential

# Clone the Volatility 3 framework
git clone https://github.com/volatilityfoundation/volatility3.git
cd volatility3

# Initialize a clean virtual environment and install core wheels
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

# Verify the installation and check loaded symbols
python3 vol.py -h

Before shutting down or touching disk blocks on the target machine, capture volatile memory. LiME (Linux Memory Extractor) builds directly into a loadable module and reads directly from /dev/fmem or system memory buses. Rather than writing to the local root disk—which risks overwriting deleted files in unallocated space—pipe the raw image to an external mount or stream it over the wire:

# Build LiME against the target kernel header package
git clone https://github.com/504ensicsLabs/LiME.git
cd LiME/src && make

# Stream an exact 16 GB raw dump directly across the network to your IR host
# Listener on forensic workstation (192.168.10.50): nc -l -p 4444 > host01_16gb_dump.raw
sudo insmod lime-$(uname -r).ko "path=tcp:192.168.10.50:4444 format=raw"
sudo rmmod lime

Record the SHA-256 hash immediately after transmission finishes.

Generating Kernel Symbols and Hunting Hidden Processes

Disk logs are brittle. A single shred /var/log/auth.log or an in-memory execution via memfd_create leaves almost no filesystem trail. Memory dumps tell a different story. They preserve socket file descriptors, loaded kernel modules, and running process structures.

Generating Intermediate Symbol Tables (ISF)

Volatility 3 requires an ISF symbol file matching the target’s build string (such as 5.15.0-88-generic). Generate this file on a clean staging box running the exact same distribution and patch level:

# Install kernel debug symbols on Ubuntu
sudo apt install -y linux-image-$(uname -r)-dbgsym

# Download the official dwarf2json conversion binary
wget https://github.com/volatilityfoundation/dwarf2json/releases/download/v0.8.0/dwarf2json-linux-amd64
chmod +x dwarf2json-linux-amd64

# Extract DWARF symbols and kernel maps into an ISF JSON table
./dwarf2json-linux-amd64 linux \
  --elf /usr/lib/debug/boot/vmlinux-$(uname -r) \
  --system-map /boot/System.map-$(uname -r) > linux-$(uname -r).json

# Drop the generated JSON table into Volatility's symbol store
cp linux-$(uname -r).json /path/to/volatility3/volatility3/symbols/linux/

Correlating Active Tasks vs. Memory Scans

Rootkits frequently delink hostile processes from the kernel’s circular doubly-linked list (the tasks pointer inside struct task_struct). Standard userland inspection relies on that linked list. To catch unlinked tasks, run two complementary scans:

# Walk the standard linked list of active tasks
python3 vol.py -f host01_16gb_dump.raw linux.pslist.PsList

# Carve memory pages to find unlinked task_struct blocks
python3 vol.py -f host01_16gb_dump.raw linux.psscan.PsScan

Compare both outputs side by side. If linux.psscan identifies a PID—such as PID 3241 running kworker_x86—that never appeared in linux.pslist, you have found Direct Kernel Object Manipulation (DKOM). The adversary broke the doubly-linked list. Despite the missing list link, the Linux CPU runqueues still schedule and execute the malicious thread.

Hunting Injected Payloads and Stealthy Modules

Modern Linux attackers rely heavily on in-memory execution. Common techniques include ptrace process injection, dynamic library tampering via LD_PRELOAD, and allocating anonymous pages with flags set to PROT_READ | PROT_WRITE | PROT_EXEC.

Auditing Memory Maps with linux.proc.Maps

Review the Virtual Memory Areas (VMAs) of suspicious processes. Production software enforces W^X (Write XOR Execute) protections. If an anonymous memory range lacking a backing file on disk shows write and execution rights, investigate immediately:

# Dump virtual memory areas for suspicious PID 3241
python3 vol.py -f host01_16gb_dump.raw linux.proc.Maps --pid 3241

# Filter for segments with read, write, and execute permissions
python3 vol.py -f host01_16gb_dump.raw linux.proc.Maps --pid 3241 | grep "rwx"

Spotting a 2 MB anonymous segment marked rwx at offset 0x7f44a8000000 usually means an unpacker or injected shellcode is active.

Dumping the Injected Memory Range

Extract that suspicious memory range directly to disk for analysis:

# Dump memory regions for PID 3241 into the evidence directory
mkdir -p ./evidence
python3 vol.py -f host01_16gb_dump.raw -o ./evidence/ linux.proc.Maps --pid 3241 --dump

Carve printable strings and run signature checks against the dumped binary artifacts:

# Extract ASCII and Unicode strings to locate command-and-control artifacts
strings -a -n 8 ./evidence/pid.3241.*.dmp | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}|http"

# Scan the dumped VMA segments with YARA rule sets
yara -r -s /opt/signatures/linux_malware_rules.yar ./evidence/

Checking Kernel System Call Tables and Modules

Rootkits frequently hook pointers in the sys_call_table, intercepting calls like sys_read or sys_getdents64. Scan for modules omitted from standard accounting structures:

# Inspect the kernel module list for unlinked objects
python3 vol.py -f host01_16gb_dump.raw linux.lsmod.Lsmod

# Correlate active listening and established TCP sockets with processes
python3 vol.py -f host01_16gb_dump.raw linux.sockstat.Sockstat

Field Guidance for Production Incidents

  • Preserve cryptographic integrity: Run sha256sum host01_16gb_dump.raw > host01_16gb_dump.raw.sha256 immediately upon acquisition. A missing or mismatched hash compromises evidentiary value in any formal investigation.
  • Account for zram and compressed swap: Many default Ubuntu and Fedora installations run swap on zram. Because memory pages are compressed in LZO or zstd blocks, traditional byte carving across those pages can fail. Verify whether /proc/swaps uses zram devices during your initial triage.
  • Pre-generate symbol profiles for your fleet: Never waste critical incident response hours compiling DWARF tables. Script a pipeline that extracts dwarf2json profiles automatically whenever your CI/CD systems build or patch production server kernels.
  • Cross-reference open ports with process IDs: Sophisticated backdoor implants often hook raw sockets or use eBPF filters without spawning a dedicated child shell. If linux.sockstat shows an established outbound connection to an unknown IP on port 4444, track its socket inode directly back to the owning struct sock pointer.
Share: