Skip to content

nmap hangs while scanning, bad file descriptor #2042

Closed

Description

@d21d3q

Haven't tried to reproduce it yet, for now I managed to attach to running scan and grab some info. I will update this issue if I will have more information.

nmap -n -Pn -oG /tmp/nmap-<ip>-1432834534 -sS --defeat-rst-ratelimit -sU -p T:<long list of ports> --scan-delay 10 <ip>
# nmap --version

Nmap version 7.40 ( https://nmap.org )
Platform: x86_64-pc-linux-gnu
Compiled with: liblua-5.3.3 openssl-1.1.0c libpcre-8.39 libpcap-1.8.1 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select
# uname -a
Linux debian 4.9.0-12-amd64 #1 SMP Debian 4.9.210-1 (2020-01-20) x86_64 GNU/Linux
# strace -p1212 -s9999
strace: Process 1212 attached
select(6, [5], NULL, NULL, {tv_sec=9, tv_usec=170055}) = 0 (Timeout)
ioctl(-1, TIOCGPGRP, 0x7ffe4a632bdc) = -1 EBADF (Bad file descriptor)
getpgrp() = 872
sendto(4, "E\0\0,/&\0\0005\6X\321\300\250\n\332P\370\341Z\3206\10:y\221\273\257\0\0\0\0`\2\4\0\210\237\0\0\2\4\5\264", 44, 0, {sa_family=AF_INET, sin_port=htons(2106), sin_addr=inet_addr("<ip>")}, 16) = 44
select(6, [5], NULL, NULL, {tv_sec=9, tv_usec=999728}) = 1 (in [5], left {tv_sec=9, tv_usec=964264})
ioctl(-1, TIOCGPGRP, 0x7ffe4a632bdc) = -1 EBADF (Bad file descriptor)
getpgrp() = 872
select(6, [5], NULL, NULL, {tv_sec=9, tv_usec=963845}^Cstrace: Process 1212 detached
 <detached ...>

and above keeps repeating

(gdb) attach 1212
(gdb) bt
#0 0x00002ad3702905e3 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:84
#1 0x0000563913f0c0b9 in pcap_select(pcap*, timeval*) ()
#2 0x0000563913f0c47d in pcap_select(pcap*, long) ()
#3 0x0000563913edfb74 in readip_pcap(pcap*, unsigned int*, long, timeval*, link_header*, bool) ()
#4 0x0000563913ecbbd1 in get_pcap_result(UltraScanInfo*, timeval*) ()
#5 0x0000563913ec43b1 in ultra_scan(std::vector<Target*, std::allocator<Target*> >&, scan_lists*, stype, timeout_info*) ()
#6 0x0000563913e969b1 in nmap_main(int, char**) ()
#7 0x0000563913e68c41 in main ()
# lsof -p 1212
(...)
nmap 1212 root mem REG 0,8 28012 socket:[28012] (stat: No such file or directory)
(...)
# ls -lh /proc/1212/fd
total 0
lr-x------ 1 root root 64 May 12 10:14 0 -> /dev/null
lrwx------ 1 root root 64 May 12 10:14 1 -> socket:[28003]
lrwx------ 1 root root 64 May 12 10:14 2 -> socket:[28003]
l-wx------ 1 root root 64 May 12 10:14 3 -> /tmp/nmap-<ip>-1432834534
lrwx------ 1 root root 64 May 12 10:14 4 -> socket:[28010]
lrwx------ 1 root root 64 May 12 10:14 5 -> socket:[28012]

Activity

  1. livelace commented on May 21, 2020

    @livelace

    I'm experiencing the same thing. Firstly I found this link #1385, but after stracing I found this one :)

    version:

    nmap --version
    Nmap version 7.80 ( https://nmap.org )
    Platform: x86_64-alpine-linux-musl
    Compiled with: liblua-5.3.5 openssl-1.1.1d libssh2-1.9.0 libz-1.2.11 libpcre-8.44 libpcap-1.9.1 nmap-libdnet-1.12 ipv6
    Compiled without:
    Available nsock engines: epoll poll select
    

    strace:

    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=81303}) = 1 (in [6], left {tv_sec=0, tv_usec=59001})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=58835}) = 1 (in [6], left {tv_sec=0, tv_usec=43533})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=43346}) = 1 (in [6], left {tv_sec=0, tv_usec=22184})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=21997}) = 1 (in [6], left {tv_sec=0, tv_usec=2476})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=2316}) = 0 (Timeout)
    ioctl(-1, TIOCGPGRP, 0x7ffc490b2fcc)    = -1 EBADF (Bad file descriptor)
    getpgid(0)                              = 2679
    select(7, [6], NULL, NULL, {tv_sec=1, tv_usec=0}) = 1 (in [6], left {tv_sec=0, tv_usec=981371})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=981210}) = 1 (in [6], left {tv_sec=0, tv_usec=981207})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=981122}) = 1 (in [6], left {tv_sec=0, tv_usec=965825})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=965707}) = 1 (in [6], left {tv_sec=0, tv_usec=949055})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=948919}) = 1 (in [6], left {tv_sec=0, tv_usec=929147})
    select(7, [6], NULL, NULL, {tv_sec=0, tv_usec=928982}) = 1 (in [6], left {tv_sec=0, tv_usec=913992})  
    

    some proc info:

    # ls -l /proc/2804/fd/                         
    total 0
    lr-x------    1 root     root            64 May 21 06:59 0 -> pipe:[50339]
    l-wx------    1 root     root            64 May 21 06:59 1 -> /root/xxx/nmap.log
    l-wx------    1 root     root            64 May 21 06:59 2 -> /root/xxx/nmap.log
    l-wx------    1 root     root            64 May 21 06:59 3 -> /root/xxx/nmap.xml
    lrwx------    1 root     root            64 May 21 06:59 4 -> anon_inode:[eventpoll]
    lrwx------    1 root     root            64 May 21 06:59 5 -> socket:[58711]
    lrwx------    1 root     root            64 May 21 06:59 6 -> socket:[58713]
    

    logs (they are still filling):

    tail -n10 /root/xxx/nmap.log
    Ping Scan Timing: About 99.24% done; ETC: 12:43 (0:02:36 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 12:45 (0:02:37 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 12:48 (0:02:38 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 12:51 (0:02:40 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 12:53 (0:02:41 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 12:56 (0:02:42 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 12:59 (0:02:43 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 13:02 (0:02:45 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 13:04 (0:02:46 remaining)
    Ping Scan Timing: About 99.24% done; ETC: 13:07 (0:02:47 remaining)
    

    args:

    nmap -v -sS -sV -O --open -oX /root/xxx/nmap.xml --host-timeout 5m x.x.x.x/20 y.y.y.y/20
    
  2. livelace commented on May 22, 2020

    @livelace

    the situation has changed, if replace -sS with -sT - the scanning is completed and nmap doesn't stuck at all (how it was before, stucking last more than 1 day before I killed it).

    btw, "Bad file descriptor" appears even for -sT scanning.

  3. livelace commented on Jun 2, 2020

    @livelace

    update. -sT doesn't help :)

    I decreased port numbers from default to 78 ports and:

    Stats: 41:22:28 elapsed; 21632 hosts completed (21696 up), 64 undergoing Service Scan
    
  4. dmiller-nmap commented on Sep 23, 2022

    @dmiller-nmap

    The EBADF (Bad file descriptor) error is in response to ioctl(TIOCGPGRP), which comes from a call to tcgetpgrp() in nmap_tty.cc. This is expected behavior when Nmap is not the foreground process of a terminal, though I will see about making it a bit more efficient if I can. The hang issue is unrelated, so I will investigate that.

  5. dmiller-nmap commented on Sep 23, 2022

    @dmiller-nmap

    I do not think this is a true hang; the strace output shows that probes are still being sent, and each Nmap output listed here shows it is in a different scan phase (First one uses -Pn and shows a TCP RST packet, another is in Ping scan, the last in Service scan). Notably, the original report used --scan-delay 10 and a "long list of ports," which means the scan should be expected to take a long time, since Nmap must wait 10 seconds between sending each new probe. I am closing this issue; if you are experiencing hangs, please open a new issue or find an existing issue that describes a hang in the same scan phase with the same scan options as your report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions