Author: canutethegreat

  • 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.

  • Patronus: I switched on the guest network and tried to get out of it

    Patronus: I switched on the guest network and tried to get out of it

    Full disclosure: I make Patronus, a router and firewall OS built on Gentoo. The guest network page is the newest thing I’ve added to it. It went into main on November 17 and isn’t in a tagged release yet.

    Every router says guests can’t reach your LAN. I wanted to check that claim, so on November 22 I switched the guest network on in a lab and tried to reach the NAS, the router’s admin page, the modem and the other guest.

    The lab

    This was a lab, not my house. One container with a handful of network namespaces: the router (the real patronus-web plus the apply step, built from main at commit 02e0a2c7, 5 minutes 11 seconds cold in a capped container), one LAN device, two “visitor” devices on two spare router ports, a fake ISP and a fake internet. The NAS is a tiny web server on the LAN that answers “192.168.50.13 sees 192.168.50.10”. The ISP modem’s admin page is another one at 10.77.7.7, behind the WAN. Everything is curl and a DHCP client. I drove the admin page with a real browser, from the LAN device’s namespace.

    Some of it is fake or missing. There is no radio, so this is the wired half only: visitors are plugged into ports and the Wi-Fi switch stayed off. The visitors run busybox’s udhcpc, not a phone. The lab router has no resolver of its own, so I filled in the “Router DNS forwards to” box with the fake internet’s DNS server. The page still carries a “This router has not been set up yet” banner because I never ran the setup wizard in this lab.

    Turning it on

    The guest network is off until you switch it on, and everything lives on one page: /svc/guest. It’s one long form. I ticked the box, set the VLAN id to 0 (no VLAN, use ports only), listed the two spare ports, left the address at its default of 192.168.30.1/24, and set a per-guest download cap of 4000 kbit/s.

    The guest network settings form with the network switched on, extra ports gst-a and gst-b, address 192.168.30.1/24 and a per-guest download cap of 4000
    The settings form as I filled it in. The DNS forwarder box is only filled because my lab router has no resolver.

    Before the real save I tried to break it. I typed the LAN’s own subnet, 192.168.50.5/24, as the guest address. The page refused with “Invalid guest subnet 192.168.50.0/24 (overlaps 192.168.50.0/24 on rtr-lan; pick another address)”, and when I asked the API afterwards the address was still 192.168.30.1/24. The red box shows up at the top of the page though, above the part you’re looking at when you click Save, so on a laptop it looks like nothing happened until you scroll up.

    A red message reading Not applied: Configuration error: Invalid guest subnet 192.168.50.0/24 overlaps 192.168.50.0/24 on rtr-lan, above the settings card with the address field filled with 192.168.50.5/24
    The refusal. The stored address did not change.

    The real save took between 0.7 and 0.8 seconds in four runs, measured from the click to the status card saying the bridge is up. Then I plugged in the two visitors.

    The live status card showing bridge up yes, DHCP and DNS running yes, and two clients listed by address and MAC
    Status card with two guests. Clients are an address, a MAC and a star where a name would go.

    Being a visitor

    Both visitors got a lease from 192.168.30.1 with a 7200 second lease time (the default of 120 minutes), the router as gateway and DNS, and could fetch a page from the fake internet. The site saw the router’s WAN address, so the traffic is masqueraded. A ping to the router answers, which is a setting that defaults to on.

    Terminal output: a visitor runs udhcpc and gets 192.168.30.193 from 192.168.30.1, fetches www.example.test and sees the router's WAN address, and pings the router
    A visitor joins. Lab names and documentation addresses throughout.

    From the visitor I tried the NAS, the router’s admin page on its guest address, on its LAN address and on its WAN address, the modem’s page behind the WAN, and the other visitor. All six timed out. As a control, the LAN device fetched the NAS fine, and a LAN device trying to open a connection to a visitor also timed out, which is what the docs promise (nothing starts a connection into the guest network).

    Terminal output: the LAN device reaches the NAS, while the visitor's curl to the NAS, the router admin page on three addresses, the modem page and the other guest all end with exit 28, and a LAN device curling a guest also times out
    The LAN control fetch, then the six visitor probes. Exit 28 is curl giving up after 3 seconds.

    These are drops, so a visitor just waits for the timeout. I looked at the firewall to see why. The guest rules are their own nft table at priority -15, ahead of the main firewall, and its input chain ends with a drop commented “guests reach nothing else on the router”. The forward chain drops private ranges beyond the WAN, drops a source address that isn’t in the guest subnet, and the way back into the guest network only allows established flows.

    Output of nft list table inet patronus_guest: input chain allowing DHCP, DNS and ping then dropping, forward chains guest_out and to_guest, a per-guest download cap set, and a masquerade rule
    The kernel’s view of the guest network. I removed one line of live meter entries, nothing else.

    The speed cap

    I set 4000 kbit/s per guest, which is 500 kilobytes a second. Each visitor downloaded for 8 seconds from a bulk server and curl reported 576,369 and 580,724 bytes a second. Across four runs the figures stayed between 576,000 and 581,000, about 15 percent over the setting. The docs say per-guest caps are policed with nft meters, that packets over the rate are dropped and that TCP settles somewhere near it, and they estimate the error at “within about 20 percent”. The LAN device on the same server got about 8.3 gigabytes a second through the lab’s virtual links, so the cap is the only thing slowing the visitors. I only tested the per-guest download cap, not the network-wide caps or either upload cap.

    Terminal output: two visitors measured at about 576 and 581 kilobytes per second, and the LAN device at over 8 gigabytes per second
    Measured with curl over 8 seconds. The LAN device number is the lab’s virtual link, not a real speed.

    Closing it, and the clip

    The page has buttons: new Wi-Fi password, new voucher, open for a while, close now, and show the password with a QR code. I pressed close now. The visitor’s internet request timed out, and a DHCP renew still worked, so the device keeps its address. DNS and ping to the router were refused. The docs say that’s intended: while closed, DHCP still answers and nothing else does.

    Terminal output after pressing Close now: the visitor's curl times out, udhcpc renews a lease, ping to the router gets 100 percent loss, and a name lookup fails
    After Close now. The lease renews, nothing else works.

    The clip is a different run on the same lab, 37 seconds, real time. The router page is on top and a terminal is underneath: I switch it on from the form, a visitor joins, tries the NAS, the router page and the other visitor, I press close now, then open for a while, and the internet comes back. The two panes were recorded at the same time but separately, so don’t read anything into sub-second timing.

    Switch on, join, probe, close now, open for 120 minutes. Router page on top, terminal below. Lab clocks are real.

    The share card is the other button I used. It generates a 16 character password and shows it with the standard Wi-Fi join text and a QR code. It’s the demo password from my lab, and I didn’t scan the QR or join anything with it, because there is no radio in this lab.

    The Actions card with five buttons and, below them, the guest SSID, a WIFI join string with a password, and a QR code
    The share card. Password is from the throwaway lab.

    What the docs say about the design

    Several choices are written down in docs/GUEST-NETWORK.md. The guest network is one bridge. VLAN sub-interfaces, spare ports and the guest SSID all join it, the ports are isolated from each other, and the SSID runs client isolation. The doc says plainly that a guest VLAN that continues onto an unmanaged switch can’t be isolated by the router, because the trunk is one bridge port. Guests get their own dnsmasq bound to the guest address only. Schedules and timed windows are nft rules, written that way “so they close by themselves, with no daemon” and survive a reboot. Vouchers are WPA2-only because stock hostapd reads SAE passwords only at start. The intro says it follows the way pfSense and OPNsense guest VLANs, OpenWrt guest networks and UniFi and Firewalla guest networks work. I haven’t done a feature-by-feature comparison against any of them.

    The docs don’t say why the default is 192.168.30.0/24 on VLAN 30, or why leases are 120 minutes, or why it ships switched off. They also don’t say why guest IPv6 is dropped, only that it isn’t supported yet. I don’t know why.

    What doesn’t work (yet)

    Worst bug: the status card shows the wrong state for schedules. I set the access mode to a daily schedule of 03:00 to 04:00 and looked at the card at 18:25 and again at 18:37 on the lab clock. The card said “schedule 03:00-04:00” and “access now: open”. The visitor’s request timed out both times, because the firewall rules were doing their job. When I changed the window to 00:00 to 23:59 the visitor got through. The rules are right and the label is wrong. I read the status function in guest.rs and it never checks the clock for a schedule, it just reports open.

    The live status card showing ACCESS DETAIL schedule 03:00-04:00 and ACCESS NOW open
    The page says open. The visitor’s internet was closed when this was taken.

    Close now and Open for a while change the access mode to timed and leave it there. After “open for 120 minutes” the network closes by itself when the time runs out and stays shut until somebody opens it again, which the docs say. I didn’t wait it out. Switching back to always open is a separate step on the form.

    Smaller annoyances. The header says “Home / Svc-guest”; a commit this morning fixed names like DHCP and DNS in the breadcrumb and this page didn’t get the same treatment. The form has “Open until (epoch seconds)” as a raw number. The minutes for open-for-a-while and for a voucher come from the browser’s own popup boxes. The clients list is an address and a MAC with a star where a hostname would be, and there is no way to kick one, which the docs list under “not yet”. On a 390 pixel wide phone the Guest network checkbox floats awkwardly next to its label. The status card looks fine there, but I only skimmed the long settings form.

    The live status card on a 390 pixel wide phone, listing ACCESS DETAIL schedule 00:00-23:59, bridge up yes, two clients, DHCP and DNS running
    Status card on a phone. This was taken at the end of the session, after I’d set an all day schedule.

    What I didn’t test: Wi-Fi at all, VLAN mode, a reboot, IPv6 (guests are supposed to get none), a real phone or a real DHCP client, lease expiry, the network-wide caps, the upload caps, a voucher actually being used to join, and anything that ran longer than an hour. I created one voucher through the page (name weekend-visitor, 2880 minutes) and it showed up in the list, and that’s all I know about vouchers. The unit tests I ran pass: 22 in the network crate’s guest module, 2 in the web crate’s guest tests and 6 in the firewall rule tests. There is also a netlab lane for the guest network (the docs count 66 checks), a Wi-Fi lane on simulated radios and a Firefox test of the page. I didn’t run them.

    Where it stands

    It works in the lab: guests get internet and can’t reach anything else. The cap lands a little high. The page needs work, starting with the schedule status.

    Next: a phone joining by QR on real hardware, and a schedule left running for a full day. The status card gets fixed first.

    Patronus lives at patronus.errant.solutions.