Repository navigation
Description
This is a persistent issue that I've run into for years, so I can't believe I'm the first person to report it, but I don't see an existing issue for it.
When I run nmap against a single host, it always completes. If I give nmap a set of multiple hosts to scan (using a network/mask, or a list of specific targets with -iL), there is a decent chance it will slow down dramatically and then effectively hang at about 99% completion. This has happened to me numerous times using the Linux and Mac OS builds. If there were a way to force it to output any results it's obtained to that point, it would be less of an issue, but I'm unaware of a way to do that.
My workaround has always been to only run nmap against a single IP, with it run in a while read loop against a list of targets if I have more than one to scan, but I feel like this problem should be addressed in the tool itself.
I have a full process memory dump from the Mac OS version of nmap 7.70 that I can submit privately if it's helpful, but this is something I've observed with literally every version of nmap I've used since I got into security work about 7 years ago. The scan in question was against a list of 87 IP addresses, using the -iL option:
nmap -sV -p1-65535 -Pn -n --open --script=nfs --script=smb-enum* --script=smb-os* --script=smb-ls* --script=smb-server* --script=smb-system* -oA nmap-local_subnets-2018-11-08-01-all_ports -iL hosts-2018-11-08-02.txt
It ran as expected for about an hour, and produced results for four of the hosts. Then it started slowing down dramatically in terms of the estimated time to completion, without producing any additional results.
In order to eliminate the possibility that it was due to a weird host in the list (e.g. newer versions of Windows responding slowly and causing full-port scans to take much longer), I literally disabled all network interfaces on the system just after 20:52 last night. At that time, it was reporting 98.70% complete. At 10:32 this morning (so almost 14 hours later), it had progressed only to 99.09%.
I'm happy to provide any additional information that I can to eliminate this persistent, long-running bug in one of the most useful pen testing tools.
Activity
blincoln-dd commentedon Nov 9, 2018
I'm rerunning essentially the same scan using the following syntax:
while read host; do nmap -sV -p1-65535 -Pn -n --open --script=nfs --script=smb-enum* --script=smb-os* --script=smb-ls* --script=smb-server* --script=smb-system* -oA nmap-$host $host; done<../hosts-2018-11-09-01.txt
There are only 71 hosts in the list today (vs. 87 yesterday), but they're completing in 120-300 seconds each so far. With the worst-case numbers (5 minutes per scan), the original scan should have completed in 8 hours tops, most likely less.
blincoln-dd commentedon Nov 9, 2018
Finished in < 5 hours when run that way.
dmiller-nmap commentedon Nov 13, 2018
Thanks for bringing this up! The description of the problem leaves a lot of possibilities open as to the cause, so please help us out by providing some more information:
--stats-every 30sto your scan options; the statistics line will mention what Nmap is doing and how far it has gotten through that task.-Pnto skip host discovery? Nmap uses this scan phase to initialize some host timeout information, and if any target address is not actually responsive, scanning 65K ports is going to waste a lot of effort. Does the scan finish more quickly if you remove it or use a custom host discovery like-PE -PS80,111,2049,445,137-139?Until we get to the bottom of this, you can try some workarounds:
--script-timeoutto set a limit on how long Nmap lets each NSE script run against a target. Scripts that timeout will not produce output, but all other target info will be preserved. If diagnostic step 1 above shows that NSE is not the problem, this won't help, but it's handy.--host-timeoutto set an upper limit on how long you want Nmap to spend scanning a particular target. All results for that target will be lost if the timeout is reached, but you will at least get all results for your other targets and can re-scan the troublesome ones individually.blincoln-dd commentedon Nov 15, 2018
Thank you. I'll give that a try and add an update later about how it changes the results.
I'm using -Pn because in my experience, response to ICMP traffic is not a reliable indication of whether or not a host has services listening (especially for scanning outside of the local subnet, and especially if the traffic is traversing the Internet or going into a restricted network). Obviously if something is pingable, it's worth looking at, but I don't want to not look at something just because I can't ping it. Scanning all ports will definitely take awhile if there really is no IP address there, but spending an extra 5-10 minutes scanning each IP is worth it (IMO) in order to find more systems.
Without the additional flags, this is the output leading up to my ctrl-C'ing out of the process:
SYN Stealth Scan Timing: About 98.55% done; ETC: 15:22 (0:03:02 remaining)
Stats: 3:36:11 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.56% done; ETC: 15:25 (0:03:04 remaining)
Stats: 3:45:25 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.56% done; ETC: 15:34 (0:03:12 remaining)
Stats: 4:13:57 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.57% done; ETC: 16:03 (0:03:35 remaining)
Stats: 4:15:55 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.57% done; ETC: 16:05 (0:03:36 remaining)
Stats: 6:03:16 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.63% done; ETC: 17:54 (0:04:58 remaining)
Stats: 6:41:50 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.64% done; ETC: 18:33 (0:05:26 remaining)
Stats: 7:01:34 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.65% done; ETC: 18:53 (0:05:40 remaining)
Stats: 8:12:29 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.69% done; ETC: 20:05 (0:06:27 remaining)
Stats: 8:25:51 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.69% done; ETC: 20:18 (0:06:36 remaining)
Stats: 8:37:41 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.70% done; ETC: 20:30 (0:06:44 remaining)
Stats: 8:59:00 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.70% done; ETC: 20:52 (0:07:00 remaining)
Stats: 21:51:08 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.08% done; ETC: 09:49 (0:12:11 remaining)
Stats: 22:30:33 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.09% done; ETC: 10:29 (0:12:23 remaining)
Stats: 22:34:02 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.09% done; ETC: 10:32 (0:12:24 remaining)
Stats: 22:46:02 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.09% done; ETC: 10:44 (0:12:27 remaining)
Stats: 23:15:10 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.11% done; ETC: 11:13 (0:12:31 remaining)
Stats: 25:09:43 elapsed; 6 hosts completed (64 up), 60 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.16% done; ETC: 13:08 (0:12:42 remaining)
dmiller-nmap commentedon Nov 21, 2018
Yeah, it's grinding slower and slower on the port scan. 65K ports on 60 targets is a lot to get through, and something is causing it to get slower more rapidly than it can complete ports. Disconnecting the network will actually make Nmap go slower, not faster, so that's not a good way to force the scan to finish. I'm tracking that issue separately: #1394.
-Pnturns off all host discovery, not just ICMP Echo Request. For historical reasons, this is frequently referred to as "ping scanning," but I've been trying to improve the documentation to address this confusion. The default host discovery probes are-PE(ICMP Echo Request),-PS443(TCP SYN port 443),-PA80(TCP ACK port 80), and-PP(ICMP Timestamp Request). As I suggested earlier, you can come up with your own assortment of host discovery probes. Even if you plan to do a-Pnscan on all "down" targets, doing so separately ought to improve overall speed.spencerroth3 commentedon Nov 9, 2020
Was there ever a final resolution to this issue? It is 2 years later, and I am still facing the same issues as @blincoln-dd
IGORYUCH commentedon Jan 2, 2021
If anyone is still facing this, you can use a script I wrote to get this bug around. You can find it here.
pr0b3r7 commentedon Jul 26, 2021
Facing this issue as well - any clue on how to address it? @IGORYUCH your command gave me further errors as well.
rvacyber commentedon Mar 27, 2022
Came across this issue today scanning about 50 IP's over the internet. Running Ubuntu 20.04.4 LTS from an Azure server. Bare bones OS install with nmap installed from the repository using apt-get. Nothing else installed.
Command used was
sudo nmap -Pn -p- -sV -O --script "safe" -iL input -oX output
The scan ran, and took a long time, but completed exactly when I thought it would based on the early nmap progress indicators. I got the screen output that was expected for the scan. But when I went to check the output file I noticed nmap was still going, almost looking like it was starting the same scan all over again. It's been running for about 10 hours now and is getting progressively slower the closer it gets to the end:
Stats: 14:55:36 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 41.10% done; ETC: 08:14 (0:28:20 remaining)
Stats: 14:55:36 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 41.11% done; ETC: 08:14 (0:28:19 remaining)
Stats: 15:04:15 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 55.34% done; ETC: 08:17 (0:22:56 remaining)
Stats: 20:08:55 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.83% done; ETC: 13:03 (0:03:57 remaining)
Stats: 21:18:08 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.91% done; ETC: 14:13 (0:04:26 remaining)
Stats: 21:18:52 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 98.91% done; ETC: 14:13 (0:04:26 remaining)
Stats: 22:43:03 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.01% done; ETC: 15:38 (0:04:52 remaining)
Stats: 22:51:32 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.02% done; ETC: 15:47 (0:04:54 remaining)
Stats: 22:53:24 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.02% done; ETC: 15:48 (0:04:54 remaining)
Stats: 24:18:51 elapsed; 4 hosts completed (39 up), 35 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 99.13% done; ETC: 17:14 (0:05:09 remaining)
DISCLAIMER: I'm still learning nmap so don't torch me if I did something stupid please. Found this page after encountering the issue so I will try some of the suggestions above next time, but I thought it was worth reporting.
EDIT: naturally this scan finished as I was typing this post. It did not produce any other screen output, but did produce the expected output file. Maybe this is happening while nmap is generating the XML output file? Just a complete wild ass guess.
nnposter commentedon Mar 27, 2022
As noted earlier in this thread, doing a 64K port scan blindly, without any upfront determination whether the hosts are up and what their effective RTT is, has the propensity to take unreasonable amount time, especially if the hosts are behind a firewall.
At a minimum, you should try using options
--max-rtt-timeoutand--max-retriesto reduce the time Nmap is retrying and waiting for packets that never come. What values to choose depends heavily on the specific environment. For scanning non-IoT targets, I would start with something like 500ms and 2 retries on a non-congested corporate WAN network and 1s with 3 retries over decent internet connection. You may have to go substantially higher on RTT if you are scanning over satellite links or targeting low-powered devices. You would also want to crank up the retries if the network is congested.dmiller-nmap commentedon Sep 23, 2022
Closing this report since there is not a specific actionable defect to address. Several workarounds and adjustments have been mentioned for slow scans. If you have issues with the speed of scanning after taking these steps, feel free to open a new issue:
-T4or-T5-Pnwhenever possible.--open(or--defeat-rst-ratelimit) if you only care about open ports. This lets Nmap stop waiting for rate-limited RST packets and just keep going with sending new probes.--host-timeoutor--script-timeout) for scanning each target to ensure you get results quickly, then go back and scan the timed-out targets if necessary.--initial-rtt-timeoutand--max-rtt-timeoutset limits on how long to wait for responses. (-T4sets these to 500ms and 100ms)--max-retrieslimits how many times Nmap will retry a probe before moving on. (-T4uses 6)--max-scan-delaylimits how much Nmap will slow down between sending probes in order to get results from rate-limiting or oversaturated targets. (-T4sets this to 10ms for TCP and 1000ms for UDP)--min-rateis a sledgehammer option that bypasses all other checks to ensure Nmap keeps sending probes at the requested rate (packets per second). This can result in inaccuracy if set too high.