1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 20:51:30 +00:00
Commit Graph

267 Commits

Author SHA1 Message Date
david
198282a9c3 Remove some Windows-only function prototypes that are obsolete. There are not
defined anywhere.

void nmapwin_init();
void nmapwin_cleanup();
void nmapwin_list_interfaces();
int if2nameindex(int ifi);
2010-06-07 18:42:17 +00:00
luis
ac860ca961 Corrected trivial typo 2010-05-17 17:56:29 +00:00
david
5cf726d259 Fix up indentation in collect_dnet_interfaces. 2010-05-12 16:34:25 +00:00
fyodor
1aecac420f Update copyright year from 2009 to 2010 2010-05-03 21:20:25 +00:00
david
b7387894f5 Fix comment typos. 2010-04-30 18:14:52 +00:00
david
8bc5135d93 When iterating over the interface list on systems that have sa_len, only
allow the sa_len to increase the size of the current structure, not
decrease it below sizeof(struct ifreq). Doing it this way makes it work
on NetBSD. This technique more or less matches that used in Unix Network
Programming, 3rd Edition, section 17.6. The old implementation was
likely incorrect, though it happened to work on FreeBSD.
2010-03-26 22:11:30 +00:00
david
bc132b963c Make read_arp_reply_pcap work with a libpcap datalink type of
DLT_LINUX_SLL, as well as the DLT_EN10MB that was formerly supported.
This type is used on some interfaces where Linux doesn't reliably retain
the link-layer header, and when capturing on the "any" device. On such
interfaces, you would get the error

read_arp_reply_pcap called on interfaces that is datatype 113 rather than DLT_EN10MB (1)

For more on this datalink type, see

pcap-linktype(7)
http://wiki.wireshark.org/SLL

I tested this by hacking scan_engine.cc to use the "any" device:

--- scan_engine.cc      (revision 16972)
+++ scan_engine.cc      (working copy)
@@ -4882,7 +4882,7 @@
     }
   }

-  USI->pd = my_pcap_open_live(Targets[0]->deviceName(), 100,  (o.spoofsource)? 1 : 0, pcap_selectable_fd_valid()? 200 : 2);
+  USI->pd = my_pcap_open_live("any" /*Targets[0]->deviceName()*/, 100,  (o.spoofsource)? 1 : 0, pcap_selectable_fd_valid()? 200 : 2);
   if (USI->ping_scan_arp){
     /* Some OSs including Windows 7 and Solaris 10 have been seen to send their
        ARP replies to the broadcast address, not to the (unicast) address that

I had to use a newer version of libpcap from git. The 1.0.0 that we ship
has a bug that keeps "any" from working. You would get SIOCGIFHWADDR: No
such device.
2010-03-12 05:23:50 +00:00
david
d109ff13d8 Consider an address directly connected if the gateway of its matching routing
table is exactly the same as the address. This is how it appears to work on Mac
OS X. Now there are three ways for an address to be directly connected:

1. Gateway address is 0.0.0.0 (Linux).
2. Gateway address is the same as local interface address (Windows).
3. Gateway address is the same as the destination address (Mac OS X).
2010-03-12 00:45:11 +00:00
david
02b1a00bf9 Change the way route_dst works to allow static routes to override
interface addresses and netmasks.

Before, route_dst worked like this:
  1) Check destination address against all interfaces, with special-case
     handling for local addresses.
  2) Check destination address against routing table.

Now it works like this:
  1) Check destination address against local addresses.
  2) Check destination address against routing table.
  3) Check destination address against all interfaces.

This allows a routing table entry to override an interface, for example
in this configuration:

  ************************INTERFACES************************
  DEV  (SHORT) IP/MASK         TYPE     UP MAC
  eth0 (eth0)  192.168.0.21/24 ethernet up 00:00:00:00:00:00

  **************************ROUTES**************************
  DST/MASK       DEV  GATEWAY
  192.168.0.3/32 eth0 192.168.0.1
  192.168.0.0/24 eth0

192.168.0.3 will not be considered directly connected, but will have its
traffic routed through 192.168.0.1.

The logic for determining when an address is directly connected has
changed. Instead of considering an address directly connected whenever
it matches an interface netmask, we consider it so when the gateway
address is 0.0.0.0 or when the gateway address is exactly equal to the
interface address. The proper way to do this would be to look at the "G"
flag from the routing table, but libdnet doesn't retain that.
2010-03-11 20:04:21 +00:00
david
0f048bb0f4 Compare addresses if netmasks are equal in the qsort comparison function
for routes, to ensure that routes keep their same relative order. This
idea is from http://www.gnu.org/s/libc/manual/html_node/Array-Sort-Function.html.
2010-03-11 18:03:01 +00:00
david
48654df805 Switch to -sn and -Pn as the new preferred synonyms for -sP and -P0.
This establishes a more regular syntax for some options that disable
phases of a scan:
	-n  no reverse DNS
	-Pn no host discovery
	-sn no port scan
Also, the -sP was possibly misleading because the 'P' suggests "ping
scan," when you can now do more than just pinging when you disable port
scanning. For example, -sC -sn and -sn -Pn --traceroute make sense.
2010-03-11 01:16:06 +00:00
david
9a31e8b830 Change PacketTrace::traceArp not to take the Ethernet header. It wasn't
being used, and this leaves the door open for non-Ethernet encapsulation
of ARP packets, in particular the Linux "cooked" socket encapsulation
that can in some cases be used by libpcap.
2010-03-10 16:58:24 +00:00
kris
a42ea72a97 Merge through r16884 from /nmap-exp/kris/nse-rawip plus the following changelog
entries:

o [NSE] Raw packet sending at the IP layer is now supported, in addition to
  the Ethernet sending functionality.  Packets to send start with an IPv4
  header and can be sent to arbitrary hosts. [Kris]

o [NSE] Added the ipidseq script to classify a host's IP ID sequence numbers
  in the same way Nmap does.  This can be used to test hosts' suitability for
  Nmap's Idle Scan (-sI), i.e. check if a host is an idle zombie.  This is
  the first script to use the new raw IP sending functionality in NSE. [Kris]

o [NSE] Added the function nmap.is_privileged() to tell a script if, as far
  as Nmap's concerned, it can do privileged operations.  For instance, this
  can be used to see if a script should be able to open a raw socket or
  Ethernet interface. [Kris]

o [NSE] Added the function nmap.get_ports() to allow a script to iterate
  over a host's port tables matching a certain protocol and state. [Kris,
  Patrick]
2010-02-26 20:42:10 +00:00
david
f21a07cfde Revert r16464. 2010-01-15 03:55:23 +00:00
david
c73b250615 Factor out a function that reports the failure to open an Ethernet
device and exits. On Windows, print a hint about "net start npf" to
start the NPF service.
2010-01-15 00:37:39 +00:00
david
577fc127f7 Use socket_strerror, not plain strerror, to report the result of non-blocking
connections in tcpip.cc. socket_strerror works with Winsock error codes whereas
plain strerror returns "Unknown error".

However, the error string for what is probably the most common error code,
WSAEWOULDBLOCK, is the big ugly "A non-blocking socket operation could not be
completed immediately.". Add a special case to use "Operation now in progress"
for that specific error.
2010-01-13 19:22:41 +00:00
david
3723852e17 Use the same trick of peeking inside the ARP packet for the destination
MAC in the doArp function as is done for ARP ping scan in
scan_engine.cc. This makes us capable of reading ARP responses that are
sent to the broadcast address.
2009-11-19 04:51:38 +00:00
david
d7cae0a753 Fix the test for an IPv4 packet in readip_pcap. It was checking this condition:
(*p & 0x40) == 0x40
But that doesn't check that the upper half of the byte is 4. It's true for 4,
5, 6, 7, 12, 13, 14, and 15. I changed it to
	(*p & 0xF0) == 0x40
2009-11-07 02:03:07 +00:00
david
f1dabda17c Fix some pointer declarations messed up by indent. 2009-10-27 15:41:22 +00:00
fyodor
93c4dec5d0 Applied FreeBSD portability patch from Jay Fink (he found it in FreeBSD ports tree). The patch
marks pcap file descriptors as not select()able by Nmap for FreeBSD versions < 5 (__FreeBSD_version < 500000)
2009-09-17 03:03:10 +00:00
david
577a1be0e7 Merge from svn://svn.insecure.org/nmap-exp/david/nmap-traceroute. This
brings in a new, faster, parallel version of traceroute.
2009-09-17 00:03:46 +00:00
david
3833d31ed6 Be more robust in parsing /proc/net/route. Check for a missing interface
name. If the destination is missing, ignore that line and continue with
the next line rather than giving up on the whole file. Patch by Ankur
Nandwani.
2009-09-07 22:04:56 +00:00
david
d99e5ec7ea Cast struct ifconf.ifc_buf to (char *) to fix a compiler error on
NetBSD, where that member has type void *. Jay Fink reported the
problem.
2009-08-31 18:55:57 +00:00
david
8605f18da4 Normalize indentation and whitespace in tcpip.cc with
indent -kr -i2 -nut -brf tcpip.cc
followed by manual adjustment.
2009-08-29 02:44:00 +00:00
david
cd5010893e Adapt part of the code I missed in r15354; the code for an address mask
request did take into the account the size of the u32 in pointer
arithmetic, so it had to be changed with the change to u8.
2009-08-29 01:50:31 +00:00
david
02c9cf42f7 Fix some pointer arithmetic in build_icmp_raw. There were two bugs. The
first is a pointer was kept to the beginning of the packet payload, and
it was increased based on the varying size of the ICMP header. But its
type was pointer to u32 instead of pointer to u8, so the expression
datastart += 12 actually increased the pointer by 48 bytes, leaving
garbage in the first 36 bytes of the payload and making it possible for
the buffer to overflow. The second was that the remaining space left in
the buffer was not decreased when the datastart was increased, again
making it possible to overflow. I got a reliable segmentation fault with
the command
nmap -PP 1.2.3.4 --data-length 1480
2009-08-29 01:45:28 +00:00
luis
a5ca31db9e Replaced nmap's hex dump functions with new hexdump() included in nbase. Before
Nmap used two functions: one of them, hdump(), just printed raw hex bytes 
(no ASCII equivalents) and the other one, lamont_hdump() had a bug when 
printing buffers where bufflen%16==3. A new function has been implemented 
from scratch, that basically produces the same output as Wireshark. 
Output looks like this:

0000   e8 60 65 86 d7 86 6d 30  35 97 54 87 ff 67 05 9e  .`e...m05.T..g..
0010   07 5a 98 c0 ea ad 50 d2  62 4f 7b ff e1 34 f8 fc  .Z....P.bO{..4..
0020   c4 84 0a 6a 39 ad 3c 10  63 b2 22 c4 24 40 f4 b1  ...j9.<.c.".$@..

Changes:

- The new hexdump() function has been added to nbase.
- Old hdump() and lamont_dump() have been removed from nmap's code.
- A wrapper to the new hexdump(), called nmap_hexdump(), has been added
  to nmap's utils.cc. The wrapper basically prints the buffer returned 
  by hexdump() using nmap's log_write() function.
2009-08-25 18:09:19 +00:00
david
f09c8091a4 Avoid doing a calculation with an uninitialized tv_start if no timeout
has been specified.
2009-08-24 21:32:01 +00:00
david
cfeb9d6563 fclose the /proc/net/route file handle after reading routes from it. 2009-08-24 21:07:47 +00:00
david
7194d27631 Fix a logic error in getinterfaces_siocgifconf. The check for increasing
the capacity of the list of interfaces was off by one. This caused a
crash on initialization for systems with more than 16 network
interfaces.
2009-07-28 22:34:48 +00:00
david
eac15cb919 Apply a patch by Dmitry Levin that uses a network interface's full name,
including alias extension, in several places to avoid this error message
when an alias has an IP address but the primary interface doesn't:
Failed to lookup subnet/netmask for device (venet0): venet0: no IPv4 address assigned
The patch also considers an interface alias if the primary interface
does not appear in the list of interfaces (perhaps because it does not
have an IP address assigned) when building the table of routes.
2009-07-27 19:01:58 +00:00
david
a88bda3d78 Make it a warning, not a fatal error, when we can't get the hardware address
for an interface, and skip the interface. The warning looks like

Warning: Unable to get hardware address for interface %s -- skipping it.

This happens when a FireWire interface (fw*) has an address configured on Mac
OS X. Previously Nmap would die in getinterfaces so it wasn't even possible to
scan over the other interfaces.
2009-07-20 18:59:58 +00:00
david
871629626e Simplify and comment getinterfaces_siocgifconf to make its structure
more clear: We call several different ioctls on each interface and use
the results to populate the interface_info array.
2009-07-09 00:09:25 +00:00
david
1d5f68a080 Remove a bogus leftover use of a valid pointer as a throwaway variable
in getinterfaces. This was the cause of an overlapping memcpy reported
at http://seclists.org/nmap-dev/2009/q2/0713.html.

In the code, sin is a pointer that holds the address of the IP address
configured for an interface. It is copied into a tmpifr.ifr_addr before
each ioctl, perhaps because that is required on some platforms even
though on Linux only ifr_name is needed by the ioctl. When the ioctl
returns, it overwrites whatever was in ifr_addr because that member is
in a union, so sin is kept in order to restore the address again before
the next ioctl.

In the code that handles SIOCGIFNETMASK, sin was mistakenly used as a
temporary pointer and redirected to &tmpifr.ifr_addr. This caused all
future memcpys before ioctl to copy tmpifr.ifr_addr to itself, rather
than copying in the IP address of the interface.

The throwaway sin assignment was not even used; the code that used it
was modified in r2751. So now we just keep sin pointing where it should
the whole time.
2009-07-08 23:09:35 +00:00
david
be55765315 Break up the getinterfaces function, which did one thing for Windows and
another thing otherwise in a big if/else. Now getinterfaces just does
caching and getinterfaces_dnet or getinterfaces_siocgifconf does the
actual interface lookup.
2009-07-08 21:42:03 +00:00
luis
2b4e4e7a8d Fixed a bug in devname2ipaddr(). The IP returned by the function was always 2.0.0.0 due to an error handling a pointer. Check http://seclists.org/nmap-dev/2009/q3/0047.html for detailed information. Also, devname2ipaddr() now makes sure we are dealing with AF_INET devices (currently the getinterfaces() function already skips non AF_INET interfaces, but this way it won't break if that changes in the future.) 2009-07-07 14:37:19 +00:00
david
9cbde2f3a0 Factor out Ethernet and socket sending function to avoid a big if-else
in send_ip_packet.
2009-07-03 18:52:54 +00:00
david
7eb63c1c2d On some BSD systems, we have to byte-swap the ip_len and ip_off fields before
sending. In send_ip_packet, unswap them after sending so that the buffer is
returned unmodified. Do the packet trace after unswapping the values so that
the correct length and fragmentation offset are reported. On Mac OS X, an
ip_len of 60 (0x003c) was being reported as 15360 (0x3c00) and when ip_off had
the DF flag set (0x4000), it looked like a fragmentation offset of 512
(0x0040 * 8).
2009-07-03 18:27:31 +00:00
david
a4c92f83e7 Use the preprocessor defines IP_DF and IP_OFFMASK instead of literal
0x4000 and 8191.
2009-07-03 18:11:15 +00:00
daniel
50830f7488 o Added initial SCTP port scanning support to Nmap. SCTP is
a layer 4 protocol used mostly for telephony related applications.
  This brings the following new features:
  o SCTP INIT chunk port scan (-sY): open ports return an INIT-ACK
    chunk, closed ones an ABORT chunk.  This is the SCTP equivalent
    of a TCP SYN stealth scan.
  o SCTP COOKIE-ECHO chunk port scan (-sZ): open ports are silent,
    closed ports return an ABORT chunk.
  o SCTP INIT chunk ping probes (-PY): host discovery using SCTP
    INIT chunk packets.
  o SCTP-specific IP protocol scan (-sO -p sctp).
  o SCTP-specific traceroute support (--traceroute).
  o The ability to use the deprecated Adler32 algorithm as specified
    in RFC 2960 instead of CRC32C from RFC 4960 (--adler32).
  o 42 well-known SCTP ports were added to the nmap-services file.
  Part of the work on SCTP support was kindly sponsored by
  Compass Security AG, Switzerland.  [Daniel Roethlisberger]
2009-06-03 23:15:45 +00:00
david
4308302f7d Update the error message shown when attempting to scan an interface
address on Solaris. The Solaris error message was
	/dev/lo: No such file or directory
but apparently it can also be
	lo0: No DLPI device found
Also changed the message to say that it can happen when scanning any
interface address, not just localhost. The new error message was lately
reported by Dom De Vitto.

http://seclists.org/nmap-dev/2006/q2/0127.html
http://seclists.org/nmap-dev/2009/q1/0853.html
2009-05-11 22:31:48 +00:00
fyodor
d0e21e1d03 Suggest that people send patches to nmap-dev rather than to me directly 2009-04-15 00:37:03 +00:00
fyodor
eccc235d5a Increase copyright year to 2009, simplify/reword some derivative works text, and remove a confusing clause about selling proprietary front-ends to Nmap 2009-03-31 04:16:12 +00:00
david
970a75edcf Display a warning if we can't read the first line (column headers) of
/proc/net/route. This also silences a _FORTIFY_SOURCE warning.
2009-01-23 21:59:22 +00:00
david
af1ccf0cfe Patch from jah: Move the definition of struct dnet_collector_route_nfo earlier
in tcpip.cc for the WIN32 functions that need it.
2009-01-04 15:08:12 +00:00
david
46378a0dfd Rearrange the dnet route functions so they are all together, add a function
comment.
2009-01-01 19:33:19 +00:00
david
adab33deb9 Split out the assignment of interfaces to routes into a postprocessing step. We
need to have all the routes available before assigning interfaces to handle a
situation like the following:

# nmap --iflist
************************INTERFACES************************
DEV  (SHORT) IP/MASK        TYPE        UP MAC
lo0  (lo0)   127.0.0.1/8    loopback    up
ppp0 (ppp0)  YY.YY.YY.YY/16 point2point up

# netstat -rn
Destination  Gateway      Flags  Refs  Use  Netif Expire
default      XX.XX.XX.XX  UGSc      7   16   ppp0
XX.XX.XX.XX  YY.YY.YY.YY  UH        8    0   ppp0

Here the second route can be matched up immediately with the ppp0 device,
because the YY.YY.YY.YY gateway address matches the YY.YY.YY.YY/16 IP and mask
of ppp0. But the first route (default) needs to go through the second route in
order to find its interface. So we don't reject the default route immediately,
but save it an try to match it with an interface after all routes have been
found. See http://seclists.org/nmap-dev/2008/q4/0576.html for more information.
2009-01-01 19:29:44 +00:00
david
9f7cffc025 Refactor getsysroutes. It had two ways to get routes: by reading
/proc/net/route and with libdnet. I split those into two separate functions.
2009-01-01 16:45:55 +00:00
kris
5be831f06f o Fixed a bug in the IP validation code which would have let a specially
crafted reply sent from a host on the same LAN slip through and cause
  Nmap to segfault.  Thanks to ithilgore of sock-raw.homeunix.org for
  the very detailed bug report. [Kris]
2008-11-21 16:17:11 +00:00
david
854a04b21c Add a guard against getaddrinfo returning no addresses in tcpip.cc. 2008-09-04 14:41:59 +00:00