netstat & ss
π§ Tool Note β Category: Host Network Inspection (built-in CLI) | Free / OS-native
π Quick Overview
What are they? Command-line tools that show the network connections and listening ports of the local machine β every socket the OS currently has open. netstat is the classic (cross-platform) tool; ss (βsocket statisticsβ) is its faster modern Linux replacement.
On Windows: netstat
On Linux: ss (preferred) or netstat (from net-tools, often deprecated)
Used in: CSF & NS (Practical 6 β spotting a compromised host beaconing out)
Related concept: Network Traffic Analysis
π― What Problem Does It Solve?
- Answer βwhat is my machine talking to right now?β and βwhat ports am I listening on?β
- Spot a suspicious outbound connection (malware C2 / beaconing) from the host itself
- Find unexpected listeners (a backdoor shell waiting for connections)
- Map a connection back to the process that owns it
Where Wireshark shows traffic on the wire, netstat/ss shows sockets from the OSβs point of view β including which process owns each one, which Wireshark canβt tell you.
βοΈ How It Works
The OS kernel keeps a table of every active socket (local IP:port β remote IP:port + state + owning process). These tools read that table β they do not send packets:
netstat(Linux) reads pseudo-files under/proc/net/(tcp,udp,tcp6β¦) and, with-p, walks/proc/<pid>/fd/to map a socket to its process. Parsing all of/procis slow on busy hosts.ssasks the kernel directly over a netlink socket (NETLINK_SOCK_DIAG) β no/proctext parsing β so itβs much faster and can filter kernel-side.
Because they read live kernel state, the output is a point-in-time snapshot of connections; run repeatedly (or watch) to see beaconing patterns.
TCP connection states youβll see
| State | Meaning |
|---|---|
LISTEN | Port open, waiting for inbound connections (a server/backdoor) |
ESTABLISHED | Active, connected session |
SYN_SENT | This host is trying to connect out (handshake started) |
TIME_WAIT | Connection closed, cleaning up |
CLOSE_WAIT | Remote closed; local app hasnβt yet |
An unexpected LISTEN on a high port, or repeated SYN_SENT/ESTABLISHED to one odd external IP:port, are classic red flags.
π¬ Key Commands
# ββ Linux (ss) ββ
ss -tulpn # TCP+UDP, Listening, show Process, Numeric (no DNS) β the go-to
ss -tan # all TCP sockets, numeric
ss -tp state established # established TCP with owning process
ss dst 203.0.113.10 # connections to a specific IP
# ββ Linux (netstat, legacy) ββ
netstat -tulpn # same idea as ss -tulpn
netstat -antp
# ββ Windows ββ
netstat -ano # all + numeric + owning PID
netstat -anob # also show the executable (needs admin)
# then map PID β process:
tasklist /fi "PID eq 1234"Flag mnemonic: t=TCP, u=UDP, l=listening, p=process, n=numeric, a=all.
π¬ Typical Workflow (Practical 6 β C2 beaconing)
ss -tunp(ornetstat -anoon Windows) β list active connections.- Spot a repeating outbound connection to a non-standard port at regular intervals β possible C2 beacon.
- Note the owning process/PID β is it something that should be talking to the Internet?
- Take the remote IP/hash to VirusTotal for reputation.
- Correlate with Wireshark to see the payload/timing, and log the incident.
β οΈ Gotchas / Limitations
- Snapshot only β short-lived connections between runs are missed; sample repeatedly.
- Seeing the owning process usually needs admin/root (
-p/-b). - Shows that a connection exists, not whatβs inside it β pair with Wireshark for payload.
netstaton Linux is deprecated; preferss. Malware on a rooted host can also hide from these tools (rootkits) β corroborate with network-side capture.
π Related Notes
- Network Traffic Analysis β host-side vs wire-side visibility
- Wireshark β packet-level view of the same connections
- VirusTotal β reputation-check the remote IPs you find
- SOC Operations & Incident Lifecycle β C2 beaconing detection & triage