diff --git a/CHANGELOG b/CHANGELOG index 117efdf2c..925ba1621 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2564,6 +2564,9 @@ o Added XML output (-oX). Hopefully this will help those of you emphasize that XML is now the preferred machine-readable output format. But don't worry if your tool uses -oM , that format (and the deprecated -oM flag) won't go away any time soon (if ever). + Thanks to Stou Sandalski (tangui(a)cell2000.net) and Fredrick Paul + Eisele (phreed(a)gmail.com) for sending proposals that inspired the + format used. o Applied patch from Stefan Rapp (s.rapp(a)hrz.uni-dortmund.de) which fixes a variable argument integer promotion problem in the new diff --git a/Makefile.in b/Makefile.in index d41bc9207..c66e33a10 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -export NMAP_VERSION = 3.83.DC13 +export NMAP_VERSION = 3.83.DC15 NMAP_NAME= nmap NMAP_URL= http://www.insecure.org/nmap/ NMAP_PLATFORM=@host@ diff --git a/docs/nmap.usage.txt b/docs/nmap.usage.txt index c86b0c6f6..8cb32d3a3 100644 --- a/docs/nmap.usage.txt +++ b/docs/nmap.usage.txt @@ -1,4 +1,4 @@ -Nmap 3.83.DC13 Usage: nmap [Scan Type(s)] [Options] +Nmap 3.83.DC15 Usage: nmap [Scan Type(s)] [Options] Some Common Scan Types ('*' options require root privileges) * -sS TCP SYN stealth port scan (default if privileged (root)) -sT TCP connect() port scan (default for unprivileged users) diff --git a/libdnet-stripped/NMAP_MODIFICATIONS b/libdnet-stripped/NMAP_MODIFICATIONS index 64a70cd76..81e525359 100644 --- a/libdnet-stripped/NMAP_MODIFICATIONS +++ b/libdnet-stripped/NMAP_MODIFICATIONS @@ -1,7 +1,7 @@ $Id$ This is Dug Song's excellent Libdnet networking library version 1.10. -It has been stripped down for inclusion within Nmap as follows: +It has been stripped down for inclusion within Nmap and modified as follows: o Removed the following directories: python, test, man @@ -20,6 +20,21 @@ o Replaced config.guess config.sub and missing in config dir with o Added this NMAP_MODIFICATIONS file. +o Added include/winconfig.h, which is a modified config.h to better support + Windows compilation via Visual Studio. Added conditional includes + for it to a bunch of the dnet source files. + +o A number of portability changes to remove errors/warnings during + Win32 Visual Studio.Net compilation. This was mostly a matter of + adding casts and a few extra include files. + +o Added libdnet-stripped.vcproj -- A Visual Studio.Net project file + for dnet. + +o Changed eth_open() in eth-win32.c to more frequently consider the +results of PacketGetAdapterNames() to be in single-char format rather +than 2-byte wide characters. + o Made some code changes to intf.c (the patch below). This does the following: o Preserve the alias qualifier from interface name in more cases diff --git a/libdnet-stripped/include/dnet/os.h b/libdnet-stripped/include/dnet/os.h index c12c7b20c..7bac1caa7 100644 --- a/libdnet-stripped/include/dnet/os.h +++ b/libdnet-stripped/include/dnet/os.h @@ -23,7 +23,11 @@ typedef u_short uint16_t; typedef u_int uint32_t; # ifndef __CYGWIN__ - typedef long ssize_t; + typedef unsigned int ssize_t; +# endif +#if !defined(__GNUC__) +#define snprintf _snprintf +#define vsnprintf _vsnprintf # endif #else # include @@ -118,8 +122,8 @@ # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L # define __flexarr [] # elif defined(_WIN32) -/* MS VC++ */ -# define __flexarr [] +/* MS VC++ -- using just [] may work, but gives a non-standard extension warning */ +# define __flexarr [1] # else /* Some other non-C99 compiler. Approximate with [1]. */ # define __flexarr [1] diff --git a/libdnet-stripped/include/dnet_winconfig.h b/libdnet-stripped/include/dnet_winconfig.h new file mode 100644 index 000000000..a10bb2395 --- /dev/null +++ b/libdnet-stripped/include/dnet_winconfig.h @@ -0,0 +1,278 @@ +/* include/dnet_winconfig.h -- Windows configuration #defines. It is modified + from the config.h generated by configure on other platforms. */ + +/* Define if arpreq struct has arp_dev. */ +#define HAVE_ARPREQ_ARP_DEV 1 + +/* Define if you have the Berkeley Packet Filter. */ +/* #undef HAVE_BSD_BPF */ + +/* Define if you have the header file. */ +#define HAVE_DLFCN_H 1 + +/* Define if you have the `err' function. */ +#define HAVE_ERR 1 + +/* Define if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_HPSECURITY_H */ + +/* Define if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define if you have arp(7) ioctls. */ +#define HAVE_IOCTL_ARP 1 + +/* Define if you have the header file. */ +/* #undef HAVE_IPHLPAPI_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_IP_COMPAT_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_IP_FIL_COMPAT_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_IP_FIL_H */ + +/* Define if you have the `iphlpapi' library (-liphlpapi). */ +/* #undef HAVE_LIBIPHLPAPI */ + +/* Define if you have the `nm' library (-lnm). */ +/* #undef HAVE_LIBNM */ + +/* Define if you have the `nsl' library (-lnsl). */ +/* #undef HAVE_LIBNSL */ + +/* Define if you have the `resolv' library (-lresolv). */ +/* #undef HAVE_LIBRESOLV */ + +/* Define if you have the `socket' library (-lsocket). */ +/* #undef HAVE_LIBSOCKET */ + +/* Define if you have the `str' library (-lstr). */ +/* #undef HAVE_LIBSTR */ + +/* Define if you have the `ws2_32' library (-lws2_32). */ +/* #undef HAVE_LIBWS2_32 */ + +/* Define if you have the header file. */ +#define HAVE_LINUX_IF_TUN_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_LINUX_IP_FWCHAINS_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_LINUX_IP_FW_H */ + +/* Define if you have the header file. + */ +#define HAVE_LINUX_NETFILTER_IPV4_IPCHAINS_CORE_H 1 + +/* Define if you have Linux PF_PACKET sockets. */ +#define HAVE_LINUX_PF_PACKET 1 + +/* Define if you have the Linux /proc filesystem. */ +#define HAVE_LINUX_PROCFS 1 + +/* Define if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_NETINET_IN_VAR_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NETINET_IP_COMPAT_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NETINET_IP_FIL_COMPAT_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NETINET_IP_FIL_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NETINET_IP_FW_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NET_BPF_H */ + +/* Define if you have the header file. */ +#define HAVE_NET_IF_ARP_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_NET_IF_DL_H */ + +/* Define if you have the header file. */ +// #define HAVE_NET_IF_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_NET_IF_TUN_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NET_IF_VAR_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NET_PFILT_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NET_PFVAR_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NET_RADIX_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_NET_RAW_H */ + +/* Define if you have the header file. */ +#define HAVE_NET_ROUTE_H 1 + +/* Define if you have cooked raw IP sockets. */ +/* #undef HAVE_RAWIP_COOKED */ + +/* Define if raw IP sockets require host byte ordering for ip_off, ip_len. */ +/* #undef HAVE_RAWIP_HOST_OFFLEN */ + +/* Define if has rt_msghdr struct. */ +/* #undef HAVE_ROUTE_RT_MSGHDR */ + +/* Define if has sockaddr_in6 struct. */ +// #define HAVE_SOCKADDR_IN6 1 + +/* Define if sockaddr struct has sa_len. */ +/* #undef HAVE_SOCKADDR_SA_LEN */ + +/* Define if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define if you have SNMP MIB2 STREAMS. */ +/* #undef HAVE_STREAMS_MIB2 */ + +/* Define if you have route(7) STREAMS. */ +/* #undef HAVE_STREAMS_ROUTE */ + +/* Define if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define if you have the `strlcat' function. */ +/* #undef HAVE_STRLCAT */ + +/* Define if you have the `strlcpy' function. */ +/* #undef HAVE_STRLCPY */ + +/* Define if you have the header file. */ +#define HAVE_STROPTS_H 1 + +/* Define if you have the `strsep' function. */ +#define HAVE_STRSEP 1 + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_BUFMOD_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_DLPIHDR_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_DLPI_EXT_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_DLPI_H */ + +/* Define if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_MIB_H */ + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_NDD_VAR_H */ + +/* Define if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_SYS_SOCKIO_H */ + +/* Define if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define if you have the header file. */ +#define HAVE_SYS_SYSCTL_H 1 + +/* Define if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define if you have the header file. */ +/* #undef HAVE_WINSOCK2_H */ + +/* Name of package */ +#define PACKAGE "libdnet" + +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.10" + +/* Define for faster code generation. */ +/* #undef WIN32_LEAN_AND_MEAN */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define as `__inline' if that's what the C compiler calls it, or to nothing + if it is not supported. */ +/* #undef inline */ + +/* Define to `int' if does not define. */ +/* #undef pid_t */ + +/* Define to `unsigned' if does not define. */ +/* #undef size_t */ + +/* Use MingW32's internal snprintf */ +/* #undef snprintf */ + +#include + +#ifdef HAVE_WINSOCK2_H +# include +# include +#endif + +#ifdef __svr4__ +# define BSD_COMP 1 +#endif + +#if defined(__osf__) && !defined(_SOCKADDR_LEN) +# define _SOCKADDR_LEN 1 +#endif + +#ifndef HAVE_INET_PTON +int inet_pton(int, const char *, void *); +#endif + +#ifndef HAVE_STRLCAT +int strlcat(char *, const char *, int); +#endif + +#ifndef HAVE_STRLCPY +int strlcpy(char *, const char *, int); +#endif + +#ifndef HAVE_STRSEP +char *strsep(char **, const char *); +#endif diff --git a/libdnet-stripped/libdnet-stripped.vcproj b/libdnet-stripped/libdnet-stripped.vcproj new file mode 100755 index 000000000..310e4cb21 --- /dev/null +++ b/libdnet-stripped/libdnet-stripped.vcproj @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libdnet-stripped/src/addr-util.c b/libdnet-stripped/src/addr-util.c index eb4dd5d12..c0ebb3128 100644 --- a/libdnet-stripped/src/addr-util.c +++ b/libdnet-stripped/src/addr-util.c @@ -6,7 +6,11 @@ * $Id: addr-util.c,v 1.4 2005/01/23 07:36:54 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif #include #include diff --git a/libdnet-stripped/src/addr.c b/libdnet-stripped/src/addr.c index 1e58abe78..0824061c0 100644 --- a/libdnet-stripped/src/addr.c +++ b/libdnet-stripped/src/addr.c @@ -8,7 +8,11 @@ * $Id: addr.c,v 1.33 2005/01/23 07:36:54 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif #include #ifdef HAVE_NET_IF_H diff --git a/libdnet-stripped/src/arp-win32.c b/libdnet-stripped/src/arp-win32.c index 104645814..5acaf480e 100644 --- a/libdnet-stripped/src/arp-win32.c +++ b/libdnet-stripped/src/arp-win32.c @@ -6,8 +6,13 @@ * $Id: arp-win32.c,v 1.12 2005/01/23 07:36:54 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif +#include #include #include diff --git a/libdnet-stripped/src/blob.c b/libdnet-stripped/src/blob.c index effc0018b..9817f8c5f 100644 --- a/libdnet-stripped/src/blob.c +++ b/libdnet-stripped/src/blob.c @@ -6,7 +6,11 @@ * $Id: blob.c,v 1.4 2002/08/20 05:18:49 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif #include #include diff --git a/libdnet-stripped/src/eth-win32.c b/libdnet-stripped/src/eth-win32.c index c13830250..b5410f2ba 100644 --- a/libdnet-stripped/src/eth-win32.c +++ b/libdnet-stripped/src/eth-win32.c @@ -6,12 +6,16 @@ * $Id: eth-win32.c,v 1.11 2005/02/15 06:37:06 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif -/* XXX - VC++ 6.0 bogosity */ -#define sockaddr_storage sockaddr +/* XXX - VC++ 6.0 bogosity +#define sockaddr_storage sockaddr */ #include -#undef sockaddr_storage +/* #undef sockaddr_storage */ #include #include @@ -40,7 +44,7 @@ eth_open(const char *device) WCHAR *name, wbuf[2048]; ULONG wlen; char *desc, *namea; - int i, j, alen; + int i, j, alen, rc; OSVERSIONINFO osvi; intf_t *intf; @@ -56,13 +60,15 @@ eth_open(const char *device) alen = sizeof(alist) / sizeof(alist[0]); wlen = sizeof(wbuf) / sizeof(wbuf[0]); - PacketGetAdapterNames((char *)wbuf, &wlen); + rc = PacketGetAdapterNames((char *)wbuf, &wlen); + if (rc == 0) return (NULL); /* Determine Windows version */ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); - if ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) && + /* Added the 0 below for testing -- may need to find new expression */ + if (0 && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osvi.dwMajorVersion >= 4)) { for (name = wbuf, i = 0; *name != '\0' && i < alen; i++) { wcstombs(alist[i].name, name, sizeof(alist[0].name)); @@ -113,9 +119,9 @@ eth_open(const char *device) ssize_t eth_send(eth_t *eth, const void *buf, size_t len) { - PacketInitPacket(eth->pkt, (void *)buf, len); + PacketInitPacket(eth->pkt, (void *)buf, (UINT) len); PacketSendPacket(eth->lpa, eth->pkt, TRUE); - return (len); + return ((ssize_t) len); } eth_t * diff --git a/libdnet-stripped/src/intf-win32.c b/libdnet-stripped/src/intf-win32.c index 977dac83b..5cd23cc18 100644 --- a/libdnet-stripped/src/intf-win32.c +++ b/libdnet-stripped/src/intf-win32.c @@ -6,17 +6,23 @@ * $Id: intf-win32.c,v 1.24 2005/02/15 06:37:06 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif +#include +#include #include +#include #include #include #include #include #include -#include "dnet.h" struct ifcombo { DWORD *idx; @@ -150,7 +156,7 @@ _ifrow_to_entry(intf_t *intf, MIB_IFROW *ifrow, struct intf_entry *entry) } } } - entry->intf_len = (u_char *)ap - (u_char *)entry; + entry->intf_len = (unsigned int) ((u_char *)ap - (u_char *)entry); } static int diff --git a/libdnet-stripped/src/intf.c b/libdnet-stripped/src/intf.c index faa416760..88f64c544 100644 --- a/libdnet-stripped/src/intf.c +++ b/libdnet-stripped/src/intf.c @@ -6,7 +6,11 @@ * $Id: intf.c,v 1.55 2005/02/10 16:57:35 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif #include #include diff --git a/libdnet-stripped/src/ip-cooked.c b/libdnet-stripped/src/ip-cooked.c index 5a3ac9730..af6060189 100644 --- a/libdnet-stripped/src/ip-cooked.c +++ b/libdnet-stripped/src/ip-cooked.c @@ -6,7 +6,11 @@ * $Id: ip-cooked.c,v 1.17 2005/01/25 21:30:40 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif #ifndef _WIN32 #include diff --git a/libdnet-stripped/src/ip-util.c b/libdnet-stripped/src/ip-util.c index 9ca9998b6..b776fd36c 100644 --- a/libdnet-stripped/src/ip-util.c +++ b/libdnet-stripped/src/ip-util.c @@ -6,7 +6,11 @@ * $Id: ip-util.c,v 1.9 2005/02/17 02:55:56 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif #include #include @@ -36,10 +40,10 @@ ip_add_option(void *buf, size_t len, int proto, hl = tcp->th_off << 2; p = (u_char *)tcp + hl; } - datalen = ntohs(ip->ip_len) - (p - (u_char *)buf); + datalen = ntohs(ip->ip_len) - (int) (p - (u_char *)buf); /* Compute padding to next word boundary. */ - if ((padlen = 4 - (optlen % 4)) == 4) + if ((padlen = (int) (4 - (optlen % 4))) == 4) padlen = 0; /* XXX - IP_HDR_LEN_MAX == TCP_HDR_LEN_MAX */ @@ -66,13 +70,13 @@ ip_add_option(void *buf, size_t len, int proto, optlen += padlen; if (proto == IP_PROTO_IP) - ip->ip_hl = (p - (u_char *)ip) >> 2; + ip->ip_hl = (uint8_t) (p - (u_char *)ip) >> 2; else if (proto == IP_PROTO_TCP) - tcp->th_off = (p - (u_char *)tcp) >> 2; + tcp->th_off = (uint8_t) (p - (u_char *)tcp) >> 2; - ip->ip_len = htons(ntohs(ip->ip_len) + optlen); + ip->ip_len = htons(ntohs(ip->ip_len) + (unsigned short) optlen); - return (optlen); + return ((ssize_t) optlen); } void @@ -103,7 +107,7 @@ ip_checksum(void *buf, size_t len) if (len >= TCP_HDR_LEN) { tcp->th_sum = 0; sum = ip_cksum_add(tcp, len, 0) + - htons(ip->ip_p + len); + htons(ip->ip_p + (unsigned short) len); sum = ip_cksum_add(&ip->ip_src, 8, sum); tcp->th_sum = ip_cksum_carry(sum); } @@ -113,7 +117,7 @@ ip_checksum(void *buf, size_t len) if (len >= UDP_HDR_LEN) { udp->uh_sum = 0; sum = ip_cksum_add(udp, len, 0) + - htons(ip->ip_p + len); + htons(ip->ip_p + (unsigned short) len); sum = ip_cksum_add(&ip->ip_src, 8, sum); udp->uh_sum = ip_cksum_carry(sum); if (!udp->uh_sum) @@ -136,7 +140,7 @@ ip_cksum_add(const void *buf, size_t len, int cksum) uint16_t *sp = (uint16_t *)buf; int n, sn; - sn = len / 2; + sn = (int) len / 2; n = (sn + 15) / 16; /* XXX - unroll loop using Duff's device. */ diff --git a/libdnet-stripped/src/ip-win32.c b/libdnet-stripped/src/ip-win32.c index d5a07dbb6..ee484bb64 100644 --- a/libdnet-stripped/src/ip-win32.c +++ b/libdnet-stripped/src/ip-win32.c @@ -8,6 +8,7 @@ #include "config.h" +#include #include #include @@ -55,9 +56,9 @@ ip_send(ip_t *ip, const void *buf, size_t len) ip->sin.sin_addr.s_addr = hdr->ip_src; - if ((len = sendto(ip->fd, (const char *)buf, len, 0, + if ((len = sendto(ip->fd, (const char *)buf, (int) len, 0, (struct sockaddr *)&ip->sin, sizeof(ip->sin))) != SOCKET_ERROR) - return (len); + return ((ssize_t) len); return (-1); } diff --git a/libdnet-stripped/src/ip6.c b/libdnet-stripped/src/ip6.c index ff8ded712..ce48e9179 100644 --- a/libdnet-stripped/src/ip6.c +++ b/libdnet-stripped/src/ip6.c @@ -6,7 +6,11 @@ * $Id: ip6.c,v 1.2 2005/01/23 07:36:54 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif #include "dnet.h" @@ -37,7 +41,7 @@ ip6_checksum(void *buf, size_t len) if (len >= TCP_HDR_LEN) { tcp->th_sum = 0; - sum = ip_cksum_add(tcp, len, 0) + htons(nxt + len); + sum = ip_cksum_add(tcp, len, 0) + htons(nxt + (unsigned short) len); sum = ip_cksum_add(&ip6->ip6_src, 32, sum); tcp->th_sum = ip_cksum_carry(sum); } @@ -46,7 +50,7 @@ ip6_checksum(void *buf, size_t len) if (len >= UDP_HDR_LEN) { udp->uh_sum = 0; - sum = ip_cksum_add(udp, len, 0) + htons(nxt + len); + sum = ip_cksum_add(udp, len, 0) + htons(nxt + (unsigned short) len); sum = ip_cksum_add(&ip6->ip6_src, 32, sum); if ((udp->uh_sum = ip_cksum_carry(sum)) == 0) udp->uh_sum = 0xffff; @@ -56,7 +60,7 @@ ip6_checksum(void *buf, size_t len) if (len >= ICMP_HDR_LEN) { icmp->icmp_cksum = 0; - sum = ip_cksum_add(icmp, len, 0) + htons(nxt + len); + sum = ip_cksum_add(icmp, len, 0) + htons(nxt + (unsigned short) len); sum = ip_cksum_add(&ip6->ip6_src, 32, sum); icmp->icmp_cksum = ip_cksum_carry(sum); } diff --git a/libdnet-stripped/src/route-win32.c b/libdnet-stripped/src/route-win32.c index 6d9fb583a..441127140 100644 --- a/libdnet-stripped/src/route-win32.c +++ b/libdnet-stripped/src/route-win32.c @@ -6,8 +6,14 @@ * $Id: route-win32.c,v 1.12 2005/02/15 07:11:32 dugsong Exp $ */ +#ifdef _WIN32 +#include "dnet_winconfig.h" +#else #include "config.h" +#endif +#include +#include #include #include diff --git a/mswin32/IPExport.h b/mswin32/IPExport.h index c1ce4fee0..59d5729ee 100644 --- a/mswin32/IPExport.h +++ b/mswin32/IPExport.h @@ -186,6 +186,7 @@ typedef struct _IP_ADAPTER_ORDER_MAP // of the ip_option_information structure. See RFC 791 for a complete // description of each. // +/* THESE ARE DEFINED IN DNET -- SO EXCLUDED #define IP_OPT_EOL 0 // End of list option #define IP_OPT_NOP 1 // No operation #define IP_OPT_SECURITY 0x82 // Security option @@ -195,6 +196,7 @@ typedef struct _IP_ADAPTER_ORDER_MAP #define IP_OPT_TS 0x44 // Timestamp #define IP_OPT_SID 0x88 // Stream ID (obsolete) #define IP_OPT_ROUTER_ALERT 0x94 // Router Alert Option +*/ #define MAX_OPT_SIZE 40 // Maximum length of IP options in bytes diff --git a/mswin32/IPTypes.h b/mswin32/IPTypes.h deleted file mode 100644 index f248d58de..000000000 --- a/mswin32/IPTypes.h +++ /dev/null @@ -1,124 +0,0 @@ -/*++ - -Copyright (c) 1995-1999 Microsoft Corporation - -Module Name: - - iptypes.h - -*/ - -#ifndef IP_TYPES_INCLUDED -#define IP_TYPES_INCLUDED - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include - -// Definitions and structures used by getnetworkparams and getadaptersinfo apis - -#define MAX_ADAPTER_DESCRIPTION_LENGTH 128 // arb. -#define MAX_ADAPTER_NAME_LENGTH 256 // arb. -#define MAX_ADAPTER_ADDRESS_LENGTH 8 // arb. -#define DEFAULT_MINIMUM_ENTITIES 32 // arb. -#define MAX_HOSTNAME_LEN 128 // arb. -#define MAX_DOMAIN_NAME_LEN 128 // arb. -#define MAX_SCOPE_ID_LEN 256 // arb. - -// -// types -// - -// Node Type - -#define BROADCAST_NODETYPE 1 -#define PEER_TO_PEER_NODETYPE 2 -#define MIXED_NODETYPE 4 -#define HYBRID_NODETYPE 8 - -// Adapter Type - -#define IF_OTHER_ADAPTERTYPE 0 -#define IF_ETHERNET_ADAPTERTYPE 1 -#define IF_TOKEN_RING_ADAPTERTYPE 2 -#define IF_FDDI_ADAPTERTYPE 3 -#define IF_PPP_ADAPTERTYPE 4 -#define IF_LOOPBACK_ADAPTERTYPE 5 -#define IF_SLIP_ADAPTERTYPE 6 - -// -// IP_ADDRESS_STRING - store an IP address as a dotted decimal string -// - -typedef struct { - char String[4 * 4]; -} IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING; - -// -// IP_ADDR_STRING - store an IP address with its corresponding subnet mask, -// both as dotted decimal strings -// - -typedef struct _IP_ADDR_STRING { - struct _IP_ADDR_STRING* Next; - IP_ADDRESS_STRING IpAddress; - IP_MASK_STRING IpMask; - DWORD Context; -} IP_ADDR_STRING, *PIP_ADDR_STRING; - -// -// ADAPTER_INFO - per-adapter information. All IP addresses are stored as -// strings -// - -typedef struct _IP_ADAPTER_INFO { - struct _IP_ADAPTER_INFO* Next; - DWORD ComboIndex; - char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4]; - char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]; - UINT AddressLength; - BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]; - DWORD Index; - UINT Type; - UINT DhcpEnabled; - PIP_ADDR_STRING CurrentIpAddress; - IP_ADDR_STRING IpAddressList; - IP_ADDR_STRING GatewayList; - IP_ADDR_STRING DhcpServer; - BOOL HaveWins; - IP_ADDR_STRING PrimaryWinsServer; - IP_ADDR_STRING SecondaryWinsServer; - time_t LeaseObtained; - time_t LeaseExpires; -} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO; - -// -// IP_PER_ADAPTER_INFO - per-adapter IP information such as DNS server list. -// - -typedef struct _IP_PER_ADAPTER_INFO { - UINT AutoconfigEnabled; - UINT AutoconfigActive; - PIP_ADDR_STRING CurrentDnsServer; - IP_ADDR_STRING DnsServerList; -} IP_PER_ADAPTER_INFO, *PIP_PER_ADAPTER_INFO; - -// -// FIXED_INFO - the set of IP-related information which does not depend on DHCP -// - -typedef struct { - char HostName[MAX_HOSTNAME_LEN + 4] ; - char DomainName[MAX_DOMAIN_NAME_LEN + 4]; - PIP_ADDR_STRING CurrentDnsServer; - IP_ADDR_STRING DnsServerList; - UINT NodeType; - char ScopeId[MAX_SCOPE_ID_LEN + 4]; - UINT EnableRouting; - UINT EnableProxy; - UINT EnableDns; -} FIXED_INFO, *PFIXED_INFO; - -#endif diff --git a/mswin32/NETINET/IP.H b/mswin32/NETINET/IP.H index 2f6b76933..fc3721d56 100644 --- a/mswin32/NETINET/IP.H +++ b/mswin32/NETINET/IP.H @@ -145,10 +145,10 @@ struct ip_timestamp { ipt_flg:4; /* flags, see below */ #endif union ipt_timestamp { - n_long ipt_time[1]; + u_int32_t ipt_time[1]; struct ipt_ta { struct in_addr ipt_addr; - n_long ipt_time; + u_int32_t ipt_time; } ipt_ta[1]; } ipt_timestamp; }; diff --git a/mswin32/NETINET/IP_ICMP.H b/mswin32/NETINET/IP_ICMP.H index c3fdc4539..0e79a4530 100644 --- a/mswin32/NETINET/IP_ICMP.H +++ b/mswin32/NETINET/IP_ICMP.H @@ -49,15 +49,15 @@ struct icmp { u_char ih_pptr; /* ICMP_PARAMPROB */ struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ struct ih_idseq { - n_short icd_id; - n_short icd_seq; + u_short icd_id; + u_short icd_seq; } ih_idseq; int ih_void; /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ struct ih_pmtu { - n_short ipm_void; - n_short ipm_nextmtu; + u_short ipm_void; + u_short ipm_nextmtu; } ih_pmtu; } icmp_hun; #define icmp_pptr icmp_hun.ih_pptr @@ -69,9 +69,9 @@ struct icmp { #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu union { struct id_ts { - n_time its_otime; - n_time its_rtime; - n_time its_ttime; + u_int32_t its_otime; + u_int32_t its_rtime; + u_int32_t its_ttime; } id_ts; struct id_ip { struct ip idi_ip; diff --git a/mswin32/lib/Packet.lib b/mswin32/lib/Packet.lib index 253d81f07..12adc24af 100644 Binary files a/mswin32/lib/Packet.lib and b/mswin32/lib/Packet.lib differ diff --git a/mswin32/lib/Wpcap.lib b/mswin32/lib/Wpcap.lib index 934031c6d..4a9986ddb 100644 Binary files a/mswin32/lib/Wpcap.lib and b/mswin32/lib/Wpcap.lib differ diff --git a/mswin32/nmap.sln b/mswin32/nmap.sln index 1a330a53e..ee48910d9 100644 --- a/mswin32/nmap.sln +++ b/mswin32/nmap.sln @@ -7,6 +7,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nmap", "nmap.vcproj", "{361 ProjectSection(ProjectDependencies) = postProject {CB578003-213B-4316-B5BC-2D71A081A65A} = {CB578003-213B-4316-B5BC-2D71A081A65A} {5DE86C7A-DE72-4265-8807-4CA38F94F22A} = {5DE86C7A-DE72-4265-8807-4CA38F94F22A} + {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C} = {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C} {F8D6D1E3-D4EA-402C-98AA-168E5309BAF4} = {F8D6D1E3-D4EA-402C-98AA-168E5309BAF4} {B630C8F7-3138-43E8-89ED-78742FA2AC5F} = {B630C8F7-3138-43E8-89ED-78742FA2AC5F} EndProjectSection @@ -24,6 +25,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nbase", "..\nbase\nbase.vcp ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dnet", "..\libdnet-stripped\libdnet-stripped.vcproj", "{5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -50,6 +55,10 @@ Global {B630C8F7-3138-43E8-89ED-78742FA2AC5F}.Debug.Build.0 = Debug|Win32 {B630C8F7-3138-43E8-89ED-78742FA2AC5F}.Release.ActiveCfg = Release|Win32 {B630C8F7-3138-43E8-89ED-78742FA2AC5F}.Release.Build.0 = Release|Win32 + {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C}.Debug.ActiveCfg = Debug|Win32 + {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C}.Debug.Build.0 = Debug|Win32 + {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C}.Release.ActiveCfg = Release|Win32 + {5328E0BE-BC0A-4C2A-8CB9-CE00B61B9C4C}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/mswin32/nmap.vcproj b/mswin32/nmap.vcproj index 899564aa2..251f81908 100644 --- a/mswin32/nmap.vcproj +++ b/mswin32/nmap.vcproj @@ -22,7 +22,7 @@ - - - - - - - - - - - - - - + RelativePath=".\winip\winip.cc"> diff --git a/mswin32/packet_types.h b/mswin32/packet_types.h index 89517d2de..ff7db82c8 100644 --- a/mswin32/packet_types.h +++ b/mswin32/packet_types.h @@ -5,7 +5,6 @@ typedef long n_long; -typedef short n_short; typedef long n_time; diff --git a/mswin32/winip/iphlpapi.h b/mswin32/winip/iphlpapi.h deleted file mode 100644 index ef5f24793..000000000 --- a/mswin32/winip/iphlpapi.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - -iphlpapi.h: declares the subset of iphlpapi needed to compile -Copyright (C) 2000 Andy Lutomirski - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License, version 2.1, as published by the Free Software -Foundation, with the exception that if this copy of the library -is distributed under the Lesser GNU Public License (as opposed -to the ordinary GPL), you may ignore section 6b, and that all -copies distributed without exercising section 3 must retain this -paragraph in its entirety. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - -#ifndef __IPHLPAPI_H__ -#ifndef __IPHLPAPI_FAKE_H__ -#define __IPHLPAPI_FAKE_H__ - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -DWORD __declspec(dllimport) __stdcall GetIfTable(PMIB_IFTABLE, DWORD*, BOOL); -DWORD __declspec(dllimport) __stdcall GetIpAddrTable(PMIB_IPADDRTABLE, DWORD*, BOOL); -DWORD __declspec(dllimport) __stdcall GetIpNetTable(PMIB_IPNETTABLE, DWORD*, BOOL); -DWORD __declspec(dllimport) __stdcall GetIpForwardTable(PMIB_IPFORWARDTABLE, DWORD*, BOOL); -DWORD __declspec(dllimport) __stdcall GetIfEntry(PMIB_IFROW); -DWORD __declspec(dllimport) __stdcall SendARP( int, int, PULONG, PULONG ); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/mswin32/winip/winip.c b/mswin32/winip/winip.cc similarity index 98% rename from mswin32/winip/winip.c rename to mswin32/winip/winip.cc index 17bc9a003..6895733c3 100644 --- a/mswin32/winip/winip.c +++ b/mswin32/winip/winip.cc @@ -659,9 +659,11 @@ typedef DWORD (__stdcall *PGBI)(IPAddr, PDWORD); int win32_sendto(int sd, const char *packet, int len, unsigned int flags, struct sockaddr *to, int tolen) { + /* COMMENTED OUT SINCE pcapsend* is obsolete -- need to use new Nmap infrastructure if(sd == 501) return pcapsendraw(packet, len, to, tolen); - else return sendto(sd, packet, len, flags, to, tolen); + else */ + return sendto(sd, packet, len, flags, to, tolen); } int Sendto(char *functionname, int sd, const unsigned char *packet, int len, @@ -679,7 +681,9 @@ int win32_socket(int af, int type, int proto) if(type == SOCK_RAW && proto == IPPROTO_RAW) { winip_test(1); - pcapsend_init(); + /* no longer using this pcapsend stuff + pcapsend_init(); + */ return 501; } diff --git a/mswin32/winip/winip.h b/mswin32/winip/winip.h index 1220319eb..acefbb6fa 100644 --- a/mswin32/winip/winip.h +++ b/mswin32/winip/winip.h @@ -64,8 +64,13 @@ frame-relay(32) */ -#include +#include +#include +#include +#include + +/* #define IF_other 1 #define IF_regular1822 2 #define IF_hdh1822 3 @@ -98,8 +103,7 @@ frame-relay(32) #define IF_ds3 30 #define IF_sip 31 #define IF_frame_relay 32 - -#include +*/ #ifndef EXTERNC # ifdef __cplusplus @@ -109,16 +113,15 @@ frame-relay(32) # endif #endif - -// change to if you have the SDK -#include "iphlpapi.h" - // windows-specific options + +#include struct winops { int norawsock, nopcap, forcerawsock, listinterfaces, nt4route, noiphlpapi, trace; }; -EXTERNC struct winops wo; +/* struct winops wo; + */ /* Sets a pcap filter function -- makes SOCK_RAW reads easier */ typedef int (*PFILTERFN)(const char *packet, unsigned int len); /* 1 to keep */ @@ -172,9 +175,9 @@ EXTERNC int get_best_route(DWORD dest, PMIB_IPFORWARDROW r); // pcapsend interface -EXTERNC void pcapsend_init(); +void pcapsend_init(); EXTERNC pcap_t *my_real_pcap_open_live(const char *device, int snaplen, int promisc, int to_ms); -EXTERNC int pcapsendraw(const char *packet, int len, +int pcapsendraw(const char *packet, int len, struct sockaddr *to, int tolen); // rawrecv interface diff --git a/nmap-os-fingerprints b/nmap-os-fingerprints index 8310039d5..fb5d41ddb 100644 --- a/nmap-os-fingerprints +++ b/nmap-os-fingerprints @@ -425,7 +425,7 @@ PU(DF=N%TOS=0%IPLEN=38%RIPTL=148%RID=E%RIPCK=F%UCK=E%ULEN=134%DAT=E) # Aethra Vega Star Gold (Videoconferencing appliance) # Aethra Video Conference System Vega Pro S running pSOSystem Fingerprint Aethra Vega Conference System -Class Aethra | embedded || webcom +Class Aethra | embedded || webcam TSeq(Class=RI%gcd=<6%SI=<2F97016&>79D33%IPID=I%TS=U) T1(DF=N%W=7FFF%ACK=S++%Flags=AS%Ops=ME) T2(Resp=N) @@ -1888,7 +1888,7 @@ PU(Resp=N) # Audio Codes MP-104 - VoIP Gateway FXO (version 4.0.282.350) Fingerprint AudioCodes MP-104 VoIP Gateway FXO -Class AudioCodes | embedded || VOIP Gateway +Class AudioCodes | embedded || VoIP gateway TSeq(Class=TD%gcd=<3D094%SI=<1E%IPID=I%TS=1000HZ) T1(DF=N%W=20F4%ACK=S++%Flags=AS%Ops=MNWNNT) T2(Resp=N) @@ -1901,7 +1901,7 @@ PU(Resp=N) # AudioCodes MP-108 FXS (iptele gateway) version: 4.40.162.274 Fingerprint AudioCodes MP-108 VoIP Gateway FXS -Class AudioCodes | embedded || VOIP Gateway +Class AudioCodes | embedded || VoIP gateway TSeq(Class=TD%gcd=<3D094%SI=<1E%IPID=I%TS=1000HZ) T1(DF=N%W=209D%ACK=S++%Flags=AS%Ops=MENWNNT) T2(Resp=N) @@ -3567,7 +3567,7 @@ PU(DF=N%TOS=0%IPLEN=38%RIPTL=148%RID=E%RIPCK=E%UCK=E%ULEN=134%DAT=E) # telephone to be used as a voice-over-IP phone. There is a # variation, the ATA 188 that has a pass-through port, much like the # Cisco 7960 phone. -Fingerprint Cisco ATA 186 POTS<->VOIP phone gateway device +Fingerprint Cisco ATA 186 POTS<->VoIP phone gateway device Class Cisco | embedded || VoIP adapter TSeq(Class=TD%gcd=VOIP gateway +Fingerprint Sipura SPA-841/1000/2000/3000 POTS<->VoIP gateway Class Sipura | embedded || VoIP adapter TSeq(Class=TR%gcd=<6%IPID=I%TS=U) T1(DF=N%W=3E80%ACK=S++%Flags=AS%Ops=M) @@ -20907,7 +20907,7 @@ PU(DF=N%TOS=0%IPLEN=70%RIPTL=148%RID=E%RIPCK=E%UCK=E%ULEN=134%DAT=E) # Signal Network Technology Co, Ltd, VoIP appliance model sp100x running firmware version SP100X3.0.1 Fingerprint CPV Telsey broadband + voip residential gateway or Signal SP100x VoIP appliance Class Telsey | embedded || broadband router -Class Signal | embedded || VoIP Gateway +Class Signal | embedded || VoIP gateway TSeq(Class=TD%gcd=<138C%SI=<1E%IPID=I%TS=U) T1(DF=N%W=578%ACK=S++%Flags=AS%Ops=M) T2(Resp=N) diff --git a/nmap-services b/nmap-services index 153d469ab..3fc032ed5 100644 --- a/nmap-services +++ b/nmap-services @@ -1981,6 +1981,7 @@ pcanywheredata 5631/tcp # pcanywherestat 5632/tcp # pcanywherestat 5632/udp # canna 5680/tcp # Canna (Japanese Input) +activesync 5679/tcp # Microsoft ActiveSync PDY synchronization proshareaudio 5713/tcp # proshare conf audio proshareaudio 5713/udp # proshare conf audio prosharevideo 5714/tcp # proshare conf video diff --git a/nmap_winconfig.h b/nmap_winconfig.h index ada64aeaf..34c8dc581 100644 --- a/nmap_winconfig.h +++ b/nmap_winconfig.h @@ -104,7 +104,7 @@ #ifndef NMAP_WINCONFIG_H #define NMAP_WINCONFIG_H -#define NMAP_VERSION "3.82" +#define NMAP_VERSION "3.83.DC14" #define NMAP_NAME "nmap" #define NMAP_URL "http://www.insecure.org/nmap" #define NMAP_PLATFORM "i686-pc-windows-windows" diff --git a/output.cc b/output.cc index 23459e49b..463d9e71c 100644 --- a/output.cc +++ b/output.cc @@ -502,7 +502,7 @@ log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "%d service%s unrecognized despite ret log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "%s\n", saved_servicefps[i]); } } - + log_flush_all(); } char* xml_convert (const char* str) { @@ -737,6 +737,7 @@ void output_ports_to_machine_parseable_output(struct scan_lists *ports, if (protsscanned) output_rangelist_given_ports(LOG_MACHINE, ports->prots, protsscanned); log_write(LOG_MACHINE, ")\n"); + log_flush_all(); } /* Simple helper function for output_xml_scaninfo_records */ @@ -773,6 +774,7 @@ void output_xml_scaninfo_records(struct scan_lists *scanlist) { doscaninfo("udp", "udp", scanlist->udp_ports, scanlist->udp_count); if (o.ipprotscan) doscaninfo("ipproto", "ip", scanlist->prots, scanlist->prot_count); + log_flush_all(); } /* Helper function to write the status and address/hostname info of a host @@ -787,6 +789,7 @@ static void write_xml_initial_hostinfo(Target *currenths, } else /* If machine is up, put blank hostname so front ends know that no name resolution is forthcoming */ if (strcmp(status, "up") == 0) log_write(LOG_XML, "\n"); + log_flush_all(); } /* Writes host status info to the log streams (including STDOUT). An @@ -980,6 +983,7 @@ static void printosclassificationoutput(const struct OS_Classification_Results * log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "\n"); } } + log_flush_all(); return; } @@ -1189,6 +1193,7 @@ void printosscanoutput(Target *currenths) { log_write(LOG_XML, " />\n"); } } + log_flush_all(); } @@ -1288,7 +1293,7 @@ void printserviceinfooutput(Target *currenths) { } log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "\n"); - + log_flush_all(); } @@ -1324,7 +1329,7 @@ void printfinaloutput(int numhosts_scanned, int numhosts_up, log_write(LOG_NORMAL|LOG_MACHINE, "# Nmap run completed at %s -- %d %s (%d %s up) scanned in %.3f seconds\n", mytime, numhosts_scanned, (numhosts_scanned == 1)? "IP address" : "IP addresses", numhosts_up, (numhosts_up == 1)? "host" : "hosts", o.TimeSinceStartMS(&tv) / 1000.0 ); log_write(LOG_XML, "\n"); - + log_flush_all(); } diff --git a/portlist.cc b/portlist.cc index 361327a59..9e86f66f0 100644 --- a/portlist.cc +++ b/portlist.cc @@ -320,7 +320,7 @@ void Port::setServiceProbeResults(enum serviceprobestate sres, if (hostname) { slen = strlen(hostname); - if (slen > 128) slen = 128; + if (slen > 64) slen = 64; serviceprobe_hostname = (char *) safe_malloc(slen + 1); memcpy(serviceprobe_hostname, hostname, slen); serviceprobe_hostname[slen] = '\0'; diff --git a/scan_engine.cc b/scan_engine.cc index 2d4107ab5..7393b9010 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -105,6 +105,7 @@ #include "scan_engine.h" #include "timing.h" #include "NmapOps.h" +#include #include using namespace std; @@ -727,7 +728,7 @@ HostScanStats::HostScanStats(Target *t, UltraScanInfo *UltraSI) { num_probes_waiting_retransmit = 0; lastping_sent = lastprobe_sent = lastrcvd = USI->now; lastping_sent_numprobes = 0; - bzero(&pingprobe, sizeof(pingprobe)); + memset(&pingprobe, 0, sizeof(pingprobe)); pingprobestate = PORT_UNKNOWN; nxtpseq = 1; max_successful_tryno = 0; diff --git a/scripts/Makefile b/scripts/Makefile index 35f872bdf..3820f433a 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -146,8 +146,9 @@ distro: /usr/tmp/nmap-$(NMAP_VERSION)/libpcre $(SHTOOL) mkdir /usr/tmp/nmap-$(NMAP_VERSION)/libdnet-stripped - cd ../$(LIBDNETDIR); cp -ra NMAP_MODIFICATIONS acconfig.h aclocal.m4 \ - config configure configure.in dnet-config.in include INSTALL \ + cd ../$(LIBDNETDIR); cp -ra NMAP_MODIFICATIONS \ + libdnet-stripped.vcproj acconfig.h aclocal.m4 config \ + configure configure.in dnet-config.in include INSTALL \ libtool LICENSE Makefile Makefile.am Makefile.am.common \ Makefile.in README src THANKS TODO \ /usr/tmp/nmap-$(NMAP_VERSION)/libdnet-stripped diff --git a/tcpip.cc b/tcpip.cc index 9d1e58642..d58227f39 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -1716,7 +1716,7 @@ int read_arp_reply_pcap(pcap_t *pd, u8 *sendermac, struct in_addr *senderIP, do { #ifdef WIN32 gettimeofday(&tv_end, NULL); - to_left = MAX(1, (to_usec - TIMEVAL_SUBTRACT(tv_end, tv_start)) / 1000); + long to_left = MAX(1, (to_usec - TIMEVAL_SUBTRACT(tv_end, tv_start)) / 1000); // Set the timeout (BUGBUG: this is cheating) PacketSetReadTimeout(pd->adapter, to_left); #endif @@ -2106,28 +2106,146 @@ return -1; } #endif /* WIN32 */ -#ifndef WIN32 /* ifdef'd out for now because 'doze apparently doesn't - support ioctl() */ +struct dnet_collector_route_nfo { + struct sys_route *routes; + int numroutes; + int capacity; /* Capacity of routes or ifaces, depending on context */ + struct interface_info *ifaces; + int numifaces; +}; + +int collect_dnet_routes(const struct route_entry *entry, void *arg) { + struct dnet_collector_route_nfo *dcrn = (struct dnet_collector_route_nfo *) arg; + int i; + + /* Make sure that it is the proper type of route ... */ + if (entry->route_dst.addr_type != ADDR_TYPE_IP || entry->route_gw.addr_type != ADDR_TYPE_IP) + return 0; /* Not interested in IPv6 routes at the moment ... */ + + /* Make sure we have room for the new route */ + if (dcrn->numroutes >= dcrn->capacity) { + dcrn->capacity <<= 2; + dcrn->routes = (struct sys_route *) realloc(dcrn->routes, + dcrn->capacity * sizeof(struct sys_route)); + } + + /* Now for the important business */ + dcrn->routes[dcrn->numroutes].dest = entry->route_dst.addr_ip; + addr_btom(entry->route_dst.addr_bits, &dcrn->routes[dcrn->numroutes].netmask, sizeof(dcrn->routes[dcrn->numroutes].netmask)); + dcrn->routes[dcrn->numroutes].gw.s_addr = entry->route_gw.addr_ip; + /* Now determine which interface the route relates to */ + u32 mask; + struct sockaddr_in *sin; + for(i = 0; i < dcrn->numifaces; i++) { + sin = (struct sockaddr_in *) &dcrn->ifaces[i].addr; + mask = htonl((unsigned long) (0-1) << (32 - dcrn->ifaces[i].netmask_bits)); + if ((sin->sin_addr.s_addr & mask) == (entry->route_gw.addr_ip & mask)) { + dcrn->routes[dcrn->numroutes].device = &dcrn->ifaces[i]; + break; + } + } + if (i == dcrn->numifaces) { + error("WARNING: Unable to find appropriate interface for system route to %s\n", addr_ntoa(&entry->route_gw)); + return 0; + } + dcrn->numroutes++; + return 0; +} + +int collect_dnet_interfaces(const struct intf_entry *entry, void *arg) { + struct dnet_collector_route_nfo *dcrn = (struct dnet_collector_route_nfo *) arg; + int i; + int numifaces = dcrn->numifaces; + + /* Make sure we have room for the new route */ + if (dcrn->numifaces >= dcrn->capacity) { + dcrn->capacity <<= 2; + dcrn->ifaces = (struct interface_info *) realloc(dcrn->ifaces, + dcrn->capacity * sizeof(struct interface_info)); + } + if (entry->intf_addr.addr_type == ADDR_TYPE_IP) { + addr_ntos(&entry->intf_addr, (struct sockaddr *) &dcrn->ifaces[numifaces].addr); + dcrn->ifaces[numifaces].netmask_bits = entry->intf_addr.addr_bits; + } else { + for(i=0; i < (int) entry->intf_alias_num; i++) { + if (entry->intf_alias_addrs[i].addr_type == ADDR_TYPE_IP) { + addr_ntos(&entry->intf_alias_addrs[i], (struct sockaddr *) &dcrn->ifaces[numifaces].addr); + dcrn->ifaces[numifaces].netmask_bits = entry->intf_alias_addrs[i].addr_bits; + break; + } + if (i == (int) entry->intf_alias_num) + return 0; /* No IPv4 addresses found for this interface */ + } + } + + /* OK, address/netmask found. Let's get the name */ + Strncpy(dcrn->ifaces[numifaces].devname, entry->intf_name, sizeof(dcrn->ifaces[numifaces].devname)); + Strncpy(dcrn->ifaces[numifaces].devfullname, entry->intf_name, sizeof(dcrn->ifaces[numifaces].devfullname)); + + /* Interface type */ + if (entry->intf_type & INTF_TYPE_ETH) { + dcrn->ifaces[numifaces].device_type = devt_ethernet; + /* Collect the MAC address since this is ethernet */ + memcpy(dcrn->ifaces[numifaces].mac, &entry->intf_link_addr.addr_eth.data, 6); + } + else if (entry->intf_type & INTF_TYPE_LOOPBACK) + dcrn->ifaces[numifaces].device_type = devt_loopback; + else if (entry->intf_type & INTF_TYPE_TUN) + dcrn->ifaces[numifaces].device_type = devt_p2p; + else dcrn->ifaces[numifaces].device_type = devt_other; + + /* Is the interface up and running? */ + dcrn->ifaces[numifaces].device_up = (entry->intf_flags & INTF_FLAG_UP)? true : false; + + /* For the rest of the information, we must open the interface directly ... */ + dcrn->numifaces++; + return 0; +} + struct interface_info *getinterfaces(int *howmany) { static bool initialized = 0; static struct interface_info *mydevs; static int numifaces = 0; int ii_capacity = 0; - int sd, len, rc; - char *p; - u8 *buf; - int bufsz; +#if WIN32 +struct dnet_collector_route_nfo dcrn; +intf_t *it; +#else //!WIN32 +int sd; struct ifconf ifc; struct ifreq *ifr; struct ifreq tmpifr; +#endif + int len, rc; + char *p; + u8 *buf; + int bufsz; struct sockaddr_in *sin; u16 ifflags; + if (!initialized) { initialized = 1; ii_capacity = 16; mydevs = (struct interface_info *) safe_zalloc(sizeof(struct interface_info) * ii_capacity); +#if WIN32 +/* On Win32 we just use Dnet to determine the interface list */ + + dcrn.routes = NULL; + dcrn.numroutes = 0; + dcrn.capacity = ii_capacity; // I'm reusing this struct for ii now + dcrn.ifaces = mydevs; + dcrn.numifaces = 0; + it = intf_open(); + if (!it) fatal("%s: intf_open() failed", __FUNCTION__); + if (intf_loop(it, collect_dnet_interfaces, &dcrn) != 0) + fatal("%s: intf_loop() failed", __FUNCTION__); + intf_close(it); + mydevs = dcrn.ifaces; + numifaces = dcrn.numifaces; + ii_capacity = dcrn.capacity; +#else // !Win32 /* Dummy socket for ioctl */ sd = socket(AF_INET, SOCK_DGRAM, 0); if (sd < 0) pfatal("socket in getinterfaces"); @@ -2253,58 +2371,13 @@ struct interface_info *getinterfaces(int *howmany) { } free(buf); close(sd); +#endif //!WIN32 } if (howmany) *howmany = numifaces; return mydevs; } -#endif -struct dnet_collector_route_nfo { - struct sys_route *routes; - int numroutes; - int route_capacity; - struct interface_info *ifaces; - int numifaces; -}; - -int collect_dnet_routes(const struct route_entry *entry, void *arg) { - struct dnet_collector_route_nfo *dcrn = (struct dnet_collector_route_nfo *) arg; - int i; - - /* Make sure that it is the proper type of route ... */ - if (entry->route_dst.addr_type != ADDR_TYPE_IP || entry->route_gw.addr_type != ADDR_TYPE_IP) - return 0; /* Not interested in IPv6 routes at the moment ... */ - - /* Make sure we have room for the new route */ - if (dcrn->numroutes >= dcrn->route_capacity) { - dcrn->route_capacity <<= 2; - dcrn->routes = (struct sys_route *) realloc(dcrn->routes, - dcrn->route_capacity * sizeof(struct sys_route)); - } - - /* Now for the important business */ - dcrn->routes[dcrn->numroutes].dest = entry->route_dst.addr_ip; - addr_btom(entry->route_dst.addr_bits, &dcrn->routes[dcrn->numroutes].netmask, sizeof(dcrn->routes[dcrn->numroutes].netmask)); - dcrn->routes[dcrn->numroutes].gw.s_addr = entry->route_gw.addr_ip; - /* Now determine which interface the route relates to */ - u32 mask; - struct sockaddr_in *sin; - for(i = 0; i < dcrn->numifaces; i++) { - sin = (struct sockaddr_in *) &dcrn->ifaces[i].addr; - mask = htonl((unsigned long) (0-1) << (32 - dcrn->ifaces[i].netmask_bits)); - if ((sin->sin_addr.s_addr & mask) == (entry->route_gw.addr_ip & mask)) { - dcrn->routes[dcrn->numroutes].device = &dcrn->ifaces[i]; - break; - } - } - if (i == dcrn->numifaces) { - error("WARNING: Unable to find appropriate interface for system route to %s\n", addr_ntoa(&entry->route_gw)); - return 0; - } - dcrn->numroutes++; - return 0; -} /* A trivial function used with qsort to sort the routes by netmask */ static int nmaskcmp(const void *a, const void *b) { @@ -2429,7 +2502,7 @@ struct sys_route *getsysroutes(int *howmany) { struct dnet_collector_route_nfo dcrn; dcrn.routes = routes; dcrn.numroutes = numroutes; - dcrn.route_capacity = route_capacity; + dcrn.capacity = route_capacity; dcrn.ifaces = ifaces; dcrn.numifaces = numifaces; route_t *dr = route_open(); @@ -2439,7 +2512,7 @@ struct sys_route *getsysroutes(int *howmany) { } route_close(dr); /* These values could have changed in the callback */ - route_capacity = dcrn.route_capacity; + route_capacity = dcrn.capacity; numroutes = dcrn.numroutes; routes = dcrn.routes; } diff --git a/tcpip.h b/tcpip.h index d21101bc0..4e5751372 100644 --- a/tcpip.h +++ b/tcpip.h @@ -230,7 +230,9 @@ extern "C" { #include #include #include -#include +#ifndef WIN32 +#include +#endif typedef enum { devt_ethernet, devt_loopback, devt_p2p, devt_other } devtype; @@ -413,8 +415,6 @@ struct icmp u_int16_t icmp_cksum; /* ones complement checksum of struct */ union { - u_char ih_pptr; /* ICMP_PARAMPROB */ - struct in_addr ih_gwaddr; /* gateway address */ struct ih_idseq /* echo datagram */ { u_int16_t icd_id; @@ -436,8 +436,7 @@ struct icmp u_int16_t irt_lifetime; } ih_rtradv; } icmp_hun; -#define icmp_pptr icmp_hun.ih_pptr -#define icmp_gwaddr icmp_hun.ih_gwaddr + /* Removed icmp_pptr and icmp_gwaddr from union and #defines because they conflict with dnet */ #define icmp_id icmp_hun.ih_idseq.icd_id #define icmp_seq icmp_hun.ih_idseq.icd_seq #define icmp_void icmp_hun.ih_void