Horizontal port scans
A horizontal port scan is one source trying the same destination port on many IPs.
The
network_discoverymodule checks TCP and UDP flows as they arrive.It needs no training and starts checking right away. No port is skipped, 443 included.
Why the old detection had false positives
It counted the “not established” flows of one Slips time window, usually one hour.
That also included what was left of old connections.
After starting Slips or changing wifi, the closing packets and resets of many HTTPS connections looked like new connection attempts.
More packets gave a higher confidence, even when they were only retransmissions or closing packets.
What the new detection does instead:
It reads the packets recorded in Zeek’s
history, with the connection state, number of packets, bytes and duration.It counts each kind of probe separately.
Retries to the same IP count as one target, and more packets don’t raise the confidence.
What counts towards a scan
Different destination IPs are counted per network, source, protocol and destination port.
With the default settings two checks run:
fast: 10 new targets in 60 seconds.
slow: 25 new targets in 30 minutes.
These periods use the start time of the connections and don’t depend on Slips time windows.
A long retransmission timeout alone doesn’t push a burst out of the fast check.
A flow that arrives very late, after newer traffic, may be too old to be counted.
The evidence is stored in the time window of the flow that caused it.
What Slips sees |
What it does |
|---|---|
TCP SYN from the source, handshake never completed |
Counted as a new attempt. Enough targets with scattered attempts that got no answer set a Low evidence, because the network may just be down. |
New SYN attempts, with rejections from at least half of the needed targets, or targets close to each other |
High evidence, if enough of the targets failed. |
Failures on 3 or more destination ports, and no recent successful connection by the source |
Lowers a SYN only evidence to Low, because the network may be down. Rejected attempts are still judged on their own. Only flows received so far are used. |
Completed handshake, no data in either direction, the source closes or resets within 3 seconds |
Checked separately, to catch scans of open services. Needs the number of targets and targets close to each other. Medium evidence. Connections that carry data don’t count. |
Only ACK/FIN in the history, no answer, no data, at most 2 packets from the source, at most 1 second long |
Checked separately. Needs enough failed targets and targets close to each other. Medium evidence, and the description says that missing packets could also explain it. |
UDP with no answer |
Checked separately. Needs enough failed targets and targets close to each other. Medium evidence. Scattered QUIC with no answer is not enough. |
A failed flow with no packet history |
Can set a Low evidence with enough targets and enough failed targets. It can’t show that a new SYN was seen. |
Closing packets, resets or one way data with no new SYN, other than the ACK/FIN case above |
Not counted as a new attempt. |
A flow that Zeek reversed ( |
Slips keeps the source and destination that Zeek ended with, and reads the flags to match. A SYN from that source counts. Without one, the flow is not counted as a SYN probe. |
Enough failed targets
The default is 80% (
horizontal_min_failure_ratio): targets with failed probes divided by all the recent targets of the same source and port.Successful connections lower this share.
Familiar destinations are not counted as new targets, even when reconnecting to them fails.
Each kind of probe is judged separately. TCP and UDP are never added together.
Targets close to each other
At least 80% of the targets are in the same IPv4 /24 or IPv6 /64, and
at least half of the IPs between the lowest and the highest target there were tried.
For example, trying IPs 1 to 10 looks more like a scan than 10 scattered IPs of a /24.
Being in the same CDN subnet is not enough.
Familiar destinations
A destination that the source connected to successfully on that port in the last hour is familiar.
Failed reconnections to it don’t count as new targets until that hour passes.
A successful connection is a TCP handshake followed by normal use, or an answer to UDP.
Data alone can’t tell which TCP side is the client.
A short connection with no data is kept as a possible scan of open services instead.
A retry that works removes the failed attempt to that target.
An older failure that arrives late can’t undo a later success.
This is kept in memory for a limited time. It is not a whitelist.
Flows that don’t come from Zeek
Argus, NetFlow and other inputs have no packet history, so Slips falls back to its own “established / not established” state, with Low confidence.
Some old files only have a total number of packets. The flow is still used, but Slips doesn’t claim to know which side sent them.
These flows can’t give a High confidence SYN evidence.
UDP flows without packet counts per direction use that state too.
Confidence, and scans that keep going
High TCP scan evidence starts at 85%. It goes up with more different destinations, not with more packets or retries:
Confidence |
Needs |
|---|---|
85% |
The number of targets of the check, enough failed targets, and repeated rejections or targets close to each other. |
95% |
Twice the number of targets of the check (at least 20), and 90% failed targets. The conditions for 85% still apply. |
100% |
10 times the number of targets of the check (at least 100), and 95% failed targets. Also needs targets close to each other, or rejections from as many destinations as the number of targets of the check. |
So with the defaults the fast check reaches 100% at 100 targets, and the slow one at 250.
A higher confidence or threat level is reported even during the cooldown.
100% means that all the conditions of a scan were met. It doesn’t prove bad intent or that an attack worked.
Missing packet history, scattered attempts with no answer and the “network may be down” case keep their lower confidence, however many packets there are.
At 100%:
Slips drops the full list of destinations of that source and port, and stops running the full check on it.
It keeps a 1 KB counter of different IPs, at most 20 recent flows, and up to 31 flows that wait to be checked.
New SYN and rejected attempts are checked 32 at a time against Slips P2P connections, then added to the counter.
Successful connections and other kinds of probes are not added to the count of this scan.
Evidence for a scan that keeps going:
is set at around 1,000, 10,000, 100,000 targets and so on.
is not held back by the cooldown, and keeps the 100% confidence.
says that it continues a confirmed scan, with an approximate count and some of its flows.
has a time that covers the whole scan so far.
Retries to the same IP don’t raise the count.
Checking 32 flows at a time can delay it by up to 31 probes.
The counter:
uses HyperLogLog with 1,024 registers.
is usually off by around 3.25%. This is not a guaranteed limit, and it can slightly move the point where the next evidence is set.
is only used after the scan is confirmed, never to decide the first threat level or confidence.
When the scan is over:
After
horizontal_alert_cooldown_secondswithout SYN or rejected attempts, the next flow is checked from zero. A later scan has to meet the conditions again.Each network, interface, source, protocol and destination port is still followed separately.
Other notes:
Only the profile of the source gets the evidence.
An evidence links to at most 20 flows. Its timestamp is the start time of the latest one.
Slips removes its own P2P connections before reporting, then checks the result again.
Only Medium and High evidence mark the source as a scanner for other detections.
An IP is not skipped just because it was resolved by DNS.
Configuration
Put these options under
network_discovery:in the YAML config file given with-c.Restart Slips after changing them.
Config files without this section use the defaults.
Each PCAP run has its own config. The Configuration page of the web interface shows the one saved when that run started.
Parameter |
Default |
What it does |
|---|---|---|
|
|
Seconds covered by the fast check. A short period doesn’t add up unrelated failures. Range: 1–3600. |
|
|
Different new destinations needed by the fast check. A higher number misses smaller scans and gives fewer false alarms. Whole number, 5–4096. |
|
|
Seconds covered by the slow check. Can’t be shorter than the fast one. Range: 1–86400. |
|
|
Different new destinations needed by the slow check. Higher than the fast one so that a failure now and then is not a slow scan. Whole number, 5–4096. |
|
|
Share of the recent targets that must have failed. Not used by the check for scans of open services. Range: 0.5–1. |
|
|
How long a successful connection makes a destination familiar on that port. A higher number can hide scans of recently used targets. Range: 1–86400. |
|
|
Minimum seconds between two evidence of the same network, source, protocol, port and kind of probe. A higher threat level or confidence is still reported. A confirmed scan is over after this many seconds without probes. Range: 1–86400. |
|
|
Minimum seconds between two full checks of the same source and port. Every |
|
|
Maximum network, source, protocol and port combinations followed at the same time. The least recently used one is dropped first. Whole number, 1–4096. |
|
|
Maximum destinations remembered per source and port before the scan is confirmed, familiar ones included. Can’t be lower than the two |
Performance, restarts and limits
Performance:
The detection uses the flow it receives in the
new_flowchannel. It adds no SQLite queries or Redis keys per flow.The old Redis totals per time window are no longer written or read, for horizontal and vertical scans.
Most updates are dictionary lookups. A full check only goes through one source and port.
Failures on other ports are only looked at for a strong SYN only case.
With the defaults at most 65,536 targets are kept (256 × 256). Confirmed scans keep the small counter instead.
All of this runs in the module. Nothing was added to capturing, profiling or passing flows to the modules.
Slips doesn’t write the old vertical port scan keys to Redis anymore, and doesn’t look up the service name of failed and non-TCP flows. The check for connections to several unknown ports works as before.
Memory:
Old records are dropped once newer flows are later than the longer of the slow check and the successful connections history.
With no traffic, what is in memory stays there.
When a limit is reached, the least recently used record is dropped. This can miss a scan, or make an old destination look new.
A large confirmed scan that fills its counter is normal, and is not reported as a reached limit.
Slips prints how many records were dropped at most once a minute.
Networks and restarts:
On an interface, each interface and each network (gateway and subnet) is followed separately.
The gateway is cached for 5 seconds, so a network change can take that long to show.
Flows that arrive late use the saved network history when there is one.
Broadcast, multicast,
0.0.0.0and loopback traffic is skipped.Each PCAP run has its own state.
Nothing is saved to disk. After a restart the counters and the successful connections history are empty. Stored evidence stays.
Limits:
There is no quiet period at startup and no skipped port.
Missing packets, NAT, packet loss, CDN traffic and a real network failure can still look like probing.
A small FIN scan and the closing of a connection that Slips didn’t see look the same in flows. That’s why the ACK/FIN check needs targets close to each other and is only Medium.
These can be missed:
scans that exchange real data with the targets.
ACK/FIN/UDP scans scattered over unrelated networks.
ACK/FIN probes that get answers.
Testing
The unit tests cover:
traffic seen right after startup, retries and successful reconnections.
separate networks and interfaces, late flows and long timeouts.
bursts within a second with mixed kinds of probes.
fast and slow scans across time windows.
scans of open services, IPv6, UDP and P2P exclusions.
confidence growth, evidence for scans that keep going, reset after a quiet period, and memory limits.
Run them from the root of the repo:
python3 -m pytest tests/unit/modules/network_discovery/ \
tests/unit/slips_files/core/database/redis_db/test_scan_detections_db.py \
tests/unit/slips_files/common/test_config_parser.py
Results of some runs. They don’t give a general false positive rate:
CTU-Normal-38 and CTU-Normal-39 (186,827 flows) on an Apple M1: no horizontal scan evidence, around 4 CPU seconds with log parsing.
65,536 targets in memory took around 35.5 MiB of Python allocations.
15,274 saved flows of
output/pcap-case-16:the TCP/445 scan reached 100% at 100 targets in timestamp order (250 in the order of the log).
evidence was set again at around 1,000 and 10,000 targets.
no records were dropped. The old detection dropped 13,968 in the same run.
Closing packets at startup don’t set evidence anymore. Bursts of SYNs with no answer can still set Low evidence.
A Zeek log made for testing gave the expected SYN, empty connection, ACK and UDP evidence, and none for what was left of old connections.
An old Argus scan is checked using the state fallback.
Notes:
A running module keeps the code and settings it started with. Run the analysis again to get evidence from the new detection.
Opening old results with
--viewdoesn’t compute evidence again or change old confidence values.
Vertical port scans and other scans
A vertical port scan is one source trying many ports on the same destination.
Slips keeps the failed ports per source, destination, protocol, kind of probe and network. Only the profile of the source gets the evidence.
A port that later works is not counted anymore.
The default period is one hour, to also catch slow scans.
Confidence:
SYN attempts start at 85%, UDP with no answer at 65%.
both can reach 95% at 20 ports and 100% at 100 ports.
missing history and ACK/FIN only traffic keep their lower confidence.
Completed connections with no data are not part of this check.
Nothing is saved to disk, and each interface and network is followed separately.
Slips P2P connections are cached for 5 seconds, at most 4,096 of them.
At 100%:
The list of ports is replaced by a 1 KB counter.
New evidence is set each time the count grows 10 times, with an approximate count and at most 20 flow IDs.
The scan is over after the cooldown without probes.
Memory:
A source and destination pair is only followed after a second different port.
Before that, contacts on one port are kept in a separate list of at most
4 × vertical_max_source_destination_pairsentries.That list can forget an old probe, but a large horizontal scan can’t push out the vertical scans being followed.
Slips warns when pairs being followed are dropped because of the limit.
Parameter |
Default |
What it does |
|---|---|---|
|
|
Seconds of failed ports that Slips looks at together. An hour also catches slow scans. Range: 1–86400. |
|
|
Different failed ports needed for a scan. Retries count once. A higher number misses smaller scans. Whole number, 5–4096. |
|
|
Minimum seconds between two evidence of the same scan. A higher confidence is still reported. A confirmed scan is over after this many seconds without probes. Range: 1–86400. |
|
|
Maximum source and destination pairs followed at the same time. The list of single port contacts holds 4 times this number. Whole number, 1–4096. |
|
|
Maximum failed ports remembered per pair before the scan is confirmed. Can’t be lower than |
|
|
Maximum DHCP clients, and separately ICMP scanners, followed at the same time. Whole number, 1–4096. |
|
|
Seconds without activity after which a DHCP or ICMP scan is over. DHCP is also followed per client MAC, interface and Slips time window. Range: 1–86400. |
|
|
Different IPs one DHCP client has to request before it’s reported. The confidence reaches 95% at twice this number (at least 20) and 100% at 10 times (at least 100). Whole number, 2–100. |
Horizontal scans with empty connections, and UDP scans with targets close to each other, grow in confidence and keep going the same way. They stay Medium.
Probes that Slips is not sure about keep their lower confidence.
See scan confidence and scans that keep going for the shared rules, the counter, ICMP notices and how the modules work together.