diff --git a/CHANGELOG b/CHANGELOG index fe19bce1b..9cf27d755 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,14 @@ # Nmap Changelog ($Id$); -*-text-*- +o Made some changes to various Nmap initialization functions which + help ALT Linux (altlinux.org) developers run Nmap in a chroot + environment. Thanks to Dmitry V. Levin (ldv(a)altlinux.org) for the + patch. + +o Cleaned up the code a bit by making a bunch (nearly 100) global + symols (mostly function calls) static. I was also able to removed + some unused functions. Thanks to Dmitry V. Levin (ldv(a)altlinux.org) + for sending a list of candidate symbols. + Nmap 4.02ALPHA1 o Added the --log-errors option, which causes most warnings and error diff --git a/MACLookup.cc b/MACLookup.cc index 451c3fd0a..7ff23b1c2 100644 --- a/MACLookup.cc +++ b/MACLookup.cc @@ -117,8 +117,6 @@ struct MAC_hash_table { struct MAC_entry **table; } MacTable; -static int initialized = 0; - static inline int MacCharPrefix2Key(const u8 *prefix) { return (prefix[0] << 16) + (prefix[1] << 8) + prefix[2]; } @@ -130,7 +128,8 @@ static inline int MACTableHash(int prefix, int table_capacity) { return prefix % table_capacity; } -void InitializeTable() { +void mac_prefix_init() { + static int initialized = 0; if (initialized) return; initialized = 1; char filename[256]; @@ -196,7 +195,7 @@ void InitializeTable() { } -struct MAC_entry *findMACEntry(int prefix) { +static struct MAC_entry *findMACEntry(int prefix) { int pos = MACTableHash(prefix, MacTable.table_capacity); while (MacTable.table[pos]) { @@ -216,7 +215,7 @@ const char *MACPrefix2Corp(const u8 *prefix) { struct MAC_entry *ent; if (!prefix) fatal("MACPrefix2Corp called with a NULL prefix"); - if (!initialized) InitializeTable(); + mac_prefix_init(); ent = findMACEntry(MacCharPrefix2Key(prefix)); return (ent)? ent->vendor : NULL; @@ -231,7 +230,7 @@ const char *MACPrefix2Corp(const u8 *prefix) { bool MACCorp2Prefix(const char *vendorstr, u8 *mac_data) { if (!vendorstr) fatal("%s: vendorstr is NULL", __FUNCTION__); if (!mac_data) fatal("%s: mac_data is NULL", __FUNCTION__); - if (!initialized) InitializeTable(); + mac_prefix_init(); for(int i = 0; i < MacTable.table_capacity; i++ ) { if (MacTable.table[i]) diff --git a/charpool.cc b/charpool.cc index 87df1c75f..be470c98a 100644 --- a/charpool.cc +++ b/charpool.cc @@ -107,11 +107,13 @@ static char *charpool[16]; static int currentcharpool; static int currentcharpoolsz; static char *nextchar; -static int charpool_initialized = 0; #define ALIGN_ON sizeof(char *) static int cp_init(void) { + static int charpool_initialized = 0; + if (charpool_initialized) return 0; + /* Create our char pool */ currentcharpool = 0; currentcharpoolsz = 16384; @@ -135,7 +137,7 @@ void *cp_alloc(int sz) { char *p; int modulus; - if (!charpool_initialized) cp_init(); + cp_init(); if ((modulus = sz % ALIGN_ON)) sz += ALIGN_ON - modulus; @@ -159,8 +161,7 @@ char *q; char *end; int modulus; - if (!charpool_initialized) - cp_init(); + cp_init(); end = charpool[currentcharpool] + currentcharpoolsz; q = nextchar; diff --git a/idle_scan.cc b/idle_scan.cc index a5c09a1bd..6e349bd7c 100644 --- a/idle_scan.cc +++ b/idle_scan.cc @@ -154,7 +154,7 @@ struct idle_proxy_info { Proxy timing is adjusted, but proxy->latestid is NOT ADJUSTED -- you'll have to do that yourself. Probes_sent is set to the number of probe packets sent during execution */ -int ipid_proxy_probe(struct idle_proxy_info *proxy, int *probes_sent, +static int ipid_proxy_probe(struct idle_proxy_info *proxy, int *probes_sent, int *probes_rcvd) { struct timeval tv_end; int tries = 0; @@ -248,7 +248,7 @@ int ipid_proxy_probe(struct idle_proxy_info *proxy, int *probes_sent, one, assuming the given IPID Sequencing class. Returns -1 if the distance cannot be determined */ -int ipid_distance(int seqclass , u16 startid, u16 endid) { +static int ipid_distance(int seqclass , u16 startid, u16 endid) { if (seqclass == IPID_SEQ_INCR) return endid - startid; @@ -279,7 +279,7 @@ static void initialize_proxy_struct(struct idle_proxy_info *proxy) { proxy is determined to be unsuitable, the function whines and exits the program */ #define NUM_IPID_PROBES 6 -void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, +static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, const struct in_addr *first_target) { int probes_sent = 0, probes_returned = 0; int hardtimeout = 9000000; /* Generally don't wait more than 9 secs total */ @@ -378,7 +378,7 @@ void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, proxy->ethptr = &proxy->eth; } else { if ((proxy->rawsd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0 ) - pfatal("socket trobles in get_fingerprint"); + pfatal("socket trobles in %s", __FUNCTION__); unblock_socket(proxy->rawsd); broadcast_socket(proxy->rawsd); #ifndef WIN32 @@ -560,7 +560,7 @@ void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, count of 'testcount' while the 'realcount' is as given. If the testcount was correct, timing is made more aggressive, while it is slowed down in the case of an error */ -void adjust_idle_timing(struct idle_proxy_info *proxy, +static void adjust_idle_timing(struct idle_proxy_info *proxy, Target *target, int testcount, int realcount) { @@ -622,7 +622,7 @@ void adjust_idle_timing(struct idle_proxy_info *proxy, They can be NULL if you don't want to use them. The purpose is for timing adjustments if the numbers turn out to be accurate */ -int idlescan_countopen2(struct idle_proxy_info *proxy, +static int idlescan_countopen2(struct idle_proxy_info *proxy, Target *target, u16 *ports, int numports, struct timeval *sent_time, struct timeval *rcv_time) { @@ -777,7 +777,7 @@ int idlescan_countopen2(struct idle_proxy_info *proxy, /* The job of this function is to use the Idlescan technique to count the number of open ports in the given list. Under the covers, this function just farms out the hard work to another function */ -int idlescan_countopen(struct idle_proxy_info *proxy, +static int idlescan_countopen(struct idle_proxy_info *proxy, Target *target, u16 *ports, int numports, struct timeval *sent_time, struct timeval *rcv_time) { int tries = 0; @@ -818,7 +818,7 @@ int idlescan_countopen(struct idle_proxy_info *proxy, /* Recursively Idlescans scans a group of ports using a depth-first divide-and-conquer strategy to find the open one(s) */ -int idle_treescan(struct idle_proxy_info *proxy, Target *target, +static int idle_treescan(struct idle_proxy_info *proxy, Target *target, u16 *ports, int numports, int expectedopen) { int firstHalfSz = (numports + 1)/2; diff --git a/nmap.cc b/nmap.cc index ce2d4adeb..61c4136d8 100644 --- a/nmap.cc +++ b/nmap.cc @@ -192,6 +192,240 @@ static int parse_bounce_argument(struct ftpinfo *ftp, char *url) { 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 : Input from list of hosts/networks\n" + " -iR : Choose random targets\n" + " --exclude : Exclude hosts/networks\n" + " --excludefile : 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" + " -P0: 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" + " -n/-R: Never do DNS resolution/Always resolve [default: sometimes]\n" + " --dns-servers : 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" + " -sN/sF/sX: TCP Null, FIN, and Xmas scans\n" + " --scanflags : Customize TCP scan flags\n" + " -sI : Idlescan\n" + " -sO: IP protocol scan\n" + " -b : FTP bounce scan\n" + "PORT SPECIFICATION AND SCAN ORDER:\n" + " -p : Only scan specified ports\n" + " Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080\n" + " -F: Fast - Scan only the ports listed in the nmap-services file)\n" + " -r: Scan ports consecutively - don't randomize\n" + "SERVICE/VERSION DETECTION:\n" + " -sV: Probe open ports to determine service/version info\n" + " --version-intensity : 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" + "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