Nmap Development mailing list archives

Re: [patch] The most minor issue ever: set noninteractive on -iL -


From: Patrick Donnelly <batrick () batbytes com>
Date: Wed, 28 Mar 2012 15:01:57 -0400

On Wed, Mar 28, 2012 at 2:14 PM, David Fifield <david () bamsoftware com> wrote:
On Wed, Mar 28, 2012 at 12:07:25PM -0500, Daniel Miller wrote:
List,

While digging through the option parsing in nmap.cc for a
presentation, I noticed that the input of hostnames (-iL or -i)
could come from stdin. I think if this is used, then
o.noninteractive should be set, since there would be no way to get
keystrokes:
Index: nmap.cc
===================================================================
--- nmap.cc    (revision 28355)
+++ nmap.cc    (working copy)
@@ -1048,6 +1048,7 @@
      }
      if (!strcmp(optarg, "-")) {
        o.inputfd = stdin;
+        o.noninteractive = true;
      } else {
        o.inputfd = fopen(optarg, "r");
        if (!o.inputfd) {

I doubt this really matters much, but I thought I'd mention it.

Thanks, Dan, but I think this is incorrect. Nmap doesn't get runtime
interaction keystrokes from stdin, but from the tty. I just tested it
and this works:

nmap --scan-delay 10ms -iL - < input.txt

But this doesn't:

cat input.txt | nmap --scan-delay 10ms -iL -

Probably there is some subshell interaction with the tty that prevents
the second example from working.

The second example doesn't work because, in nmap_tty.cc, Nmap closes
the tty FD if it is not the foreground process group leader. In
tty_init:

#ifndef __CYGWIN32__
    if (tcgetpgrp(tty_fd) != getpid()) {
        close(tty_fd); return;
    }
#endif

getpid should maybe be getpgrp so that Nmap accepts terminal input
even when it's part of a pipeline (i.e. not the process group leader).

Also, I used to have problems with this when Nmap was called in a
script (e.g. automated benchmarking) run in the foreground. For
example:

<test.sh>
#!/bin/bash

nmap -iL <(echo example.com) --scan-delay 10ms

exit 1
</test.sh>

[The exit 1 is necessary because bash optimizes a simple command to an
exec if it is the only command.] I would argue that nmap in this case
should still accept terminal input.

-- 
- Patrick Donnelly
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/

Current thread: