nmap.cc
来自「Ubuntu packages of security software。 相」· CC 代码 · 共 1,556 行 · 第 1/5 页
CC
1,556 行
* compiler will be able to optimize this a little better using a jump table * or what have you */ switch (i1) { case 0: /* 000/8 is IANA reserved */ case 1: /* 001/8 is IANA reserved */ case 2: /* 002/8 is IANA reserved */ case 5: /* 005/8 is IANA reserved */ case 6: /* USA Army ISC */ case 7: /* used for BGP protocol */ case 10: /* the infamous 10.0.0.0/8 */ case 23: /* 023/8 is IANA reserved */ case 27: /* 027/8 is IANA reserved */ case 31: /* 031/8 is IANA reserved */ case 36: /* 036/8 is IANA reserved */ case 37: /* 037/8 is IANA reserved */ case 39: /* 039/8 is IANA reserved */ case 42: /* 042/8 is IANA reserved */ case 49: /* 049/8 is IANA reserved */ case 50: /* 050/8 is IANA reserved */ case 55: /* misc. U.S.A. Armed forces */ case 127: /* 127/8 is reserved for loopback */ case 197: /* 197/8 is IANA reserved */ case 223: /* 223/8 is IANA reserved */ return 1; default: break; } /* 077-079/8 is IANA reserved */ if (i1 >= 77 && i1 <= 79) return 1; /* 092-123/8 is IANA reserved */ if (i1 >= 92 && i1 <= 123) return 1; /* 172.16.0.0/12 is reserved for private nets by RFC1819 */ if (i1 == 172 && i2 >= 16 && i2 <= 31) return 1; /* 173-187/8 is IANA reserved */ if (i1 >= 173 && i1 <= 187) return 1; /* 192.168.0.0/16 is reserved for private nets by RFC1819 */ /* 192.0.2.0/24 is reserved for documentation and examples */ /* 192.88.99.0/24 is used as 6to4 Relay anycast prefix by RFC3068 */ if (i1 == 192) { if (i2 == 168) return 1; if (i2 == 0 && i3 == 2) return 1; if (i2 == 88 && i3 == 99) return 1; } /* 198.18.0.0/15 is used for benchmark tests by RFC2544 */ if (i1 == 198 && i2 == 18 && i3 >= 1 && i3 <= 64) { return 1; } /* reserved for DHCP clients seeking addresses, not routable outside LAN */ if (i1 == 169 && i2 == 254) return 1; /* believe it or not, 204.152.64.0/23 is some bizarre Sun proprietary * clustering thing */ if (i1 == 204 && i2 == 152 && (i3 == 64 || i3 == 65)) return 1; /* 224-239/8 is all multicast stuff */ /* 240-255/8 is IANA reserved */ if (i1 >= 224) return 1; /* 255.255.255.255, note we already tested for i1 in this range */ if (i2 == 255 && i3 == 255 && i4 == 255) return 1; return 0;}static char *grab_next_host_spec(FILE *inputfd, int argc, char **fakeargv) { static char host_spec[1024]; unsigned int host_spec_index; int ch; struct in_addr ip; if (o.generate_random_ips) { do { ip.s_addr = get_random_u32(); } while (ip_is_reserved(&ip)); Strncpy(host_spec, inet_ntoa(ip), sizeof(host_spec)); } else if (!inputfd) { return( (optind < argc)? fakeargv[optind++] : NULL); } else { host_spec_index = 0; while((ch = getc(inputfd)) != EOF) { if (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t' || ch == '\0') { if (host_spec_index == 0) continue; host_spec[host_spec_index] = '\0'; return host_spec; } else if (host_spec_index < sizeof(host_spec) / sizeof(char) -1) { host_spec[host_spec_index++] = (char) ch; } else fatal("One of the host_specifications from your input file is too long (> %d chars)", (int) sizeof(host_spec)); } host_spec[host_spec_index] = '\0'; } if (!*host_spec) return NULL; return host_spec;}int nmap_main(int argc, char *argv[]) { char *p, *q; int i, arg; long l; unsigned int targetno; FILE *inputfd = NULL, *excludefd = NULL; char *host_spec = NULL, *exclude_spec = NULL; short fastscan=0, randomize=1; short quashargv = 0; char **host_exp_group; char *idleProxy = NULL; /* The idle host used to "Proxy" an Idlescan */ int num_host_exp_groups = 0; char *machinefilename = NULL, *kiddiefilename = NULL, *normalfilename = NULL, *xmlfilename = NULL; HostGroupState *hstate = NULL; char *endptr = NULL; struct scan_lists *ports = NULL; TargetGroup *exclude_group = NULL; char myname[MAXHOSTNAMELEN + 1];#if (defined(IN_ADDR_DEEPSTRUCT) || defined( SOLARIS)) /* Note that struct in_addr in solaris is 3 levels deep just to store an * unsigned int! */ struct ftpinfo ftp = { FTPUSER, FTPPASS, "", { { { 0 } } } , 21, 0};#else struct ftpinfo ftp = { FTPUSER, FTPPASS, "", { 0 }, 21, 0};#endif struct hostent *target = NULL; char **fakeargv; Target *currenths; vector<Target *> Targets; char *portlist = NULL; /* Ports list specified by user */ char *proberr; int sourceaddrwarning = 0; /* Have we warned them yet about unguessable source addresses? */ unsigned int ideal_scan_group_sz = 0; char hostname[MAXHOSTNAMELEN + 1] = ""; const char *spoofmac = NULL; time_t timep; char mytime[128]; struct sockaddr_storage ss; size_t sslen; int option_index; bool iflist = false; // Pre-specified timing parameters. // These are stored here during the parsing of the arguments so that we can // set the defaults specified by any timing template options (-T2, etc) BEFORE // any of these. In other words, these always take precedence over the templates. int pre_max_parallelism=-1, pre_scan_delay=-1, pre_max_scan_delay=-1; int pre_init_rtt_timeout=-1, pre_min_rtt_timeout=-1, pre_max_rtt_timeout=-1; int pre_max_retries=-1; long pre_host_timeout=-1; struct option long_options[] = { {"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, {"datadir", required_argument, 0, 0}, {"debug", optional_argument, 0, 'd'}, {"help", no_argument, 0, 'h'}, {"iflist", no_argument, 0, 0}, {"release_memory", no_argument, 0, 0}, {"release-memory", no_argument, 0, 0}, {"max_os_tries", required_argument, 0, 0}, {"max-os-tries", required_argument, 0, 0}, {"max_parallelism", required_argument, 0, 'M'}, {"max-parallelism", required_argument, 0, 'M'}, {"min_parallelism", required_argument, 0, 0}, {"min-parallelism", required_argument, 0, 0}, {"timing", required_argument, 0, 'T'}, {"max_rtt_timeout", required_argument, 0, 0}, {"max-rtt-timeout", required_argument, 0, 0}, {"min_rtt_timeout", required_argument, 0, 0}, {"min-rtt-timeout", required_argument, 0, 0}, {"initial_rtt_timeout", required_argument, 0, 0}, {"initial-rtt-timeout", required_argument, 0, 0}, {"excludefile", required_argument, 0, 0}, {"exclude", required_argument, 0, 0}, {"max_hostgroup", required_argument, 0, 0}, {"max-hostgroup", required_argument, 0, 0}, {"min_hostgroup", required_argument, 0, 0}, {"min-hostgroup", required_argument, 0, 0}, {"open", no_argument, 0, 0}, {"scanflags", required_argument, 0, 0}, {"defeat_rst_ratelimit", no_argument, 0, 0}, {"defeat-rst-ratelimit", no_argument, 0, 0}, {"host_timeout", required_argument, 0, 0}, {"host-timeout", required_argument, 0, 0}, {"scan_delay", required_argument, 0, 0}, {"scan-delay", required_argument, 0, 0}, {"max_scan_delay", required_argument, 0, 0}, {"max-scan-delay", required_argument, 0, 0}, {"max_retries", required_argument, 0, 0}, {"max-retries", required_argument, 0, 0}, {"oA", required_argument, 0, 0}, {"oN", required_argument, 0, 0}, {"oM", required_argument, 0, 0}, {"oG", required_argument, 0, 0}, {"oS", required_argument, 0, 0}, {"oH", required_argument, 0, 0}, {"oX", required_argument, 0, 0}, {"iL", required_argument, 0, 'i'}, {"iR", required_argument, 0, 0}, {"sI", required_argument, 0, 0}, {"source_port", required_argument, 0, 'g'}, {"source-port", required_argument, 0, 'g'}, {"randomize_hosts", no_argument, 0, 0}, {"randomize-hosts", no_argument, 0, 0}, {"osscan_limit", no_argument, 0, 0}, /* skip OSScan if no open ports */ {"osscan-limit", no_argument, 0, 0}, /* skip OSScan if no open ports */ {"osscan_guess", no_argument, 0, 0}, /* More guessing flexability */ {"osscan-guess", no_argument, 0, 0}, /* More guessing flexability */ {"fuzzy", no_argument, 0, 0}, /* Alias for osscan_guess */ {"packet_trace", no_argument, 0, 0}, /* Display all packets sent/rcv */ {"packet-trace", no_argument, 0, 0}, /* Display all packets sent/rcv */ {"version_trace", no_argument, 0, 0}, /* Display -sV related activity */ {"version-trace", no_argument, 0, 0}, /* Display -sV related activity */ {"data_length", required_argument, 0, 0}, {"data-length", required_argument, 0, 0}, {"send_eth", no_argument, 0, 0}, {"send-eth", no_argument, 0, 0}, {"send_ip", no_argument, 0, 0}, {"send-ip", no_argument, 0, 0}, {"stylesheet", required_argument, 0, 0}, {"no_stylesheet", no_argument, 0, 0}, {"no-stylesheet", no_argument, 0, 0}, {"webxml", no_argument, 0, 0}, {"rH", no_argument, 0, 0}, {"vv", no_argument, 0, 0}, {"ff", no_argument, 0, 0}, {"privileged", no_argument, 0, 0}, {"unprivileged", no_argument, 0, 0}, {"mtu", required_argument, 0, 0}, {"append_output", no_argument, 0, 0}, {"append-output", no_argument, 0, 0}, {"noninteractive", no_argument, 0, 0}, {"spoof_mac", required_argument, 0, 0}, {"spoof-mac", required_argument, 0, 0}, {"thc", no_argument, 0, 0}, {"badsum", no_argument, 0, 0}, {"ttl", required_argument, 0, 0}, /* Time to live */ {"allports", no_argument, 0, 0}, {"version_intensity", required_argument, 0, 0}, {"version-intensity", required_argument, 0, 0}, {"version_light", no_argument, 0, 0}, {"version-light", no_argument, 0, 0}, {"version_all", no_argument, 0, 0}, {"version-all", no_argument, 0, 0}, {"system_dns", no_argument, 0, 0}, {"system-dns", no_argument, 0, 0}, {"log_errors", no_argument, 0, 0}, {"log-errors", no_argument, 0, 0}, {"dns_servers", required_argument, 0, 0}, {"dns-servers", required_argument, 0, 0}, {"ip_options", required_argument, 0, 0}, {"ip-options", required_argument, 0, 0}, {0, 0, 0, 0} }; /* argv faking silliness */ fakeargv = (char **) safe_malloc(sizeof(char *) * (argc + 1)); for(i=0; i < argc; i++) { fakeargv[i] = strdup(argv[i]); } fakeargv[argc] = NULL; if (argc < 2 ) printusage(argv[0], -1); Targets.reserve(100);#ifdef WIN32 win_pre_init();#endif /* OK, lets parse these args! */ optind = 1; /* so it can be called multiple times */ while((arg = getopt_long_only(argc,fakeargv,"6Ab:D:d::e:Ffg:hIi:M:m:nO::o:P:p:qRrS:s:T:Vv", long_options, &option_index)) != EOF) { switch(arg) { case 0: if (optcmp(long_options[option_index].name, "max-os-tries") == 0) { l = tval2msecs(optarg); if (l < 1 || l > 50) fatal("Bogus --max-os-tries argument specified, must be between 1 and 50 (inclusive)"); o.setMaxOSTries(l); } else if (optcmp(long_options[option_index].name, "max-rtt-timeout") == 0) { l = tval2msecs(optarg); if (l < 5) fatal("Bogus --max-rtt-timeout argument specified, must be at least 5"); if (l < 20) { error("WARNING: You specified a round-trip time timeout (%ld ms) that is EXTRAORDINARILY SMALL. Accuracy may suffer.", l); } pre_max_rtt_timeout = l; } else if (optcmp(long_options[option_index].name, "min-rtt-timeout") == 0) { l = tval2msecs(optarg); if (l < 0) fatal("Bogus --min-rtt-timeout argument specified"); if (l > 50000) { error("Warning: min-rtt-timeout is given in milliseconds, your value seems pretty large."); } pre_min_rtt_timeout = l; } else if (optcmp(long_options[option_index].name, "initial-rtt-timeout") == 0) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?