-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Nmap on Windows with -sT shows 'filtered' instead of 'closed' #2113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Important updates:
I believe this is related to how Windows handles non-blocking socket connect; something is going wrong between the |
Ok, this is really weird. When debugging, the outcome depends on where I place the breakpoints relative to the select() call.
I verified and the FD set correctly contains the appropriate FD number in both cases. The timeout is a reasonable value (usually 0 seconds 999000 usecs, regardless of breakpoint placement). |
Adding a |
The timeout is too short. Apparently WinSock is delaying the error notification for RST by up to 1.5 seconds. We'll have to add an artificial delay to compensate. We should turn this delay off if user chooses --defeat-rst-ratelimit. |
It's delaying because it's doing 3 retransmissions before giving up. This can be controlled with the |
Unfortunately, setting |
Update: As of 9/23/24, me and @dmiller-nmap can still reproduce this with Nmap 7.95. The issue is just that Windows takes so long to notify us about the RST. If we use --min-rtt-timeout it does work, but the scan is then super slow. We have ideas for potentially fixing this, though it is a bit of an edge case. Npcap is so good now that it's a lot rarer that people need to resort to -sT. And the ones who need more subtle details like whether a port is closed or filtered are probably more likely to scan from a system that can use raw sockets. So we're keeping this open, but for now it might just be considered another unfortunate limitation of using -sT on Windows. |
When I was looking into this last time, I asked on StackOverflow: Windows sockets: How to immediately detect TCP RST on nonblocking connect()?. No answer as yet, but a useful comment:
|
Recent research has yielded all the necessary parts to fix this issue, so I'm dumping them here for later. There are 4 parameters to consider:
So we need to set a timeout such that if a RST comes in response to the last SYN sent (the worst case), the connection will not timeout. The sum of the timeouts for Other observations:
(Edited to correct: SIO_TCP_INITIAL_RTO actually interprets the |
For comparison, Linux kernel docs for
I was incorrect in saying Nmap doesn't enforce a timeout for connect scan. It closes the socket after the probe timeout, which is 1 second by default. In other words, Nmap is ensuring and expecting only 1 SYN is sent per connect() call, which makes our job of choosing parameters easier: for a given probe timeout, we can round up to the nearest whole second and then set SIO_TCP_INITIAL_RTO with |
Describe the bug
Nmap on Windows with
-sT
does not show closed ports, even though Wireshark shows RST packets in the loopback traffic capture.To Reproduce
nmap -sT localhost -F
Expected behavior
Closed ports will show "closed" not "filtered"
Version info (please complete the following information):
OS: Windows 10
Additional context
Also affects Nmap 7.60. Have not checked older versions or other versions of Windows.
The text was updated successfully, but these errors were encountered: