1 2 /*************************************************************************** 3 * nmap.h -- Currently handles some of Nmap's port scanning features as * 4 * well as the command line user interface. Note that the actual main() * 5 * function is in main.c * 6 * * 7 ***********************IMPORTANT NMAP LICENSE TERMS************************ 8 * * 9 * The Nmap Security Scanner is (C) 1996-2020 Insecure.Com LLC ("The Nmap * 10 * Project"). Nmap is also a registered trademark of the Nmap Project. * 11 * * 12 * This program is distributed under the terms of the Nmap Public Source * 13 * License (NPSL). The exact license text applying to a particular Nmap * 14 * release or source code control revision is contained in the LICENSE * 15 * file distributed with that version of Nmap or source code control * 16 * revision. More Nmap copyright/legal information is available from * 17 * https://nmap.org/book/man-legal.html, and further information on the * 18 * NPSL license itself can be found at https://nmap.org/npsl. This header * 19 * summarizes some key points from the Nmap license, but is no substitute * 20 * for the actual license text. * 21 * * 22 * Nmap is generally free for end users to download and use themselves, * 23 * including commercial use. It is available from https://nmap.org. * 24 * * 25 * The Nmap license generally prohibits companies from using and * 26 * redistributing Nmap in commercial products, but we sell a special Nmap * 27 * OEM Edition with a more permissive license and special features for * 28 * this purpose. See https://nmap.org/oem * 29 * * 30 * If you have received a written Nmap license agreement or contract * 31 * stating terms other than these (such as an Nmap OEM license), you may * 32 * choose to use and redistribute Nmap under those terms instead. * 33 * * 34 * The official Nmap Windows builds include the Npcap software * 35 * (https://npcap.org) for packet capture and transmission. It is under * 36 * separate license terms which forbid redistribution without special * 37 * permission. So the official Nmap Windows builds may not be * 38 * redistributed without special permission (such as an Nmap OEM * 39 * license). * 40 * * 41 * Source is provided to this software because we believe users have a * 42 * right to know exactly what a program is going to do before they run it. * 43 * This also allows you to audit the software for security holes. * 44 * * 45 * Source code also allows you to port Nmap to new platforms, fix bugs, * 46 * and add new features. You are highly encouraged to submit your * 47 * changes as a Github PR or by email to the dev@nmap.org mailing list * 48 * for possible incorporation into the main distribution. Unless you * 49 * specify otherwise, it is understood that you are offering us very * 50 * broad rights to use your submissions as described in the Nmap Public * 51 * Source License Contributor Agreement. This is important because we * 52 * fund the project by selling licenses with various terms, and also * 53 * because the inability to relicense code has caused devastating * 54 * problems for other Free Software projects (such as KDE and NASM). * 55 * * 56 * The free version of Nmap is distributed in the hope that it will be * 57 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * 58 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties, * 59 * indemnification and commercial support are all available through the * 60 * Npcap OEM program--see https://nmap.org/oem. * 61 * * 62 ***************************************************************************/ 63 64 /* $Id: nmap.h 38100 2020-10-09 22:33:04Z dmiller $ */ 65 66 #ifndef NMAP_H 67 #define NMAP_H 68 69 /************************INCLUDES**********************************/ 70 71 #ifdef HAVE_CONFIG_H 72 #include "nmap_config.h" 73 #else 74 #ifdef WIN32 75 #include "nmap_winconfig.h" 76 #endif /* WIN32 */ 77 #endif /* HAVE_CONFIG_H */ 78 79 #ifdef __amigaos__ 80 #include "nmap_amigaos.h" 81 #endif 82 83 #if HAVE_UNISTD_H 84 #include <unistd.h> 85 #endif 86 87 #ifdef HAVE_BSTRING_H 88 #include <bstring.h> 89 #endif 90 91 /* Keep assert() defined for security reasons */ 92 #undef NDEBUG 93 94 #include <assert.h> 95 96 /*#include <net/if_arp.h> *//* defines struct arphdr needed for if_ether.h */ 97 // #if HAVE_NET_IF_H 98 // #ifndef NET_IF_H /* why doesn't OpenBSD do this?! */ 99 // #include <net/if.h> 100 // #define NET_IF_H 101 // #endif 102 // #endif 103 // #if HAVE_NETINET_IF_ETHER_H 104 // #ifndef NETINET_IF_ETHER_H 105 // #include <netinet/if_ether.h> 106 // #define NETINET_IF_ETHER_H 107 // #endif /* NETINET_IF_ETHER_H */ 108 // #endif /* HAVE_NETINET_IF_ETHER_H */ 109 110 /******* DEFINES ************/ 111 112 #ifdef NMAP_OEM 113 #include "../nmap-build/nmap-oem.h" 114 #endif 115 116 #ifndef NMAP_NAME 117 #define NMAP_NAME "Nmap" 118 #endif 119 #define NMAP_URL "https://nmap.org" 120 121 #ifndef NMAP_VERSION 122 /* Edit this definition only within the quotes, because it is read from this 123 file by the makefiles. */ 124 #define NMAP_VERSION "7.91" 125 #define NMAP_NUM_VERSION "7.91.0.0" 126 #endif 127 128 #define NMAP_XMLOUTPUTVERSION "1.05" 129 130 /* User configurable #defines: */ 131 #define MAX_PROBE_PORTS 10 /* How many TCP probe ports are allowed ? */ 132 /* Default number of ports in parallel. Doesn't always involve actual 133 sockets. Can also adjust with the -M command line option. */ 134 #define MAX_SOCKETS 36 135 136 #define MAX_TIMEOUTS MAX_SOCKETS /* How many timed out connection attempts 137 in a row before we decide the host is 138 dead? */ 139 #define _STR(X) #X 140 #define STR(X) _STR(X) 141 #define DEFAULT_TCP_PROBE_PORT 80 /* The ports TCP ping probes go to if 142 unspecified by user -- uber hackers 143 change this to 113 */ 144 #define DEFAULT_TCP_PROBE_PORT_SPEC STR(DEFAULT_TCP_PROBE_PORT) 145 #define DEFAULT_UDP_PROBE_PORT 40125 /* The port UDP ping probes go to 146 if unspecified by user */ 147 #define DEFAULT_UDP_PROBE_PORT_SPEC STR(DEFAULT_UDP_PROBE_PORT) 148 #define DEFAULT_SCTP_PROBE_PORT 80 /* The port SCTP probes go to 149 if unspecified by 150 user */ 151 #define DEFAULT_SCTP_PROBE_PORT_SPEC STR(DEFAULT_SCTP_PROBE_PORT) 152 #define DEFAULT_PROTO_PROBE_PORT_SPEC "1,2,4" /* The IPProto ping probes to use 153 if unspecified by user */ 154 155 #define MAX_DECOYS 128 /* How many decoys are allowed? */ 156 157 /* TCP Options for TCP SYN probes: MSS 1460 */ 158 #define TCP_SYN_PROBE_OPTIONS "\x02\x04\x05\xb4" 159 #define TCP_SYN_PROBE_OPTIONS_LEN (sizeof(TCP_SYN_PROBE_OPTIONS)-1) 160 161 /* Default maximum send delay between probes to the same host */ 162 #ifndef MAX_TCP_SCAN_DELAY 163 #define MAX_TCP_SCAN_DELAY 1000 164 #endif 165 166 #ifndef MAX_UDP_SCAN_DELAY 167 #define MAX_UDP_SCAN_DELAY 1000 168 #endif 169 170 #ifndef MAX_SCTP_SCAN_DELAY 171 #define MAX_SCTP_SCAN_DELAY 1000 172 #endif 173 174 /* Maximum number of extra hostnames, OSs, and devices, we 175 consider when outputting the extra service info fields */ 176 #define MAX_SERVICE_INFO_FIELDS 5 177 178 /* We wait at least 100 ms for a response by default - while that 179 seems aggressive, waiting too long can cause us to fail to detect 180 drops until many probes later on extremely low-latency 181 networks (such as localhost scans). */ 182 #ifndef MIN_RTT_TIMEOUT 183 #define MIN_RTT_TIMEOUT 100 184 #endif 185 186 #ifndef MAX_RTT_TIMEOUT 187 #define MAX_RTT_TIMEOUT 10000 /* Never allow more than 10 secs for packet round 188 trip */ 189 #endif 190 191 #define INITIAL_RTT_TIMEOUT 1000 /* Allow 1 second initially for packet responses */ 192 #define INITIAL_ARP_RTT_TIMEOUT 200 /* The initial timeout for ARP is lower */ 193 194 #ifndef MAX_RETRANSMISSIONS 195 #define MAX_RETRANSMISSIONS 10 /* 11 probes to port at maximum */ 196 #endif 197 198 /* Number of hosts we pre-ping and then scan. We do a lot more if 199 randomize_hosts is set. Every one you add to this leads to ~1K of 200 extra always-resident memory in nmap */ 201 #define PING_GROUP_SZ 4096 202 203 /* DO NOT change stuff after this point */ 204 #define UC(b) (((int)b)&0xff) 205 #define SA struct sockaddr /*Ubertechnique from R. Stevens */ 206 207 #define HOST_UNKNOWN 0 208 #define HOST_UP 1 209 #define HOST_DOWN 2 210 211 #define PINGTYPE_UNKNOWN 0 212 #define PINGTYPE_NONE 1 213 #define PINGTYPE_ICMP_PING 2 214 #define PINGTYPE_ICMP_MASK 4 215 #define PINGTYPE_ICMP_TS 8 216 #define PINGTYPE_TCP 16 217 #define PINGTYPE_TCP_USE_ACK 32 218 #define PINGTYPE_TCP_USE_SYN 64 219 /* # define PINGTYPE_RAWTCP 128 used to be here, but was never used. */ 220 #define PINGTYPE_CONNECTTCP 256 221 #define PINGTYPE_UDP 512 222 /* #define PINGTYPE_ARP 1024 // Not used; see o.implicitARPPing */ 223 #define PINGTYPE_PROTO 2048 224 #define PINGTYPE_SCTP_INIT 4096 225 226 /* Empirically determined optimum combinations of different numbers of probes: 227 -PE 228 -PE -PA80 229 -PE -PA80 -PS443 230 -PE -PA80 -PS443 -PP 231 -PE -PA80 -PS443 -PP -PU40125 232 We use the four-probe combination. */ 233 #define DEFAULT_IPV4_PING_TYPES (PINGTYPE_ICMP_PING|PINGTYPE_TCP|PINGTYPE_TCP_USE_ACK|PINGTYPE_TCP_USE_SYN|PINGTYPE_ICMP_TS) 234 #define DEFAULT_IPV6_PING_TYPES (PINGTYPE_ICMP_PING|PINGTYPE_TCP|PINGTYPE_TCP_USE_ACK|PINGTYPE_TCP_USE_SYN) 235 #define DEFAULT_PING_ACK_PORT_SPEC "80" 236 #define DEFAULT_PING_SYN_PORT_SPEC "443" 237 /* For nonroot. */ 238 #define DEFAULT_PING_CONNECT_PORT_SPEC "80,443" 239 240 /* The max length of each line of the subject fingerprint when 241 wrapped. */ 242 #define FP_RESULT_WRAP_LINE_LEN 74 243 244 /* Length of longest DNS name */ 245 #define FQDN_LEN 254 246 247 /* Max payload: Worst case is IPv4 with 40bytes of options and TCP with 20 248 * bytes of options. */ 249 #define MAX_PAYLOAD_ALLOWED 65535-60-40 250 251 #ifndef recvfrom6_t 252 # define recvfrom6_t int 253 #endif 254 255 /***********************PROTOTYPES**********************************/ 256 257 /* Renamed main so that interactive mode could preprocess when necessary */ 258 int nmap_main(int argc, char *argv[]); 259 260 int nmap_fetchfile(char *filename_returned, int bufferlen, const char *file); 261 int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv); 262 263 #endif /* NMAP_H */ 264 265