nmapops.cc
来自「Ubuntu packages of security software。 相」· CC 代码 · 共 574 行 · 第 1/2 页
CC
574 行
/* this function does not currently cover cases such as TCP SYN ping scan which can go either way based on whether the user is root or IPv6 is being used. It will return false in those cases where a RawScan is not neccessarily used. */bool NmapOps::RawScan() { if (ackscan|finscan|idlescan|ipprotscan|maimonscan|nullscan|osscan|synscan|udpscan|windowscan|xmasscan) return true; if (pingtype & (PINGTYPE_ICMP_PING|PINGTYPE_ICMP_MASK|PINGTYPE_ICMP_TS|PINGTYPE_TCP_USE_ACK|PINGTYPE_UDP)) return true; return false; }void NmapOps::ValidateOptions() {#ifdef WIN32 const char *privreq = "that WinPcap version 3.1 or higher and iphlpapi.dll be installed. You seem to be missing one or both of these. Winpcap is available from http://www.winpcap.org. iphlpapi.dll comes with Win98 and later operating sytems and NT 4.0 with SP4 or greater. For previous windows versions, you may be able to take iphlpapi.dll from another system and place it in your system32 dir (e.g. c:\\windows\\system32)";#else const char *privreq = "root privileges";#endif if (pingtype == PINGTYPE_UNKNOWN) { if (isr00t && af() == AF_INET) pingtype = DEFAULT_PING_TYPES; else pingtype = PINGTYPE_TCP; // if nonr00t or IPv6 getpts_simple(DEFAULT_TCP_PROBE_PORT_SPEC, SCAN_TCP_PORT, &o.ping_ackprobes, &o.num_ping_ackprobes); assert(o.num_ping_ackprobes > 0); } /* Insure that at least one scantype is selected */ if (TCPScan() + UDPScan() + ipprotscan + listscan + pingscan == 0) { if (isr00t && af() == AF_INET) synscan++; else connectscan++; // if (verbose) error("No tcp, udp, or ICMP scantype specified, assuming %s scan. Use -sP if you really don't want to portscan (and just want to see what hosts are up).", synscan? "SYN Stealth" : "vanilla tcp connect()"); } if ((pingtype & PINGTYPE_TCP) && (!isr00t || af() != AF_INET)) { /* We will have to do a connect() style ping */ if (num_ping_synprobes && num_ping_ackprobes) { fatal("Cannot use both SYN and ACK ping probes if you are nonroot or using IPv6"); } /* Pretend we wanted SYN probes all along. */ if (num_ping_ackprobes > 0) { num_ping_synprobes = num_ping_ackprobes; ping_synprobes = ping_ackprobes; num_ping_ackprobes = 0; ping_ackprobes = NULL; } pingtype &= ~PINGTYPE_TCP_USE_ACK; pingtype |= PINGTYPE_TCP_USE_SYN; } if (pingtype != PINGTYPE_NONE && spoofsource) { error("WARNING: If -S is being used to fake your source address, you may also have to use -e <interface> and -PN . If you are using it to specify your real source address, you can ignore this warning."); } if (pingtype != PINGTYPE_NONE && idlescan) { error("WARNING: Many people use -PN w/Idlescan to prevent pings from their true IP. On the other hand, timing info Nmap gains from pings can allow for faster, more reliable scans."); sleep(2); /* Give ppl a chance for ^C :) */ } if (numdecoys > 1 && idlescan) { error("WARNING: Your decoys won't be used in the Idlescan portion of your scanning (although all packets sent to the target are spoofed anyway"); } if (connectscan && spoofsource) { error("WARNING: -S will only affect the source address used in a connect() scan if you specify one of your own addresses. Use -sS or another raw scan if you want to completely spoof your source address, but then you need to know what you're doing to obtain meaningful results."); } if ((pingtype & PINGTYPE_UDP) && (!isr00t || af() != AF_INET)) { fatal("Sorry, UDP Ping (-PU) only works if you are root (because we need to read raw responses off the wire) and only for IPv4 (cause fyodor is too lazy right now to add IPv6 support and nobody has sent a patch)"); } if ((pingtype & PINGTYPE_PROTO) && (!isr00t || af() != AF_INET)) { fatal("Sorry, IPProto Ping (-PO) only works if you are root (because we need to read raw responses off the wire) and only for IPv4"); } if (ipprotscan + (TCPScan() || UDPScan()) + listscan + pingscan > 1) { fatal("Sorry, the IPProtoscan, Listscan, and Pingscan (-sO, -sL, -sP) must currently be used alone rather than combined with other scan types."); } if ((pingscan && pingtype == PINGTYPE_NONE)) { fatal("-PN (skip ping) is incompatable with -sP (ping scan). If you only want to enumerate hosts, try list scan (-sL)"); } if (pingscan && (TCPScan() || UDPScan() || ipprotscan || listscan)) { fatal("Ping scan is not valid with any other scan types (the other ones all include a ping scan"); } if (sendpref == PACKET_SEND_NOPREF) {#ifdef WIN32 sendpref = PACKET_SEND_ETH_STRONG;#else sendpref = PACKET_SEND_IP_WEAK;#endif }/* We start with stuff users should not do if they are not root */ if (!isr00t) {#ifndef WIN32 /* Win32 has perfectly fine ICMP socket support */ if (pingtype & (PINGTYPE_ICMP_PING|PINGTYPE_ICMP_MASK|PINGTYPE_ICMP_TS)) { error("Warning: You are not root -- using TCP pingscan rather than ICMP"); pingtype = PINGTYPE_TCP; if (num_ping_synprobes == 0) { getpts_simple(DEFAULT_TCP_PROBE_PORT_SPEC, SCAN_TCP_PORT, &o.ping_synprobes, &o.num_ping_synprobes); assert(o.num_ping_synprobes > 0); } }#endif if (ackscan|finscan|idlescan|ipprotscan|maimonscan|nullscan|synscan|udpscan|windowscan|xmasscan) { fatal("You requested a scan type which requires %s.", privreq); } if (numdecoys > 0) { fatal("Sorry, but decoys (-D) require %s.", privreq); } if (fragscan) { fatal("Sorry, but fragscan requires %s.", privreq); } if (osscan) { fatal("TCP/IP fingerprinting (for OS scan) requires %s.", privreq); } if (ipoptionslen) fatal("Sorry, using ip options requires %s.", privreq); } if (numdecoys > 0 && rpcscan) { error("WARNING: RPC scan currently does not make use of decoys so don't count on that protection"); } if (bouncescan && pingtype != PINGTYPE_NONE) log_write(LOG_STDOUT, "Hint: if your bounce scan target hosts aren't reachable from here, remember to use -PN so we don't try and ping them prior to the scan\n"); if (ackscan+bouncescan+connectscan+finscan+idlescan+maimonscan+nullscan+synscan+windowscan+xmasscan > 1) fatal("You specified more than one type of TCP scan. Please choose only one of -sA, -b, -sT, -sF, -sI, -sM, -sN, -sS, -sW, and -sX"); if (numdecoys > 0 && (bouncescan || connectscan)) { error("WARNING: Decoys are irrelevant to the bounce or connect scans"); } if (fragscan && !(ackscan|finscan|maimonscan|nullscan|synscan|windowscan|xmasscan) && \ !(pingtype&(PINGTYPE_ICMP_TS|PINGTYPE_TCP)) && !(fragscan == 8 && pingtype&PINGTYPE_ICMP_MASK) && \ !(extra_payload_length + 8 > fragscan)) { fatal("Fragscan only works with TCP, ICMP Timestamp or ICMP Mask (mtu=8) ping types or ACK, FIN, Maimon, NULL, SYN, Window, and XMAS scan types"); } if (osscan && bouncescan) error("Combining bounce scan with OS scan seems silly, but I will let you do whatever you want!"); #if !defined(LINUX) && !defined(OPENBSD) && !defined(FREEBSD) && !defined(NETBSD) if (fragscan) { error("Warning: Packet fragmentation selected on a host other than Linux, OpenBSD, FreeBSD, or NetBSD. This may or may not work."); }#endif if (osscan && pingscan) { fatal("WARNING: OS Scan is unreliable with a ping scan. You need to use a scan type along with it, such as -sS, -sT, -sF, etc instead of -sP"); } if (osscan && ipprotscan) { error("WARNING: Disabling OS Scan (-O) as it is incompatible with the IPProto Scan (-sO)"); osscan = 0; } if (servicescan && ipprotscan) { error("WARNING: Disabling Service Scan (-sV) as it is incompatible with the IPProto Scan (-sO)"); servicescan = 0; } if (servicescan && pingscan) servicescan = 0; if (defeat_rst_ratelimit && !synscan) { fatal("Option --defeat-rst-ratelimit works only with a SYN scan (-sS)"); } if (resume_ip.s_addr && generate_random_ips) resume_ip.s_addr = 0; if (magic_port_set && connectscan) { error("WARNING: -g is incompatible with the default connect() scan (-sT). Use a raw scan such as -sS if you want to set the source port."); } if (max_parallelism && min_parallelism && (min_parallelism > max_parallelism)) { fatal("--min-parallelism=%i must be less than or equal to --max-parallelism=%i",min_parallelism,max_parallelism); } if (af() == AF_INET6 && (numdecoys|osscan|bouncescan|fragscan|ackscan|finscan|idlescan|ipprotscan|maimonscan|nullscan|rpcscan|synscan|udpscan|windowscan|xmasscan)) { fatal("Sorry -- IPv6 support is currently only available for connect() scan (-sT), ping scan (-sP), and list scan (-sL). OS detection and decoys are also not supported with IPv6. Further support is under consideration."); } if (af() != AF_INET) mass_dns = false; /* Prevent performance values from getting out of whack */ if (min_parallelism > max_parallelism) max_parallelism = min_parallelism; if(ipoptions && osscan) error("WARNING: Ip options are NOT used while OS scanning!"); }void NmapOps::setMaxOSTries(int mot) { if (mot <= 0) fatal("%s: value must be at least 1", __func__); max_os_tries = mot; }void NmapOps::setMaxRttTimeout(int rtt) { if (rtt <= 0) fatal("%s: maximum round trip time must be greater than 0", __func__); max_rtt_timeout = rtt; if (rtt < min_rtt_timeout) min_rtt_timeout = rtt; if (rtt < initial_rtt_timeout) initial_rtt_timeout = rtt;}void NmapOps::setMinRttTimeout(int rtt) { if (rtt < 0) fatal("%s: minimum round trip time must be at least 0", __func__); min_rtt_timeout = rtt; if (rtt > max_rtt_timeout) max_rtt_timeout = rtt; if (rtt > initial_rtt_timeout) initial_rtt_timeout = rtt;}void NmapOps::setInitialRttTimeout(int rtt) { if (rtt <= 0) fatal("%s: initial round trip time must be greater than 0", __func__); initial_rtt_timeout = rtt; if (rtt > max_rtt_timeout) max_rtt_timeout = rtt; if (rtt < min_rtt_timeout) min_rtt_timeout = rtt;}void NmapOps::setMaxRetransmissions(int max_retransmit){ if (max_retransmit < 0) fatal("%s: must be positive", __func__); max_retransmissions = max_retransmit;}void NmapOps::setMinHostGroupSz(unsigned int sz) { if (sz > max_host_group_sz) fatal("Minimum host group size may not be set to greater than maximum size (currently %d)\n", max_host_group_sz); min_host_group_sz = sz;}void NmapOps::setMaxHostGroupSz(unsigned int sz) { if (sz < min_host_group_sz) fatal("Maximum host group size may not be set to less than the maximum size (currently %d)\n", min_host_group_sz); if (sz <= 0) fatal("Max host size must be at least 1"); max_host_group_sz = sz;} /* Sets the Name of the XML stylesheet to be printed in XML output. If this is never called, a default stylesheet distributed with Nmap is used. If you call it with NULL as the xslname, no stylesheet line is printed. */void NmapOps::setXSLStyleSheet(char *xslname) { if (xsl_stylesheet) free(xsl_stylesheet); xsl_stylesheet = xslname? strdup(xslname) : NULL;}void NmapOps::setSpoofMACAddress(u8 *mac_data) { memcpy(spoof_mac, mac_data, 6); spoof_mac_set = true;}#ifndef NOLUAvoid NmapOps::chooseScripts(char* argument) { char *ap; ap = strtok(argument, ","); while(ap != NULL) { chosenScripts.push_back(std::string(ap)); ap = strtok(NULL, ","); }}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?