nmap.cc

来自「Ubuntu packages of security software。 相」· CC 代码 · 共 1,539 行 · 第 1/5 页

CC
1,539
字号
/*************************************************************************** * nmap.cc -- Currently handles some of Nmap's port scanning features as   * * well as the command line user interface.  Note that the actual main()   * * function is in main.cc                                                  * *                                                                         * ***********************IMPORTANT NMAP LICENSE TERMS************************ *                                                                         * * The Nmap Security Scanner is (C) 1996-2008 Insecure.Com LLC. Nmap is    * * also a registered trademark of Insecure.Com LLC.  This program is free  * * software; you may redistribute and/or modify it under the terms of the  * * GNU General Public License as published by the Free Software            * * Foundation; Version 2 with the clarifications and exceptions described  * * below.  This guarantees your right to use, modify, and redistribute     * * this software under certain conditions.  If you wish to embed Nmap      * * technology into proprietary software, we sell alternative licenses      * * (contact sales@insecure.com).  Dozens of software vendors already       * * license Nmap technology such as host discovery, port scanning, OS       * * detection, and version detection.                                       * *                                                                         * * Note that the GPL places important restrictions on "derived works", yet * * it does not provide a detailed definition of that term.  To avoid       * * misunderstandings, we consider an application to constitute a           * * "derivative work" for the purpose of this license if it does any of the * * following:                                                              * * o Integrates source code from Nmap                                      * * o Reads or includes Nmap copyrighted data files, such as                * *   nmap-os-fingerprints or nmap-service-probes.                          * * o Executes Nmap and parses the results (as opposed to typical shell or  * *   execution-menu apps, which simply display raw Nmap output and so are  * *   not derivative works.)                                                *  * o Integrates/includes/aggregates Nmap into a proprietary executable     * *   installer, such as those produced by InstallShield.                   * * o Links to a library or executes a program that does any of the above   * *                                                                         * * The term "Nmap" should be taken to also include any portions or derived * * works of Nmap.  This list is not exclusive, but is just meant to        * * clarify our interpretation of derived works with some common examples.  * * These restrictions only apply when you actually redistribute Nmap.  For * * example, nothing stops you from writing and selling a proprietary       * * front-end to Nmap.  Just distribute it by itself, and point people to   * * http://insecure.org/nmap/ to download Nmap.                             * *                                                                         * * We don't consider these to be added restrictions on top of the GPL, but * * just a clarification of how we interpret "derived works" as it applies  * * to our GPL-licensed Nmap product.  This is similar to the way Linus     * * Torvalds has announced his interpretation of how "derived works"        * * applies to Linux kernel modules.  Our interpretation refers only to     * * Nmap - we don't speak for any other GPL products.                       * *                                                                         * * If you have any questions about the GPL licensing restrictions on using * * Nmap in non-GPL works, we would be happy to help.  As mentioned above,  * * we also offer alternative license to integrate Nmap into proprietary    * * applications and appliances.  These contracts have been sold to dozens  * * of software vendors, and generally include a perpetual license as well  * * as providing for priority support and updates as well as helping to     * * fund the continued development of Nmap technology.  Please email        * * sales@insecure.com for further information.                             * *                                                                         * * As a special exception to the GPL terms, Insecure.Com LLC grants        * * permission to link the code of this program with any version of the     * * OpenSSL library which is distributed under a license identical to that  * * listed in the included Copying.OpenSSL file, and distribute linked      * * combinations including the two. You must obey the GNU GPL in all        * * respects for all of the code used other than OpenSSL.  If you modify    * * this file, you may extend this exception to your version of the file,   * * but you are not obligated to do so.                                     * *                                                                         * * If you received these files with a written license agreement or         * * contract stating terms other than the terms above, then that            * * alternative license agreement takes precedence over these comments.     * *                                                                         * * Source is provided to this software because we believe users have a     * * right to know exactly what a program is going to do before they run it. * * This also allows you to audit the software for security holes (none     * * have been found so far).                                                * *                                                                         * * Source code also allows you to port Nmap to new platforms, fix bugs,    * * and add new features.  You are highly encouraged to send your changes   * * to fyodor@insecure.org for possible incorporation into the main         * * distribution.  By sending these changes to Fyodor or one the            * * Insecure.Org development mailing lists, it is assumed that you are      * * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right * * to reuse, modify, and relicense the code.  Nmap will always be          * * available Open Source, but this is important because the inability to   * * relicense code has caused devastating problems for other Free Software  * * projects (such as KDE and NASM).  We also occasionally relicense the    * * code to third parties as discussed above.  If you wish to specify       * * special license conditions of your contributions, just say so when you  * * send them.                                                              * *                                                                         * * This program 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       * * General Public License for more details at                              * * http://www.gnu.org/copyleft/gpl.html , or in the COPYING file included  * * with Nmap.                                                              * *                                                                         * ***************************************************************************//* $Id: nmap.cc 6633 2007-12-22 06:32:03Z fyodor $ */#include "nmap.h"#include "osscan.h"#include "osscan2.h"#include "scan_engine.h"#include "idle_scan.h"#include "timing.h"#include "NmapOps.h"#include "MACLookup.h"#include "traceroute.h"#include "nmap_tty.h"#include "nmap_dns.h"#include "services.h"#include "protocols.h"#include "targets.h"#include "TargetGroup.h"#include "service_scan.h"#include "charpool.h"#include "nmap_error.h"#include "utils.h"#ifndef NOLUA#include "nse_main.h"#endif #ifdef WIN32#include "winfix.h"#endifusing namespace std;/* global options */extern char *optarg;extern int optind;extern NmapOps o;  /* option structure *//* parse the --scanflags argument.  It can be a number >=0 or a string consisting of TCP flag names like "URGPSHFIN".  Returns -1 if the argument is invalid. */static int parse_scanflags(char *arg) {  int flagval = 0;  char *end = NULL;  if (isdigit(arg[0])) {    flagval = strtol(arg, &end, 0);    if (*end || flagval < 0 || flagval > 255) return -1;  } else {    if (strcasestr(arg, "FIN")) {      flagval |= TH_FIN;    }     if (strcasestr(arg, "SYN")) {      flagval |= TH_SYN;    }     if (strcasestr(arg, "RST") || strcasestr(arg, "RESET")) {      flagval |= TH_RST;    }     if (strcasestr(arg, "PSH") || strcasestr(arg, "PUSH")) {      flagval |= TH_PUSH;    }     if (strcasestr(arg, "ACK")) {      flagval |= TH_ACK;    }     if (strcasestr(arg, "URG")) {      flagval |= TH_URG;    }     if (strcasestr(arg, "ECE")) {      flagval |= TH_ECE;    }     if (strcasestr(arg, "CWR")) {      flagval |= TH_CWR;    }     if (strcasestr(arg, "ALL")) {      flagval = 255;    }    if (strcasestr(arg, "NONE")) {      flagval = 0;    }  }  return flagval;}/* parse a URL stype ftp string of the form user:pass@server:portno */static int parse_bounce_argument(struct ftpinfo *ftp, char *url) {  char *p = url,*q, *s;  if ((q = strrchr(url, '@'))) { /* we have user and/or pass */    *q++ = '\0';    if ((s = strchr(p, ':'))) { /* we have user AND pass */      *s++ = '\0';      strncpy(ftp->pass, s, 255);    } else { /* we ONLY have user */      log_write(LOG_STDOUT, "Assuming %s is a username, and using the default password: %s\n",		p, ftp->pass);    }    strncpy(ftp->user, p, 63);  } else {    q = url;  }  /* q points to beginning of server name */  if ((s = strchr(q, ':'))) { /* we have portno */    *s++ = '\0';    ftp->port = atoi(s);  }  strncpy(ftp->server_name, q, MAXHOSTNAMELEN);  ftp->user[63] = ftp->pass[255] = ftp->server_name[MAXHOSTNAMELEN] = 0;  return 1;}static void printusage(char *name, int rc) {printf("%s %s ( %s )\n"       "Usage: nmap [Scan Type(s)] [Options] {target specification}\n"       "TARGET SPECIFICATION:\n"       "  Can pass hostnames, IP addresses, networks, etc.\n"       "  Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254\n"       "  -iL <inputfilename>: Input from list of hosts/networks\n"       "  -iR <num hosts>: Choose random targets\n"       "  --exclude <host1[,host2][,host3],...>: Exclude hosts/networks\n"       "  --excludefile <exclude_file>: Exclude list from file\n"       "HOST DISCOVERY:\n"       "  -sL: List Scan - simply list targets to scan\n"       "  -sP: Ping Scan - go no further than determining if host is online\n"       "  -PN: Treat all hosts as online -- skip host discovery\n"       "  -PS/PA/PU [portlist]: TCP SYN/ACK or UDP discovery to given ports\n"       "  -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes\n"       "  -PO [protocol list]: IP Protocol Ping\n"       "  -n/-R: Never do DNS resolution/Always resolve [default: sometimes]\n"       "  --dns-servers <serv1[,serv2],...>: Specify custom DNS servers\n"       "  --system-dns: Use OS's DNS resolver\n"       "SCAN TECHNIQUES:\n"       "  -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans\n"       "  -sU: UDP Scan\n"       "  -sN/sF/sX: TCP Null, FIN, and Xmas scans\n"       "  --scanflags <flags>: Customize TCP scan flags\n"       "  -sI <zombie host[:probeport]>: Idle scan\n"       "  -sO: IP protocol scan\n"       "  -b <FTP relay host>: FTP bounce scan\n"       "  --traceroute: Trace hop path to each host\n"       "  --reason: Display the reason a port is in a particular state\n"       "PORT SPECIFICATION AND SCAN ORDER:\n"       "  -p <port ranges>: Only scan specified ports\n"       "    Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080\n"       "  -F: Fast mode - Scan fewer ports than the default scan\n"       "  -r: Scan ports consecutively - don't randomize\n"       "  --top-ports <number>: Scan <number> most common ports\n"       "  --port-ratio <ratio>: Scan ports more common than <ratio>\n"       "SERVICE/VERSION DETECTION:\n"       "  -sV: Probe open ports to determine service/version info\n"       "  --version-intensity <level>: Set from 0 (light) to 9 (try all probes)\n"       "  --version-light: Limit to most likely probes (intensity 2)\n"       "  --version-all: Try every single probe (intensity 9)\n"       "  --version-trace: Show detailed version scan activity (for debugging)\n"#ifndef NOLUA       "SCRIPT SCAN:\n"       "  -sC: equivalent to --script=safe,intrusive\n"       "  --script=<Lua scripts>: <Lua scripts> is a comma separated list of \n"	   "           directories, script-files or script-categories\n"	   "  --script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts\n"       "  --script-trace: Show all data sent and received\n"       "  --script-updatedb: Update the script database.\n"#endif       "OS DETECTION:\n"       "  -O: Enable OS detection\n"       "  --osscan-limit: Limit OS detection to promising targets\n"       "  --osscan-guess: Guess OS more aggressively\n"       "TIMING AND PERFORMANCE:\n"       "  Options which take <time> are in milliseconds, unless you append 's'\n"       "  (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).\n"       "  -T[0-5]: Set timing template (higher is faster)\n"       "  --min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes\n"       "  --min-parallelism/max-parallelism <time>: Probe parallelization\n"       "  --min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifies\n"       "      probe round trip time.\n"       "  --max-retries <tries>: Caps number of port scan probe retransmissions.\n"       "  --host-timeout <time>: Give up on target after this long\n"       "  --scan-delay/--max-scan-delay <time>: Adjust delay between probes\n"       "FIREWALL/IDS EVASION AND SPOOFING:\n"       "  -f; --mtu <val>: fragment packets (optionally w/given MTU)\n"       "  -D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys\n"       "  -S <IP_Address>: Spoof source address\n"       "  -e <iface>: Use specified interface\n"       "  -g/--source-port <portnum>: Use given port number\n"       "  --data-length <num>: Append random data to sent packets\n"       "  --ip-options <options>: Send packets with specified ip options\n"       "  --ttl <val>: Set IP time-to-live field\n"       "  --spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address\n"       "  --badsum: Send packets with a bogus TCP/UDP checksum\n"       "OUTPUT:\n"       "  -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,\n"       "     and Grepable format, respectively, to the given filename.\n"       "  -oA <basename>: Output in the three major formats at once\n"       "  -v: Increase verbosity level (use twice for more effect)\n"       "  -d[level]: Set or increase debugging level (Up to 9 is meaningful)\n"       "  --open: Only show open (or possibly open) ports\n"       "  --packet-trace: Show all packets sent and received\n"       "  --iflist: Print host interfaces and routes (for debugging)\n"       "  --log-errors: Log errors/warnings to the normal-format output file\n"       "  --append-output: Append to rather than clobber specified output files\n"       "  --resume <filename>: Resume an aborted scan\n"       "  --stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML\n"       "  --webxml: Reference stylesheet from Insecure.Org for more portable XML\n"       "  --no-stylesheet: Prevent associating of XSL stylesheet w/XML output\n"       "MISC:\n"       "  -6: Enable IPv6 scanning\n"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?