nmap.cc

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

CC
1,539
字号
	  o.decoyturn = o.numdecoys++;	} else if (!strcasecmp(p, "rnd") || !strncasecmp(p, "rnd:", 4)) {	  int i = 1;	  /* 'rnd:' is allowed and just gives them one */	  if (strlen(p) > 4)	    i = atoi(&p[4]);	  if (i < 1)	    fatal("Bad 'rnd' decoy \"%s\"", p);	  if (o.numdecoys + i >= MAX_DECOYS - 1)	    fatal("You are only allowed %d decoys (if you need more redefine MAX_DECOYS in nmap.h)", MAX_DECOYS);	  while (i--) {	    do {	      o.decoys[o.numdecoys].s_addr = get_random_u32();	    } while (ip_is_reserved(&o.decoys[o.numdecoys]));	    o.numdecoys++;	  }	} else {      	  if (o.numdecoys >= MAX_DECOYS -1)	    fatal("You are only allowed %d decoys (if you need more redefine MAX_DECOYS in nmap.h)", MAX_DECOYS);	  if (resolve(p, &o.decoys[o.numdecoys])) {	    o.numdecoys++;	  } else {	    fatal("Failed to resolve decoy host: %s (must be hostname or IP address)", p);	  }	}	if (q) {	  *q = ',';	  p = q+1;	}      } while(q);      break;    case 'd':       if (optarg)	o.debugging = o.verbose = atoi(optarg);      else {	o.debugging++; o.verbose++;      }      o.reason = true;      break;    case 'e':       Strncpy(o.device, optarg, sizeof(o.device)); break;    case 'F': o.fastscan++; break;    case 'f': o.fragscan += 8; break;    case 'g':       o.magic_port = atoi(optarg);      o.magic_port_set = 1;      if (o.magic_port == 0) error("WARNING: a source port of zero may not work on all systems.");      break;        case 'h': printusage(argv[0], 0); break;    case '?': printusage(argv[0], -1); break;    case 'I':       printf("WARNING: identscan (-I) no longer supported.  Ignoring -I\n");      break;      // o.identscan++; break;    case 'i':       if (inputfd) {	fatal("Only one input filename allowed");      }      if (!strcmp(optarg, "-")) {	inputfd = stdin;      } else {    	inputfd = fopen(optarg, "r");	if (!inputfd) {	  fatal("Failed to open input file %s for reading", optarg);	}        }      break;      case 'M':       pre_max_parallelism = atoi(optarg);       if (pre_max_parallelism < 1) fatal("Argument to -M must be at least 1!");      if (pre_max_parallelism > 900) {	error("Warning: Your max-parallelism (-M) option is extraordinarily high, which can hurt reliability");      }      break;    case 'm':       machinefilename = optarg;      break;    case 'n': o.noresolve++; break;    case 'O':       if (!optarg || *optarg == '2')        o.osscan = OS_SCAN_DEFAULT;      else if (*optarg == '1')        fatal("First-generation OS detection (-O1) is no longer supported. Use -O instead.");      else        fatal("Unknown argument to -O.");      break;    case 'o':      normalfilename = logfilename(optarg, tm);      break;    case 'P':       if (*optarg == '\0' || *optarg == 'I' || *optarg == 'E')	o.pingtype |= PINGTYPE_ICMP_PING;      else if (*optarg == 'M') 	o.pingtype |= PINGTYPE_ICMP_MASK;      else if (*optarg == 'P') 	o.pingtype |= PINGTYPE_ICMP_TS;      else if (*optarg == '0' || *optarg == 'N' || *optarg == 'D')      	o.pingtype = PINGTYPE_NONE;      else if (*optarg == 'R')	o.pingtype |= PINGTYPE_ARP;      else if (*optarg == 'S') {	o.pingtype |= (PINGTYPE_TCP|PINGTYPE_TCP_USE_SYN);	if (*(optarg + 1) != '\0') {	  getpts_simple(optarg + 1, SCAN_TCP_PORT, &o.ping_synprobes, &o.num_ping_synprobes);	  if (o.num_ping_synprobes <= 0) {	    fatal("Bogus argument to -PS: %s", optarg + 1);	  }	}	if (o.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);	}      }      else if (*optarg == 'T' || *optarg == 'A') {	/* NmapOps::ValidateOptions() takes care of changing this	   to SYN if not root or if IPv6 */	o.pingtype |= (PINGTYPE_TCP|PINGTYPE_TCP_USE_ACK);	if (*(optarg + 1) != '\0') {	  getpts_simple(optarg + 1, SCAN_TCP_PORT, &o.ping_ackprobes, &o.num_ping_ackprobes);	  if (o.num_ping_ackprobes <= 0) {	    fatal("Bogus argument to -PA: %s", optarg + 1);	  }	}	if (o.num_ping_ackprobes == 0) {	  getpts_simple(DEFAULT_TCP_PROBE_PORT_SPEC, SCAN_TCP_PORT, &o.ping_ackprobes, &o.num_ping_ackprobes);	  assert(o.num_ping_ackprobes > 0);	}      }      else if (*optarg == 'U') {	o.pingtype |= (PINGTYPE_UDP);	if (*(optarg + 1) != '\0') {	  getpts_simple(optarg + 1, SCAN_UDP_PORT, &o.ping_udpprobes, &o.num_ping_udpprobes);	  if (o.num_ping_udpprobes <= 0) {	    fatal("Bogus argument to -PU: %s", optarg + 1);	  }	}	if (o.num_ping_udpprobes == 0) {	  getpts_simple(DEFAULT_UDP_PROBE_PORT_SPEC, SCAN_UDP_PORT, &o.ping_udpprobes, &o.num_ping_udpprobes);	  assert(o.num_ping_udpprobes > 0);	}      }      else if (*optarg == 'B') {	o.pingtype = (PINGTYPE_TCP|PINGTYPE_TCP_USE_ACK|PINGTYPE_ICMP_PING);	if (*(optarg + 1) != '\0') {	  getpts_simple(optarg + 1, SCAN_TCP_PORT, &o.ping_ackprobes, &o.num_ping_ackprobes);	  if (o.num_ping_ackprobes <= 0) {	    fatal("Bogus argument to -PB: %s", optarg + 1);	  }	}	if (o.num_ping_ackprobes == 0) {	  getpts_simple(DEFAULT_TCP_PROBE_PORT_SPEC, SCAN_TCP_PORT, &o.ping_ackprobes, &o.num_ping_ackprobes);	  assert(o.num_ping_ackprobes > 0);	}      } else if (*optarg == 'O') {	o.pingtype |= PINGTYPE_PROTO;	if (*(optarg + 1) != '\0') {	  getpts_simple(optarg + 1, SCAN_PROTOCOLS, &o.ping_protoprobes, &o.num_ping_protoprobes);	  if (o.num_ping_protoprobes <= 0) {	    fatal("Bogus argument to -PO: %s", optarg + 1);	  }	}	if (o.num_ping_protoprobes == 0) {	  getpts_simple(DEFAULT_PROTO_PROBE_PORT_SPEC, SCAN_PROTOCOLS, &o.ping_protoprobes, &o.num_ping_protoprobes);	  assert(o.num_ping_protoprobes > 0);	}      } else { 	fatal("Illegal Argument to -P, use -PN, -PO, -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) {	error("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;#ifndef NOLUA	case 'C':  o.script = 1; break;#endif	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_DEFAULT)    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);

⌨️ 快捷键说明

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