← All posts

macOS memory forensics: processes, kexts and kernel hooks from RAM

7 min read

macOS memory forensics has a reputation for being hard to get started with: the kernel moves with KASLR, the symbols live in a Kernel Debug Kit you have to find for the exact build, and many tools stopped maintaining their Mac support years ago. ramparser takes care of the setup and then runs the checks from part IV of The Art of Memory Forensics (chapters 29 and 30) on real XNU structures.

Scope first: this is Intel x86_64 macOS only. The libkern C++ object layouts used for IOKit notifiers were validated against 10.9.

From Darwin banner to symbols

The kernel's version string ("Darwin Kernel Version 13.2.0: … xnu-2422…") identifies the exact build. ramparser scans physical memory for every copy of it, then looks for the matching ISF without sending the banner anywhere. Volatility publishes its macOS ISFs, generated from each Kernel Debug Kit, as one large zip (85 MB). ramparser bundles a few of them, listed in a static index the browser downloads in full and matches locally. For any other build, the "Symbols needed" panel shows the banner and, from a second static index of the zip, the exact entry to extract (roughly 0.5 to 1 MB compressed); you load that file and the browser remembers it for the next dump of the same build.

With the ISF loaded, the foundation mirrors Volatility 3's Mac stacker:

  • KASLR shift. For each banner copy, the shift is its physical offset minus the ISF address of version. A candidate is accepted only if version_major at the shifted address holds the major number from the banner.
  • Kernel page tables. IdlePML4 gives the PML4 root (as a physical address on some releases, a kernel virtual address on others). The candidate is kept only if translating version through those tables lands back on the banner.

Every symbol is then its ISF address plus the shift.

Processes: three lists and a cross-view (mac_psxview)

ps and Activity Monitor read allproc. A rootkit that unlinks its proc from that list stays in other kernel structures, so ramparser collects processes from three sources:

  • allproc and zombproc;
  • the Mach tasks queue, following each task.bsd_info to its proc. The KDK's task layout can be a few bytes off the running kernel, so the bsd_info offset is calibrated near the ISF value and only trusted when it explains most sampled tasks;
  • the PID hash (pidhashtbl, chained through p_hash).

A process present in the task queue or PID hash but missing from allproc is flagged. One caught in SIDL (fork not finished) is reported as "being created", not as hidden. The processes panel shows a check mark per list, so the gap is visible at a glance.

Dead processes (mac_dead_procs)

When a process exits, its proc structure goes back to the proc zone's free list. A freed zone element keeps its contents except the first word, which becomes the free-list link. ramparser walks that list and keeps elements with a plausible PID and printable name, recovering PID, parent, name, start time and, when the credential is still readable, UID. These show as exited processes: short-lived tools (chown, curl, an installer script) that ran and ended before the capture.

Command lines, open files and sockets (mac_psaux, mac_lsof)

For each process, ramparser switches to its address space (proc.task → task.map → pmap.pm_cr3) and reads:

  • arguments: the block right below user_stack, p_argslen bytes long, holding the exec path then argv;
  • descriptors: p_fd → fd_ofiles, each fileproc typed as vnode, socket, pipe, kqueue, POSIX shared memory and so on. Vnode paths are rebuilt by walking v_parent up to the mount point;
  • sockets: family (inet, inet6, unix), protocol, local and remote endpoints, and TCP state. Internet sockets feed the same network view used for Windows and Linux.

Injected code (mac_malfind)

ramparser walks each process's vm_map entries and keeps those mapped both writable and executable. JIT regions are excluded: entries with the kernel's used_for_jit flag, or tagged as JavaScriptCore JIT memory (VM tags 64 and 65).

If a remaining W+X region starts with a Mach-O header, the check is critical: a Mach-O image in such memory was mapped by hand, not by dyld. Other W+X regions are listed as context with their VM tag and first 16 bytes, because some macOS components keep a few.

bash history (mac_bash)

For bash processes, the same history recovery used on Linux runs over the process's malloc zones (regions tagged VM_MEMORY_MALLOC*): it finds the #<epoch> timestamp strings and the HIST_ENTRY structures pointing at them, and feeds the commands into the command list with their times.

Kexts and hidden kexts (mac_lsmod_kext_map)

Loaded kexts come from the kmod chain. If the chain is cut short (an unreadable entry), ramparser rebuilds the list by scanning physical memory for kmod_info records.

A kernel rootkit unlinks its kext from that chain so kextstat does not show it, but its code stays allocated in g_kext_map. ramparser walks that map, keeps every allocation that starts with a Mach-O kext header, and subtracts the listed kexts. With an intact chain, an unlisted image is critical. When the list had to be rebuilt by scanning, hidden and not-acquired cannot be told apart, so the result is shown as context.

Third-party kexts are always listed for context; the acquisition driver (osxpmem, MacQuisition and similar) is labelled as such.

Kernel handler tables

Every handler is attributed to an owner: the kernel image, a loaded kext, or no loaded code. If an address falls in no listed kext, ramparser walks back to a MH_KEXT_BUNDLE header whose segments cover it, and names it "unlisted kext image". Code a rootkit copied into kernel memory has no image around it.

TableRule
BSD syscalls (sysent)every entry in the kernel image
Mach traps (mach_trap_table)every entry in the kernel image
MIG routines (mig_buckets)every entry in the kernel image
sysctl tree (sysctl__children)kexts allowed; no loaded code is critical, non-Apple owner is reviewed

For the first three, a kext owner is no excuse: Rubilyn-style rootkits patch sysent to hide processes, files and network activity. sysctl handlers are checked because rootkits replace the ones behind kern.proc or net.inet.tcp.pcblist to hide from ps and netstat.

Callbacks: TrustedBSD, filters, IOKit notifiers

The same owner logic applies to registered callbacks:

  • TrustedBSD policies (mac_policy_list): every mac_policy_ops callback of every policy. A policy sees, and can veto, every file, process and socket operation.
  • IP filters (ipv4_filters, ipv6_filters) and socket filters (sock_filter_head): code that sees every packet or every socket of a protocol.
  • IOKit notifiers (mac_notifiers): gNotifications maps each notification type to a set of _IOServiceNotifier objects; ramparser reads their handler and matching dictionary. A keylogger registers one to attach to every new keyboard.

A callback in no loaded kext is critical; one owned by a third-party kext is flagged for review; Apple-owned sets are clean.

System state and kernel log

ramparser also reads mounts (mountlist), interfaces with their addresses and promiscuous flag, the ARP table and IPv4 routes. A promiscuous interface is flagged as a possible sniffer, or shown as context when a bridge is up. The kernel message buffer (msgbufp, what dmesg prints) is shown oldest first.

String sweeps: heuristic by design

Next to the structured analysis, ramparser runs about fifty macOS string-sweep plugins: kext bundle ids, Safari URLs, quarantine attributes, code-signing artefacts, login items, Wi-Fi networks, FileVault, MDM profiles and more. They search raw memory for known strings and report what was resident. They do not walk structures and cannot prove anything is loaded or hooked. Some of them, such as syscall_names and kauth_strings, are explicitly symbol-name inventories, not integrity checks. Use them as leads, and take verdicts from the structured checks above.

Further reading