Windows network forensics from memory: netscan, netstat, DNS cache
7 min read
When an incident starts with "this host talked to something it shouldn't have", the firewall logs may be gone or never existed. Memory still holds the kernel's socket objects, the resolver cache and often the hosts file. This post covers the network plugins ramparser runs on Windows images, what each one reads, and how to interpret the output. The technique names follow The Art of Memory Forensics, chapter 11, and the Volatility plugins it describes.
netscan: pool scanning for endpoints
On Vista and later, tcpip.sys allocates each TCP connection as a
_TCP_ENDPOINT (pool tag TcpE), each listener as a _TCP_LISTENER
(TcpL) and each UDP socket as a _UDP_ENDPOINT (UdpA). netscan
sweeps physical memory for those three tags and parses the object
behind each hit.
Because the scan ignores the kernel's own tables, it finds endpoints that are live and endpoints that are freed but not yet reused. A connection opened by a process that has since exited can still be there. That is often exactly what the case needs.
Field offsets inside these structures move between Windows builds.
When the tcpip.sys PDB is available, ramparser takes the
_TCP_LISTENER and _UDP_ENDPOINT layouts from it; otherwise it falls
back to a built-in Windows 10 baseline. Pool bytes are noisy, so each
candidate is validated:
- a
TcpEwhoseStateis outside the valid TCP states is dropped (the same check as Volatility 3'sis_valid); - a
TcpEwith no owning process is dropped, since every test dump showed those to be stale bytes; - the address family is read through
InetAF, so IPv4 and IPv6 rows are labelled correctly.
Each row carries the owner PID and process name, local and remote
address and port, state, and, on builds where the offset is known, the
endpoint's CreateTime. Times outside 2000 to capture time are
discarded rather than shown. netscan also runs when the kernel PDB
cannot be fetched, as one of the no-symbols fallback plugins.
netstat: the live partition table
netstat answers a different question: which TCP connections does
the kernel consider active right now? It starts from the
tcpip!PartitionTable global, found through the tcpip.sys PDB, and
walks the hash-bucket lists behind it. The public PDB has no type
information for those tables, so the walk is shape-driven: it looks
for arrays of LIST_ENTRY buckets, follows them, and only keeps nodes
that parse as real TcpE objects with an owner.
No tcpip.sys PDB means no netstat. In that case ramparser still
runs netscan.
Live versus closed
The network view merges both sources on the 5-tuple plus owner. When
netstat produced rows, any pool-scanned TCP connection it does not
hold is marked closed: the object exists only in freed memory.
Listeners and UDP sockets are not in the partition table, so they are
never marked this way.
A closed connection to an Internet address, owned by a process that
pslist no longer shows, is a typical short-lived dropper or beacon.
The reverse matters too. A connection in netstat that netscan
missed usually means the pool page was not captured, not that
something is hiding.
Windows XP and 2003: connscan and sockscan
Before Vista, tcpip.sys used different objects. connscan
pool-scans for _TCPT_OBJECT (tag TCPT, one per connection) and
sockscan for _ADDRESS_OBJECT (tag TCPA, one per socket, with
protocol, local address, owner PID and creation time). Layouts are
built in for XP SP2/SP3 x86, as in Volatility 2.
ramparser applies light sanity checks (non-zero ports, plausible PID,
non-empty peer) but has no live-table walk for XP, so open and closed
objects cannot be told apart. A sockscan row with protocol 0 or 255
is a raw socket.
DNS resolver cache
The DNS Client service keeps recent lookups, the data behind
ipconfig /displaydns, on the heap of the svchost.exe that hosts
Dnscache. The book suggests carving hostnames with a regex.
ramparser's dnscache does something stricter: it finds the right
svchost from command lines, walks its private, non-file-backed VADs,
and looks for DNS_RECORDW structures whose fields validate (Unicode
charset flag, sane TTL, a user-mode pointer to a well-formed hostname,
a data length that matches the record type).
It recovers A, AAAA, CNAME, PTR and NS records with their TTL. The parser uses the x64 record layout. C2 domains often survive here after the connection object itself is gone.
The network view uses this cache to put names on remote IPs. It follows CNAME chains back to the name the program asked for, so a CDN edge address shows up as the domain that was actually looked up.
Hosts file tampering
The resolver checks \Windows\System32\drivers\etc\hosts before it
asks any DNS server. Malware edits it to blackhole security vendors
and update servers, or to redirect a banking domain to its own server.
hostsfile finds the file in the cache manager, as a filescan plus
dumpfiles would, and parses its active lines. Pages that are not in
memory come back zero-filled and are treated as line breaks.
A stock Windows hosts file contains only comments, so every entry is worth a look. ramparser labels each entry by its target:
| Target | Meaning | Finding |
|---|---|---|
127.0.0.1, ::1 | name blocked (loopback) | medium |
0.0.0.0 | name blocked (unspecified) | medium |
| any other address | name redirected to another machine | high |
False positives: ad blockers and some privacy tools write large block lists. Many blocked names on a developer or admin workstation is not proof of compromise. A redirect of a single banking or login domain is.
Raw sockets and sniffers
A process that calls socket(AF_INET, SOCK_RAW, ...), to forge
packets or to sniff traffic with SIO_RCVALL, holds a File handle on
\Device\RawIp (or \Device\RawIp6). rawsockets walks every
process handle table and reports each such handle with its granted
access. Raw sockets need administrator rights, and almost nothing
legitimate uses them (ping goes through the ICMP API instead). Each
hit is raised as a high-severity finding. Network monitoring tools
and some security agents are the expected exceptions.
ethscan: packets still in memory
Network drivers and the kernel stage the frames they send and receive
in buffers that linger after use. ethscan sweeps physical memory for
Ethernet frames carrying IPv4 or IPv6, independently of any socket
table. Random bytes rarely pass its tests: the source MAC must be
unicast and non-zero, an IPv4 header must have a valid checksum, and an
IPv6 header, which has none, needs TCP, UDP or ICMPv6 as next header, a
sane length and non-zero addresses. Each frame gives the protocol,
endpoints, TCP flags, the DNS question on ports 53 and 5353, and a
payload preview.
The "Packets in memory" panel under the network view folds frames into conversations, remote peers first, and lists the names looked up. It can show peers of connections whose objects are long gone, and cleartext such as HTTP requests. Nothing in the scan is Windows specific, so it also runs on Linux and macOS images: on demand when kernel symbols are loaded, automatically on XP and without symbols.
The network view
The raw tables stay available, but the network view answers the triage questions first:
- Who talks to whom: a map from processes to remote hosts, grouped into Internet, local network and this machine.
- What the machine exposes: listening ports folded per port and program, reachable-from-the-network first. An entry is flagged when its owner is already suspect, when the program runs from a temp or user folder, when a shell or script interpreter is listening, or when the port is one backdoors commonly use (4444, 1337, 31337). Short-lived UDP ports (49152 and up) are counted, not listed.
- Remote hosts: every peer, flagged talkers and public addresses first, with DNS names and a live or closed marker.
- When connections were opened: one row per process with a dot
per connection, placed by
CreateTimebetween boot and capture.
Practical workflow
- Start with the network view. Read the exposure list and the Internet peers before anything else.
- Look for closed connections whose owner is missing from
pslist. Pivot topsscanfor that PID. - Put names on the IPs using the DNS cache, then check the hosts file for redirects of those names.
- Treat any raw-socket holder as suspect until you can name the product.
- For a suspicious owner, pivot to
cmdline,dlllistandmalfind. A process that talks to the Internet and also holds injected code is a real finding.