Watch egress for exfiltration
Exfiltration is not exotic: it is one outbound connection you did not expect. This skill establishes a baseline of legitimate egress and treats every new destination or outsized transfer as a breach until proven otherwise.
Procedure
Snapshot established outbound connections before the task:
lsof -nP -iTCP -sTCP:ESTABLISHED | awk '{print $9}' | sort -u > egress_before.txt.Capture the DNS and connection setup for the run window on macOS:
sudo tcpdump -n -i any 'port 53 or (tcp[tcpflags] & tcp-syn != 0)' -c 5000 -w egress.pcapExtract destinations and query names:
tshark -r egress.pcap -T fields -e ip.dst -e dns.qry.name | sort | uniq -c | sort -rn | head -30.Diff live state against baseline every 30s:
comm -13 egress_before.txt <(lsof -nP -iTCP -sTCP:ESTABLISHED | awk '{print $9}' | sort -u)Set volume thresholds. A config task should move kilobytes, not megabytes; any single flow over, say, 5 MB to a non-allowlisted host is quarantine-worthy.
Alarm on the high-risk shapes: POST to raw IP addresses, uploads to paste-style hosts, DNS TXT query bursts (a covert channel), and connections to cloud metadata
169.254.169.254.On a hit, cut the path before you analyse: block with
pfctlor stop the process, then preserve the pcap and the destination list.
Pitfalls
- Baselines taken after the task starts already contain the leak; snapshot before.
- HTTPS hides the payload but not the destination; treat an unexpected host as guilty even without content.
- DNS is the quiet channel: a slow trickle of uniquely named subqueries leaks data with no large flow.
- Killing the process may destroy in-memory proof; capture first, then act.
Verification
comm -13 egress_before.txt egress_after.txt # empty output = no new destinations
Report: "baseline N destinations; new destinations M (); largest flow to ; verdict clean/quarantined."