nmap.cc

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

CC
1,556
字号
	  }	}	if (o.num_ping_ackprobes == 0) {	  o.num_ping_ackprobes = 1;	  o.ping_ackprobes[0] = DEFAULT_TCP_PROBE_PORT;	}      }      else if (*optarg == 'U') {	o.pingtype |= (PINGTYPE_UDP);	if (isdigit((int) *(optarg+1))) {	  o.num_ping_udpprobes = numberlist2array(optarg+1, o.ping_udpprobes, sizeof(o.ping_udpprobes), &proberr);	  if (o.num_ping_udpprobes < 0) {	    fatal("Bogus argument to -PU: %s", proberr);	  }	}	if (o.num_ping_udpprobes == 0) {	  o.num_ping_udpprobes = 1;	  o.ping_udpprobes[0] = DEFAULT_UDP_PROBE_PORT;	}      }      else if (*optarg == 'B') {	o.pingtype = (PINGTYPE_TCP|PINGTYPE_TCP_USE_ACK|PINGTYPE_ICMP_PING);	if (isdigit((int) *(optarg+1))) {	  o.num_ping_ackprobes = numberlist2array(optarg+1, o.ping_ackprobes, sizeof(o.ping_ackprobes), &proberr);	  if (o.num_ping_ackprobes < 0) {	    fatal("Bogus argument to -PB: %s", proberr);	  }	}	if (o.num_ping_ackprobes == 0) {	  o.num_ping_ackprobes = 1;	  o.ping_ackprobes[0] = DEFAULT_TCP_PROBE_PORT;	}      } else if (*optarg == 'O') {	fatal("-PO (the letter O)? No such option. Perhaps you meant to disable pings with -P0 (Zero).");      } else { 	fatal("Illegal Argument to -P, use -P0, -PI, -PB, -PE, -PM, -PP, -PA, -PU, -PT, or -PT80 (or whatever number you want for the TCP probe destination port)");       }      break;    case 'p':       if (ports || portlist)	fatal("Only 1 -p option allowed, separate multiple ranges with commas.");      portlist = strdup(optarg);      break;    case 'q': quashargv++; break;    case 'R': o.resolve_all++; break;    case 'r':       randomize = 0;      break;    case 'S':       if (o.spoofsource)	fatal("You can only use the source option once!  Use -D <decoy1> -D <decoy2> etc. for decoys\n");      if (resolve(optarg, &ss, &sslen, o.af()) == 0) {	fatal("Failed to resolve/decode supposed %s source address %s. Note that if you are using IPv6, the -6 argument must come before -S", (o.af() == AF_INET)? "IPv4" : "IPv6", optarg);      }      o.setSourceSockAddr(&ss, sslen);      o.spoofsource = 1;      break;    case 's':       if (!*optarg) {	fprintf(stderr, "An option is required for -s, most common are -sT (tcp scan), -sS (SYN scan), -sF (FIN scan), -sU (UDP scan) and -sP (Ping scan)");	printusage(argv[0], -1);      }      p = optarg;      while(*p) {	switch(*p) {	case 'A': o.ackscan = 1; break;	case 'B':  fatal("No scan type 'B', did you mean bounce scan (-b)?");	  break;	case 'F':  o.finscan = 1; break;	case 'L':  o.listscan = 1; o.pingtype = PINGTYPE_NONE; break;	case 'M':  o.maimonscan = 1; break;	case 'N':  o.nullscan = 1; break;	case 'O':  o.ipprotscan = 1; break;	case 'P':  o.pingscan = 1; break;	case 'R':  o.rpcscan = 1; break;	case 'S':  o.synscan = 1; break;	  	case 'W':  o.windowscan = 1; break;	case 'T':  o.connectscan = 1; break;	case 'V':  o.servicescan = 1; break;	case 'U':  	  o.udpscan++;	  break;	case 'X':  o.xmasscan++;break;	default:  error("Scantype %c not supported\n",*p); printusage(argv[0], -1); break;	}	p++;      }      break;    case 'T':      if (*optarg == '0' || (strcasecmp(optarg, "Paranoid") == 0)) {	o.timing_level = 0;	o.max_parallelism = 1;	o.scan_delay = 300000;	o.setInitialRttTimeout(300000);      } else if (*optarg == '1' || (strcasecmp(optarg, "Sneaky") == 0)) {	o.timing_level = 1;	o.max_parallelism = 1;	o.scan_delay = 15000;	o.setInitialRttTimeout(15000);      } else if (*optarg == '2' || (strcasecmp(optarg, "Polite") == 0)) {	o.timing_level = 2;	o.max_parallelism = 1;	o.scan_delay = 400;      } else if (*optarg == '3' || (strcasecmp(optarg, "Normal") == 0)) {      } else if (*optarg == '4' || (strcasecmp(optarg, "Aggressive") == 0)) {	o.timing_level = 4;	o.setMinRttTimeout(100);	o.setMaxRttTimeout(1250);	o.setInitialRttTimeout(500);        o.setMaxTCPScanDelay(10);        o.setMaxRetransmissions(6);      } else if (*optarg == '5' || (strcasecmp(optarg, "Insane") == 0)) {	o.timing_level = 5;	o.setMinRttTimeout(50);	o.setMaxRttTimeout(300);	o.setInitialRttTimeout(250);	o.host_timeout = 900000;        o.setMaxTCPScanDelay(5);        o.setMaxRetransmissions(2);      } else {	fatal("Unknown timing mode (-T argument).  Use either \"Paranoid\", \"Sneaky\", \"Polite\", \"Normal\", \"Aggressive\", \"Insane\" or a number from 0 (Paranoid) to 5 (Insane)");      }      break;    case 'V':       printf("\n%s version %s ( %s )\n", NMAP_NAME, NMAP_VERSION, NMAP_URL);       exit(0);      break;    case 'v': o.verbose++; break;    }  }#ifdef WIN32    win_init();#endif  tty_init(); // Put the keyboard in raw mode#if HAVE_SIGNAL  if (!o.debugging)    signal(SIGSEGV, sigdie); #endif  // After the arguments are fully processed we now make any of the timing  // tweaks the user might've specified:  if (pre_max_parallelism != -1) o.max_parallelism = pre_max_parallelism;  if (pre_scan_delay != -1) {    o.scan_delay = pre_scan_delay;    if (o.scan_delay > o.maxTCPScanDelay()) o.setMaxTCPScanDelay(o.scan_delay);    if (o.scan_delay > o.maxUDPScanDelay()) o.setMaxUDPScanDelay(o.scan_delay);    o.max_parallelism = 1;    if(pre_max_parallelism != -1)      fatal("You can't use --max-parallelism with --scan-delay.");  }  if (pre_max_scan_delay != -1) {    o.setMaxTCPScanDelay(pre_max_scan_delay);    o.setMaxUDPScanDelay(pre_max_scan_delay);  }  if (pre_init_rtt_timeout != -1) o.setInitialRttTimeout(pre_init_rtt_timeout);  if (pre_min_rtt_timeout != -1) o.setMinRttTimeout(pre_min_rtt_timeout);  if (pre_max_rtt_timeout != -1) o.setMaxRttTimeout(pre_max_rtt_timeout);  if (pre_max_retries != -1) o.setMaxRetransmissions(pre_max_retries);  if (pre_host_timeout != -1) o.host_timeout = pre_host_timeout;  if (o.osscan == OS_SCAN_SYS_1_ONLY)    o.reference_FPs1 = parse_fingerprint_reference_file("nmap-os-fingerprints");  else if (o.osscan == OS_SCAN_DEFAULT || o.osscan == OS_SCAN_SYS_2_ONLY)    o.reference_FPs = parse_fingerprint_reference_file("nmap-os-db");  o.ValidateOptions();  // print ip options  if((o.debugging || o.packetTrace()) && o.ipoptionslen){    char buf[256]; // 256 > 5*40    bintohexstr(buf, sizeof(buf), (char*)o.ipoptions, o.ipoptionslen);    if(o.ipoptionslen>=8)	// at least one ip address    log_write(LOG_STDOUT, "Binary ip options to be send:\n%s", buf);    log_write(LOG_STDOUT, "Parsed ip options to be send:\n%s\n",     	print_ip_options(o.ipoptions, o.ipoptionslen));  }  /* Open the log files, now that we know whether the user wants them appended     or overwritten */  if (normalfilename)    log_open(LOG_NORMAL, o.append_output, normalfilename);  if (machinefilename)    log_open(LOG_MACHINE, o.append_output, machinefilename);  if (kiddiefilename)    log_open(LOG_SKID, o.append_output, kiddiefilename);  if (xmlfilename)    log_open(LOG_XML, o.append_output, xmlfilename);  if (!o.interactivemode) {    char tbuf[128];    struct tm *tm;    time_t now = time(NULL);    if (!(tm = localtime(&now)))       fatal("Unable to get current localtime()#!#");    // ISO 8601 date/time -- http://www.cl.cam.ac.uk/~mgk25/iso-time.html     if (strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M %Z", tm) <= 0)      fatal("Unable to properly format time");    log_write(LOG_STDOUT|LOG_SKID, "\nStarting %s %s ( %s ) at %s\n", NMAP_NAME, NMAP_VERSION, NMAP_URL, tbuf);    if (o.verbose && tm->tm_mon == 8 && tm->tm_mday == 1) {      log_write(LOG_STDOUT|LOG_SKID, "Happy %dth Birthday to Nmap, may it live to be %d!\n", tm->tm_year - 97, tm->tm_year + 3 );    }    if (iflist) {      print_iflist();      exit(0);    }  }  if ((o.pingscan || o.listscan) && (portlist || fastscan)) {    fatal("You cannot use -F (fast scan) or -p (explicit port selection) with PING scan or LIST scan");  }  if (portlist) {    ports = getpts(portlist);    if (!ports)      fatal("Your port specification string is not parseable");    free(portlist);    portlist = NULL;  }  if (fastscan && ports) {    fatal("You can specify fast scan (-F) or explicitly select individual ports (-p), but not both");  } else if (fastscan && o.ipprotscan) {    ports = getfastprots();  } else if (fastscan) {    ports = getfastports(o.TCPScan(), o.UDPScan());  }#ifdef WIN32  if (o.sendpref & PACKET_SEND_IP) {	  error("WARNING: raw IP (rather than raw ethernet) packet sending attempted on Windows. This probably won't work.  Consider --send-eth next time.\n");  }#endif  if (spoofmac) {    u8 mac_data[6];    int pos = 0; /* Next index of mac_data to fill in */    char tmphex[3];    /* A zero means set it all randomly.  Anything that is all digits       or colons is treated as a prefix, with remaining characters for       the 6-byte MAC (if any) chosen randomly.  Otherwise, it is       treated as a vendor string for lookup in nmap-mac-prefixes */    if (strcmp(spoofmac, "0") == 0) {      pos = 0;    } else {      const char *p = spoofmac;      while(*p) { 	if (*p == ':') p++;	if (isxdigit(*p) && isxdigit(*(p+1))) {	  if (pos >= 6) fatal("Bogus --spoof-mac value encountered (%s) -- only up to 6 bytes permitted", spoofmac);	  tmphex[0] = *p; tmphex[1] = *(p+1); tmphex[2] = '\0';	  mac_data[pos] = (u8) strtol(tmphex, NULL, 16);	  pos++;	  p += 2;	} else break;      }      if (*p) {	/* Failed to parse it as a MAC prefix -- treating as a vendor substring instead */	if (!MACCorp2Prefix(spoofmac, mac_data))	  fatal("Could not parse as a prefix nor find as a vendor substring the given --spoof-mac argument: %s.  If you are giving hex digits, there must be an even number of them.", spoofmac);	pos = 3;      }    }    if (pos < 6) {      get_random_bytes(mac_data + pos, 6 - pos);    }    /* Got the new MAC! */    const char *vend = MACPrefix2Corp(mac_data);    log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, 	      "Spoofing MAC address %02X:%02X:%02X:%02X:%02X:%02X (%s)\n",	      mac_data[0], mac_data[1], mac_data[2], mac_data[3], mac_data[4],	      mac_data[5], vend? vend : "No registered vendor");    o.setSpoofMACAddress(mac_data);    /* If they want to spoof the MAC address, we should at least make       some effort to actually send raw ethernet frames rather than IP       packets (which would use the real IP */    if (o.sendpref != PACKET_SEND_IP_STRONG)      o.sendpref = PACKET_SEND_ETH_STRONG;  }  if (!ports) {    if (o.ipprotscan) {      ports = getdefaultprots();    } else {      ports = getdefaultports(o.TCPScan(), o.UDPScan());    }  }  /* By now, we've got our port lists.  Give the user a warning if no    * ports are specified for the type of scan being requested.  Other things   * (such as OS ident scan) might break cause no ports were specified,  but   * we've given our warning...   */  if ((o.TCPScan()) && ports->tcp_count == 0)    error("WARNING: a TCP scan type was requested, but no tcp ports were specified.  Skipping this scan type.");  if (o.UDPScan() && ports->udp_count == 0)    error("WARNING: UDP scan was requested, but no udp ports were specified.  Skipping this scan type.");  if (o.ipprotscan && ports->prot_count == 0)    error("WARNING: protocol scan was requested, but no protocols were specified to be scanned.  Skipping this scan type.");  /* Set up our array of decoys! */  if (o.decoyturn == -1) {    o.decoyturn = (o.numdecoys == 0)?  0 : get_random_uint() % o.numdecoys;     o.numdecoys++;    for(i=o.numdecoys-1; i > o.decoyturn; i--)      o.decoys[i] = o.decoys[i-1];  }  /* We need to find what interface to route through if:

⌨️ 快捷键说明

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