Nmap, the ubiquitous network scanner, often flags ports as open that are, in reality, closed or filtered, leading to a frustrating amount of noise in your scan results.
Let’s watch Nmap in action, and then break down why these "false positives" happen and how to silence them.
Imagine you’re scanning a subnet 192.168.1.0/24 for open SSH ports (port 22). You run a basic scan:
nmap -p 22 192.168.1.0/24
You might see output like this for a host that doesn’t actually have SSH running:
Host: 192.168.1.100 (router.local)
PORT STATE SERVICE
22/tcp filtered ssh
Or even:
Host: 192.168.1.105 (server.local)
PORT STATE SERVICE
22/tcp open ssh
But when you try to connect to 192.168.1.105:22, nothing happens, or you get a connection refused. That’s the "false positive" – Nmap thinks it’s open, but it’s not.
The core of the problem lies in how Nmap determines port states. It relies on sending probes and analyzing the responses (or lack thereof) from the target. Different scan types use different probes and interpretations, and network intermediaries (firewalls, routers) can interfere, leading to ambiguity.
TCP SYN Scan (-sS) - The Default for Root
This is Nmap’s default scan when run with root privileges. It sends a TCP SYN packet to the target port.
-
Response:
SYN/ACK: Port is open. Nmap sends an RST to tear down the connection.RST/ACK: Port is closed.- No response: Port is filtered.
-
Common False Positive Cause: A firewall or Intrusion Detection System (IDS) intercepts the
SYN/ACKresponse and sends back a different packet, often an ICMP "destination unreachable" message, or simply drops the packet. Nmap, not receiving the expectedRSTto its initialSYN, might interpret this silence or unexpected reply as a sign the port is open and then filtered by the firewall.- Diagnosis: Look for ICMP error messages in the scan output or use
tcpdumpon the scanning machine to see what responses are actually arriving. - Fix: Switch to a scan type that is less likely to be blocked or misinterpreted. The TCP ACK scan (
-sA) can sometimes help differentiate between open and filtered ports because it’s often allowed through firewalls to map their rulesets.
This scan sends an ACK packet. If it receives an RST, the port is likely closed. If it receives no response or an ICMP error, it’s likely filtered. The key is thatnmap -sA -p 22 192.168.1.0/24-sAdoesn’t try to establish a connection, making it more stealthy and less prone to triggering some filtering devices into sending misleading responses. - Why it works: The ACK scan probes the firewall’s state table directly. A firewall that allows
ACKpackets through to mapped ports will send anRSTback if the port is closed. If the port is open, the firewall will likely drop theACKor send an ICMP error, but the lack of anRSTfrom the target itself can be interpreted differently.
- Diagnosis: Look for ICMP error messages in the scan output or use
UDP Scan (-sU) - The Ambiguity King
UDP is connectionless, making state detection inherently trickier. Nmap sends a UDP packet to the target port.
-
Response:
- UDP response: Port is open.
- ICMP "port unreachable" error: Port is closed.
- No response: Port is open or filtered. This is the big problem.
-
Common False Positive Cause: A firewall or router drops the UDP probe packet or drops the ICMP "port unreachable" response. Nmap, not getting a definitive "closed" (ICMP unreachable) or "open" (UDP response) signal, defaults to "open|filtered". However, sometimes, systems might send a different ICMP error or a malformed packet that Nmap misinterprets as a sign of an open port when it’s actually filtered or closed.
- Diagnosis: Use
nmap -sU --reason -p 53 192.168.1.50to see Nmap’s reasoning. Look forno-responseorport-unreachable. If you seeno-responsefor a port you know is closed, it’s a false positive. - Fix: Use the
--version-all(-sV) option with UDP scans. Nmap will send more specific UDP probes based on service version detection. If a service is actually running, it’s more likely to respond correctly. If not, the lack of a specific service response is a better indicator than just a generic UDP probe.nmap -sU -sV -p 53 192.168.1.0/24 - Why it works: Service version detection sends application-specific probes. A real DNS server (UDP/53) will respond to a DNS query in a predictable way. A closed port won’t. A firewall blocking UDP/53 might drop the probe, leading to
open|filtered, or it might pass the probe but block the response, also leading toopen|filtered. However, if Nmap doesn’t get a DNS response, and it isn’t an ICMP unreachable, it’s stillopen|filtered. The false positive here is when Nmap claims it’sopenwhen it’s not. This happens less with-sVbecause the probes are more specific.
- Diagnosis: Use
TCP ACK Scan (-sA) and Firewall Rule Sets
While -sA is often used to diagnose filtering, it can also produce false positives.
-
Response:
RST: Port is closed.- No response or ICMP error: Port is filtered.
-
Common False Positive Cause: A firewall might be configured to block
ACKpackets to certain ports but allow them to others. Nmap might interpret the lack of anRSTas "filtered" when it’s actually "closed" and the firewall is just doing its job of dropping unsolicitedACKs.- Diagnosis: Compare results from
-sAwith-sSor-sT(TCP Connect Scan). If-sAshowsfilteredand-sSshowsopenfor the same port, it’s a strong indicator of firewall manipulation. - Fix: Use a more aggressive scan type like TCP Connect Scan (
-sT) if-sSis unreliable due to filtering. The TCP Connect scan is the slowest but most reliable as it completes the full TCP handshake, which is harder for firewalls to interfere with without outright blocking the entire connection attempt.nmap -sT -p 80 192.168.1.0/24 - Why it works: The TCP Connect scan (
-sT) uses the operating system’sconnect()system call. This means it performs the full three-way handshake. If a firewall allows the connection to complete, the port is genuinely open. If the firewall blocks any part of the handshake,connect()will fail, and Nmap will reportclosedorfilteredaccurately based on the OS’s error.
- Diagnosis: Compare results from
FIN, NULL, and Xmas Scans (-sF, -sN, -sX)
These scans are designed to be stealthy by sending malformed TCP packets.
-
Response:
RST: Port is closed.- No response: Port is open or filtered. (This is the ambiguity).
-
Common False Positive Cause: Microsoft Windows systems do not follow RFC 793 for TCP behavior. They often send an
RSTpacket in response to FIN, NULL, and Xmas scans regardless of whether the port is open or closed. Nmap, seeing anRST, correctly interprets it as closed, but if a Windows machine is supposed to have a service open on that port and doesn’t respond correctly, Nmap might mark it as closed when it might be intermittently accessible or just misbehaving. More commonly, these scans can be misinterpreted by firewalls themselves.- Diagnosis: Run these scans against known open and closed ports on a Windows machine. Observe the inconsistent
RSTresponses. - Fix: Avoid using
-sF,-sN, or-sXagainst Windows targets. Stick to-sSor-sT. If you suspect firewall interference with these stealth scans, try increasing the timing (-T4or-T5) to send packets faster, hoping to overwhelm a stateful inspection rule, or use-sAto map the firewall.nmap -sS -T5 -p 135 192.168.1.0/24 - Why it works: The
-T5flag increases the scan speed, sending packets more rapidly. This can sometimes bypass the detection mechanisms of certain firewalls or IDS that track packet states over time. If the port is genuinely open, a faster scan might get the "open" response before a firewall can block it or send a misleadingRST.
- Diagnosis: Run these scans against known open and closed ports on a Windows machine. Observe the inconsistent
Network Latency and Packet Loss
Even with perfect configurations, high latency or packet loss on the network can cause Nmap to miss responses.
-
Common False Positive Cause: A packet is dropped in transit. Nmap sends a probe, but it never arrives at the target, or the response never arrives back. Nmap interprets this lack of response as the port being filtered or sometimes open (especially in UDP scans).
- Diagnosis: Use
pingormtrto check for packet loss to the target IP. Examine Nmap’s--packet-traceoutput for dropped packets. - Fix: Increase the retransmission timeout. Use the
-Toption to adjust timing.-T4(Aggressive) or-T5(Insane) speed up scans, which can sometimes help if the network is just slow, but-T3(Normal) is usually a good balance. For high-loss networks, use--max-retriesto tell Nmap how many times to retransmit a probe before giving up.nmap -sS --max-retries 5 -p 80 192.168.1.0/24 - Why it works: By increasing the number of retries (
--max-retries 5), Nmap will send the probe up to five additional times if it doesn’t receive a response. This significantly increases the chance that a probe will reach the target and its response will get back through on a lossy network.
- Diagnosis: Use
The "Open|Filtered" State Itself
Sometimes Nmap doesn’t actually give a false positive, but an ambiguous state that looks like a false positive because you expect a definitive "open" or "closed."
-
Common Cause: This state is most common with UDP scans and stealthier TCP scans (
-sS,-sF,-sN,-sX). It means Nmap couldn’t definitively say if the port is open or if a firewall is blocking its probes.- Diagnosis: Look for
open|filteredin the output. - Fix: Use a more definitive scan type like TCP Connect (
-sT) or a UDP scan with service version detection (-sU -sV). You might also need to try different probe types or increase scan intensity.nmap -sT -p 161 192.168.1.10 --reason - Why it works:
-sTattempts a full TCP connection, which is less likely to be ambiguously filtered than a stealth scan.--reasonhelps explain why Nmap arrived at its conclusion, which is crucial for decipheringopen|filtered.
- Diagnosis: Look for
After fixing all these, your next problem will likely be dealing with rate limiting imposed by network devices, causing your scan to be even slower or blocked entirely.