Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 36 ยท Memory Forensics

Memory Injection Indicators

Learn how defenders spot injected or hidden code in a memory image: memory protections, VAD regions, RWX pages, unbacked executable memory, malfind-style checks and what is normal versus suspicious.

Malware that wants to hide often runs inside another, trusted process, for instance by placing code in that process's memory so the operating system lists only a harmless name. This is called code injection. Defenders cannot see it in a process list, but a memory image shows it, because injected code must occupy memory marked as executable. This lesson explains what analysts look for. It is a defender's view: we describe the traces and give harmless simulations, not working injection or malware code.

Memory regions and protections

Each process's virtual address space is divided into regions with permissions:

Permission Meaning
R Read
W Write
X Execute

Normal programs follow a pattern. Program code is R-X (readable and executable, not writable). Data, heap and stack are RW- (writable, not executable). Regions are also backed or unbacked:

  • Image-backed (mapped from an executable or DLL file on disk): you can check that the contents match the file.
  • File-mapped data files.
  • Private / unbacked memory allocated by the process at run time (heap, stack, JIT buffers).

Windows keeps a tree of these regions per process, the VAD (Virtual Address Descriptor tree). Linux has /proc/<pid>/maps and vm_area_struct. Memory-forensics tools list them (windows.vadinfo, windows.malfind, linux.proc.Maps, linux.malfind).

What injection leaves behind

A process that was injected typically shows one or more of:

  1. Private memory that is executable. Ordinary programs rarely need executable private memory (JIT-compilers like browsers, .NET and Java runtimes are the main legitimate exceptions).
  2. Writable and executable (RWX) regions. Code that was written then run, or self-modifying code.
  3. A PE or ELF header in unbacked memory. Seeing MZ...This program cannot be run in DOS mode in private memory means an executable image was mapped by hand ("reflective loading").
  4. Mismatches between loaded modules and files, for example a DLL whose in-memory code differs from the disk copy (hollowing, patching).
  5. Threads whose start address is not inside a known module.
  6. Hidden modules: modules present in memory but missing from the loader's lists.
  7. Odd parent/child behaviour: a process started suspended and then altered ("process hollowing"), with the on-disk path not matching the memory image.
flowchart TD
    A["Process memory regions"] --> B{"Executable?"}
    B -- "no" --> N["Usually fine"]
    B -- "yes" --> C{"Backed by a file?"}
    C -- "yes" --> D["Check module matches disk"]
    C -- "no (private)" --> E{"Writable too (RWX)<br/>or contains a PE header?"}
    E -- "yes" --> F["High-priority lead"]
    E -- "no" --> G["Medium: check owner<br/>(browser JIT is normal)"]

A decision aid: unbacked executable memory is the strongest single clue.

Sample malfind-style output (read-only)

malfind prints regions that match the suspicious pattern and a short hex preview. Shortened, made-up sample (not produced here):

TEXT
$ vol -f mem.raw windows.malfind
PID  Process       Start VPN  Protection                    Hexdump
3244 notepad.exe   0x2a0000   PAGE_EXECUTE_READWRITE        4d 5a 90 00 03 00 00 00 ...

A notepad that owns a private PAGE_EXECUTE_READWRITE region beginning 4D 5A ("MZ") is a textbook lead: notepad has no reason to hold an executable image in private memory. Tools produce false positives too. Browsers, antivirus products and managed runtimes legitimately generate executable private memory, so judge each hit against what the process does.

A region-scanning stand-in

The program below holds a made-up list of memory regions for several processes and applies the rules above. Nothing in it injects or executes anything; it only inspects descriptions.

Python Flag suspicious regions in a made-up VAD list

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Chrome's JIT region is downgraded, but not ignored: attackers also abuse trusted programs, so you still compare with normal behaviour.

Comparing memory to disk

Another defensive technique is integrity checking of module code. The code of a DLL in memory should match the code in the file on disk (apart from relocations). If it differs, something patched it ("hooking"). Security tools and forensic plugins compare hashes of each code page.

Python Compare in-memory code pages with the file on disk

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Modified code pages in a system library, such as a hooked network function, are a classic sign of a rootkit or a legitimate security product that hooks functions on purpose. Context again decides.

Beyond Windows

  • Linux: look for executable anonymous mappings in maps, processes whose /proc/<pid>/exe is deleted, LD_PRELOAD entries and kernel modules missing from the module list.
  • macOS: unsigned code in signed processes, unusual dylibs.
  • Fileless scripts: PowerShell or Python code running in memory; check cmdline, script-block logs and strings (strings lesson).

Responding defensively

When you find an injected region:

  1. Record process, PID, address range, protection and a hash of the region.
  2. Dump the region to a file in your lab (never execute it) and hash it.
  3. Check strings and network connections of that process (process analysis).
  4. Look at disk and log evidence for how the code arrived.
  5. Share indicators (hashes, strings, addresses) with the response team; build detection rules.
  6. Analyse the dumped code only in an isolated sandbox with the right authorisation and skills.

Never run extracted code on your normal computer, and do not try to reproduce injection techniques against systems you do not own. This course teaches detection only.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which memory region is the strongest single clue of injected code?

    Ordinary programs rarely execute code from private memory that is not mapped from a file.
  2. 2. Why does malfind produce false positives?

    JIT compilers write code at run time, which looks like injection to a simple rule.
  3. 3. What does a PE header (MZ) in private memory of notepad.exe suggest?

    A full executable image in private memory means code was mapped manually, a common injection trait.
  4. 4. What should you do with an extracted suspicious region?

    Suspicious code is handled as dangerous evidence in isolation, never executed on a normal machine.

Summary

  • Normal code is R-X and file-backed; data is RW-; injection often leaves private executable (or RWX) memory.
  • Look for PE/ELF headers in unbacked memory, threads starting outside modules, hidden modules and modified code pages.
  • Tools like malfind give leads; JIT-based programs cause legitimate hits.
  • Compare in-memory code with the file on disk to detect patching or hooks.
  • Dump, hash and analyse suspicious regions only in isolation; never reproduce attacks on others' systems.

Next: back to the Digital Forensics course overview