Safe Penetration Testing Labs · intermediate · ~15 min
Recognise scan flag signatures and count per-source port fan-out.
Two angles: classify TCP flag signatures (SYN/NULL/FIN/XMAS) and count distinct-port fan-out per source IP.
Combining packet-level and behavioural signals is how real scan detectors avoid both false negatives and false positives.
Port scans leave two kinds of evidence: packet-level (unusual TCP flag combinations) and behavioural (one source touching many ports fast). A detector reads both.
| Scan | Flags | Hex |
|---|---|---|
| SYN | SYN | 0x02 |
| NULL | (none) | 0x00 |
| FIN | FIN | 0x01 |
| XMAS | FIN+PSH+URG | 0x29 |
Normal traffic always has ACK set (e.g. a SYN-ACK is 0x12), so it never
matches a scan signature.
Tally distinct destination ports per source IP. A source over a threshold (say, >10 ports in a short window) is almost certainly scanning. Repeated hits to the same port don't count — it's the spread that matters.
tcp_scan_type(...) — classify a single header's flag byte.count_scanners(...) — count source IPs whose distinct-port fan-out exceeds
a threshold, from a static connection log.Mask the flags byte to spot scan types; tally distinct ports per IP to spot fan-out.