Learn › Part 2 ยท Network attacks and defence
Security tools: tcpdump, httprobe, nmap and Snort 3
Packet capture with BPF filters and TCP flag masks, web-service discovery, nmap scan types and port states, and Snort 3 IDS/IPS rules and modes.
tcpdump
Pipeline: interface → capture → libpcap → in-kernel BPF filter → tcpdump decoding → screen or .pcap. It needs root and uses promiscuous mode unless -p is given.
| Option | Effect |
|---|---|
-i eth0 | any | Interface |
-n / -nn | No host-name / no host- or port-name resolution |
-c N | Stop after N packets |
-A / -X | Payload as ASCII / hex + ASCII |
-v…-vvv | More header detail |
-s 0 | Full packets |
-w f.pcap / -r f.pcap | Write / read a capture |
-S | Absolute instead of relative sequence numbers |
sudo tcpdump -i eth0 -nn 'udp port 53' # DNS
sudo tcpdump -i any -nn host 192.0.2.10 -s 0 -w cap.pcap # one host to file
sudo tcpdump 'src net 192.0.2.0/24 and not port 22' # subnet, no SSH
sudo tcpdump 'tcp[13] & 0x12 == 0x02' # initial SYNs only
sudo tcpdump 'tcp[tcpflags] & tcp-rst != 0' # any RST
TCP flags byte tcp[13]: FIN 0x01, SYN 0x02, RST 0x04, PSH 0x08, ACK 0x10, URG 0x20. SYN-ACK = 0x12, PSH-ACK = 0x18, FIN-ACK = 0x11.
Note: tcp[tcpflags] & tcp-syn != 0 also matches SYN-ACK, so it overcounts connection attempts.
httprobe
Reads hosts on standard input and prints the http:// and https:// URLs that answer. -p http:8080 adds ports, -s skips the defaults 80/443, --prefer-https skips HTTP when HTTPS works, -c sets concurrency, -t the timeout in ms. It does not crawl or test for vulnerabilities.
cat subdomains.txt | httprobe -p http:8080 -p https:8443 --prefer-https | tee live.txt
nmap
| Scan | How | Notes |
|---|---|---|
-sn | Host discovery only | -Pn skips discovery |
-sS | SYN, read reply, send RST | Default with root; half-open |
-sT | Full connect() | Used without root |
-sU | UDP probes | Slow; many open|filtered results |
-sA | ACK probes | Maps filtering, not open/closed |
-sV, -O, -sC, -A | Versions, OS, default scripts, all of these + traceroute | -T0…-T5 timing; -oN/-oX/-oG/-oA output |
Port states: open (SYN-ACK), closed (RST), filtered (no reply or ICMP unreachable), unfiltered (ACK scan got RST), open|filtered (no reply in UDP/FIN/NULL/Xmas scans), closed|filtered (idle scan only). Port selection: -p 22,80, -p 1-1024, -p- (all), -F (top 100).
Snort 3
A passive IDS on a SPAN port alerts without touching traffic; an inline IPS can drop packets but risks false positives. Snort 3 is multi-threaded and configured in Lua (snort.lua). Pipeline: DAQ → decoder → inspectors → detection → output.
alert icmp any any -> any any (msg:"ICMP echo request"; itype:8; sid:1000001; rev:1;)
# action proto src sport -> dst dport (options)
# actions: alert, log, pass; inline only: drop, block, reject
# local rules use sid >= 1000000
sudo snort -c /etc/snort/snort.lua -T # test config
sudo snort -c /etc/snort/snort.lua -R local.rules -i eth0 -A alert_fast # passive IDS
sudo snort -c /etc/snort/snort.lua -R local.rules -r cap.pcap -A alert_fast # offline
sudo snort -c /etc/snort/snort.lua --daq afpacket -i eth0:eth1 -Q # inline IPS
There is no --mode inline option in Snort 3; inline mode is -Q with an interface pair.
Common pitfalls
- ICMP type 8 is Echo Request; type 0 is Echo Reply.
- ACK scans cannot tell open from closed.
- Display filters in Wireshark are not BPF capture filters.