home *** CD-ROM | disk | FTP | other *** search
/ Steganos Hacker Tools / SHT151.iso / programme / scanner / nmapNTsp1 / Win_2000.exe / nmapNT-src / nmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-12  |  11.9 KB  |  385 lines

  1. #ifndef NMAP_H
  2. #define NMAP_H
  3.  
  4. /************************INCLUDES**********************************/
  5. #ifdef WIN32
  6. #include <winclude.h>
  7. #endif
  8.  
  9. #ifdef HAVE_CONFIG_H
  10. #include "config.h"
  11. #endif
  12.  
  13. #include <unistd.h>
  14. #ifdef HAVE_GETOPT_H
  15. #include <getopt.h>
  16. #else
  17. /* The next half-dozen lines are from gcc-2.95 ... -Fyodor */
  18. /* Include getopt.h for the sake of getopt_long.
  19.    We don't need the declaration of getopt, and it could conflict
  20.    with something from a system header file, so effectively nullify that.  */
  21. #define getopt getopt_loser
  22. #include "getopt.h"
  23. #undef getopt
  24. #endif
  25.  
  26. #ifdef STDC_HEADERS
  27. #include <stdlib.h>
  28. #else
  29. void *malloc();
  30. void *realloc();
  31. #endif
  32.  
  33. #if STDC_HEADERS || HAVE_STRING_H
  34. #include <string.h>
  35. #if !STDC_HEADERS && HAVE_MEMORY_H
  36. #include <memory.h>
  37. #endif
  38. #endif
  39. #if HAVE_STRINGS_H
  40. #include <strings.h>
  41. #endif
  42.  
  43. #ifdef HAVE_BSTRING_H
  44. #include <bstring.h>
  45. #endif
  46.  
  47.  
  48. #ifndef HAVE_BZERO
  49. #define bzero(s, n) memset((s), 0, (n))
  50. #endif
  51. #ifndef WIN32
  52. #ifndef HAVE_MEMCPY
  53. #define memcpy(d, s, n) bcopy((s), (d), (n))
  54. #endif
  55. #endif
  56.  
  57. #include <ctype.h>
  58. #include <sys/types.h>
  59.  
  60. #ifndef WIN32
  61. #include <sys/wait.h>
  62.  
  63. #ifdef HAVE_SYS_PARAM_H   
  64. #include <sys/param.h> /* Defines MAXHOSTNAMELEN on BSD*/
  65. #endif
  66.  
  67. /* Linux uses these defines in netinet/ip.h and netinet/tcp.h to
  68.    use the correct struct ip and struct tcphdr */
  69. #ifndef __FAVOR_BSD
  70. #define __FAVOR_BSD
  71. #endif
  72. #ifndef __USE_BSD
  73. #define __USE_BSD
  74. #endif
  75. #ifndef __BSD_SOURCE
  76. #define __BSD_SOURCE
  77. #endif
  78.  
  79. /* BSDI needs this to insure the correct struct ip */
  80. #undef _IP_VHL
  81.  
  82. #if HAVE_STRINGS_H
  83. #include <strings.h>
  84. #endif
  85.  
  86. #include <stdio.h>
  87. #include <rpc/types.h>
  88. #include <sys/socket.h>
  89. #include <sys/socket.h> 
  90. #include <sys/stat.h>
  91. #include <netinet/in.h>
  92. #include <errno.h>
  93. #include <netdb.h>
  94.  
  95. #if TIME_WITH_SYS_TIME
  96. # include <sys/time.h>
  97. # include <time.h>
  98. #else
  99. # if HAVE_SYS_TIME_H
  100. #  include <sys/time.h>
  101. # else
  102. #  include <time.h>
  103. # endif
  104. #endif
  105.  
  106. #include <fcntl.h>
  107. #include <signal.h> 
  108. #include <signal.h>
  109. #include <stdarg.h>
  110. #include <pwd.h>
  111. #ifndef NETINET_IN_SYSTEM_H  /* why the HELL does OpenBSD not do this? */
  112. #include <netinet/in_systm.h> /* defines n_long needed for netinet/ip.h */
  113. #define NETINET_IN_SYSTEM_H
  114. #endif
  115. #ifndef NETINET_IP_H  /* why the HELL does OpenBSD not do this? */
  116. #include <netinet/ip.h> 
  117. #define NETINET_IP_H
  118. #endif
  119. #include <netinet/ip_icmp.h> 
  120. #include <arpa/inet.h>
  121. #include <math.h>
  122. #include <assert.h>
  123. #ifndef __FAVOR_BSD
  124. #define __FAVOR_BSD
  125. #endif
  126. #ifndef NETINET_TCP_H  /* why the HELL does OpenBSD not do this? */
  127. #include <netinet/tcp.h>          /*#include <netinet/ip_tcp.h>*/
  128. #define NETINET_TCP_H
  129. #endif
  130. #include <sys/resource.h>
  131. /*#include <net/if_arp.h> *//* defines struct arphdr needed for if_ether.h */
  132. #ifndef NET_IF_H  /* why the HELL does OpenBSD not do this? */
  133. #include <net/if.h>
  134. #define NET_IF_H
  135. #endif
  136. #if HAVE_NETINET_IF_ETHER_H 
  137. #ifndef NETINET_IF_ETHER_H
  138. #include <netinet/if_ether.h>
  139. #define NETINET_IF_ETHER_H
  140. #endif /* NETINET_IF_ETHER_H */
  141. #endif /* HAVE_NETINET_IF_ETHER_H */
  142.  
  143. #if !HAVE_VSNPRINTF
  144. #define vsnprintf(str, n, format, ap) vsprintf(str, format, ap)
  145. #endif
  146. #endif
  147.  
  148. /*******  DEFINES  ************/
  149.  
  150. /* User configurable #defines: */
  151. #ifndef VERSION
  152. #define VERSION "1.60-Beta"
  153. #endif
  154. #ifndef DEBUGGING
  155. #define DEBUGGING 0
  156. #endif
  157. /* Default number of ports in parallel.  Doesn't always involve actual 
  158.    sockets.  Can also adjust with the -M command line option.  */
  159. #define MAX_SOCKETS 36 
  160. /* As an optimisation we limit the maximum value of MAX_SOCKETS to a very
  161.    high value (avoids dynamic memmory allocation */
  162. #define MAX_SOCKETS_ALLOWED 1025
  163. /* How many hosts do we ping in parallel to see if they are up? */
  164. #define LOOKAHEAD 25
  165. /* If reads of a UDP port keep returning EAGAIN (errno 13), do we want to 
  166.    count the port as valid? */
  167. #define RISKY_UDP_SCAN 0
  168. /* How many syn packets do we send to TCP sequence a host? */
  169. #define NUM_SEQ_SAMPLES 6
  170.  /* This ideally should be a port that isn't in use for any protocol on our machine or on the target */ 
  171. #define MAGIC_PORT 49724
  172. /* How many udp sends without a ICMP port unreachable error does it take before we consider the port open? */
  173. #define UDP_MAX_PORT_RETRIES 4
  174.  /*How many seconds before we give up on a host being alive? */
  175.  
  176. #define FAKE_ARGV "pine" /* What ps and w should show if you use -q */
  177. /* How do we want to log into ftp sites for */ 
  178. #define FTPUSER "anonymous"
  179. #define FTPPASS "-wwwuser@"
  180. #define FTP_RETRIES 2 /* How many times should we relogin if we lose control
  181.                          connection? */
  182. #define MAX_TIMEOUTS MAX_SOCKETS   /* How many timed out connection attempts 
  183.                       in a row before we decide the host is 
  184.                       dead? */
  185. #define MAX_DECOYS 128 /* How many decoys are allowed? */
  186.  
  187. #ifndef MAX_RTT_TIMEOUT
  188. #define MAX_RTT_TIMEOUT 10000 /* Never allow more than 10 secs for packet round
  189.                  trip */
  190. #endif
  191.  
  192. #ifndef MIN_RTT_TIMEOUT
  193. #define MIN_RTT_TIMEOUT 300 /* We will always wait at least 300 ms for a response */
  194. #endif
  195.  
  196. #define INITIAL_RTT_TIMEOUT 6000 /* Allow 6 seconds at first for packet responses */
  197. #define HOST_TIMEOUT    0 /* By default allow unlimited time to scan each host */
  198.  
  199. /* If nmap is called with one of the names below, it will start up in interactive mode -- alternatively, you can rename Nmap any of the following names to have it start up interactivey by default.  */
  200. #define INTERACTIVE_NAMES { "BitchX", "Calendar", "X", "awk", "bash", "bash2", "calendar", "cat", "csh", "elm", "emacs", "ftp", "fvwm", "g++", "gcc", "gimp", "httpd", "irc", "man", "mutt", "nc", "ncftp", "netscape", "perl", "pine", "ping", "sleep", "slirp", "ssh", "sshd", "startx", "tcsh", "telnet", "telnetd", "tia", "top", "vi", "vim", "xdvi", "xemacs", "xterm", "xv" }
  201.  
  202. /* Number of hosts we pre-ping and then scan.  We do a lot more if
  203.    randomize_hosts is set.  Every one you add to this leads to ~1K of
  204.    extra always-resident memory in nmap */
  205. #define HOST_GROUP_SZ 256
  206.  
  207. /* DO NOT change stuff after this point */
  208. #define UC(b)   (((int)b)&0xff)
  209. #define SA    struct sockaddr  /*Ubertechnique from R. Stevens */
  210. /*#define fatal(x) { fprintf(stderr, "%s\n", x); exit(-1); }
  211.   #define error(x) fprintf(stderr, "%s\n", x);*/
  212. /* hoststruct->flags stuff */
  213. #define HOST_UP 1
  214. #define HOST_DOWN 2 
  215. #define HOST_FIREWALLED 4 
  216. #define HOST_BROADCAST 8 /* use the wierd_responses member of hoststruct instead */
  217.  
  218. #define PINGTYPE_UNKNOWN 0
  219. #define PINGTYPE_NONE 1
  220. #define PINGTYPE_ICMP 2
  221. #define PINGTYPE_TCP  4
  222. #define PINGTYPE_TCP_USE_ACK 8
  223. #define PINGTYPE_TCP_USE_SYN 16
  224. #define PINGTYPE_RAWTCP 32
  225. #define PINGTYPE_CONNECTTCP 64
  226.  
  227. #define SEQ_UNKNOWN 0
  228. #define SEQ_64K 1
  229. #define SEQ_TD 2
  230. #define SEQ_RI 4
  231. #define SEQ_TR 8
  232. #define SEQ_i800 16
  233. #define SEQ_CONSTANT 32
  234.  
  235. #ifndef MAXHOSTNAMELEN
  236. #define MAXHOSTNAMELEN 64
  237. #endif
  238.  
  239. #ifndef BSDFIX
  240. #if FREEBSD || BSDI || NETBSD
  241. #define BSDFIX(x) x
  242. #define BSDUFIX(x) x
  243. #else
  244. #define BSDFIX(x) htons(x)
  245. #define BSDUFIX(x) ntohs(x)
  246. #endif
  247. #endif /* BSDFIX */
  248.  
  249. #define LOG_TYPES 4
  250. #define LOG_MASK 15
  251. #define LOG_NORMAL 1
  252. #define LOG_MACHINE 2
  253. #define LOG_HTML 4
  254. #define LOG_SKID 8
  255. #define LOG_STDOUT 1024
  256. #define LOG_SKID_NOXLT 2048
  257.  
  258. #define LOG_NAMES {"normal", "machine", "HTML", "$Cr!pT |<!dd!3"}
  259. /********************** LOCAL INCLUDES *****************************/
  260.  
  261. #include "portlist.h"
  262. #include "tcpip.h"
  263. #include "global_structures.h"
  264. #include "error.h"
  265. #include "utils.h"
  266. #include "services.h"
  267. #include "rpc.h"
  268. #include "targets.h"
  269.  
  270. /***********************STRUCTURES**********************************/
  271.  
  272. /* Moved to global_structures.h */
  273.  
  274. /***********************PROTOTYPES**********************************/
  275.  
  276. /* print usage information and exit */
  277. void printusage(char *name, int rc);
  278. /* print Interactive usage information */
  279. void printinteractiveusage();
  280.  
  281. /* our scanning functions */
  282. void super_scan(struct hoststruct *target, unsigned short *portarray, 
  283.         stype scantype);
  284. void pos_scan(struct hoststruct *target, unsigned short *portarray, 
  285.           stype scantype);
  286. void bounce_scan(struct hoststruct *target, unsigned short *portarray,
  287.              struct ftpinfo *ftp);
  288.  
  289. /* Scan helper functions */
  290. unsigned long calculate_sleep(struct in_addr target);
  291. int check_ident_port(struct in_addr target);
  292. int getidentinfoz(struct in_addr target, int localport, int remoteport,
  293.           char *owner);
  294. int parse_bounce(struct ftpinfo *ftp, char *url);
  295. int ftp_anon_connect(struct ftpinfo *ftp);
  296. /* Does the appropriate stuff when the port we are looking at is found
  297.    to be open trynum is the try number that was successful */
  298. void posportupdate(struct hoststruct *target, struct portinfo *current, 
  299.            int trynum, struct portinfo *scan,
  300.            struct scanstats *ss ,stype scantype, int newstate,
  301.            struct portinfolist *pil, struct connectsockinfo *csi);
  302. void get_syn_results(struct hoststruct *target, struct portinfo *scan,
  303.              struct scanstats *ss, struct portinfolist *pil, 
  304.              int *portlookup, pcap_t *pd, unsigned long *sequences, stype scantype);
  305. int get_connect_results(struct hoststruct *target, struct portinfo *scan, 
  306.              struct scanstats *ss, struct portinfolist *pil, 
  307.              int *portlookup, unsigned long *sequences, 
  308.              struct connectsockinfo *csi);
  309. inline void adjust_timeouts(struct timeval sent, struct timeout_info *to);
  310. /* port manipulators */
  311. unsigned short *getpts(char *expr); /* someone stole the name getports()! */
  312.  
  313. void printportoutput(struct hoststruct *currenths, portlist *plist);
  314.  
  315. /* socket manipulation functions */
  316. void init_socket(int sd);
  317. int unblock_socket(int sd);
  318. int block_socket(int sd);
  319. void broadcast_socket(int sd);
  320. int recvtime(int sd, char *buf, int len, int seconds);
  321. void max_rcvbuf(int sd);
  322. int max_sd();
  323. int log_open(int logt, int append, char *filename);
  324. /* RAW packet building/dissasembling stuff */
  325. int isup(struct in_addr target);
  326. int listen_icmp(int icmpsock, unsigned short outports[],
  327.         unsigned short numtries[], int *num_out,
  328.         struct in_addr target, portlist *ports);
  329.  
  330. /* Renamed main so that interactive mode could preprocess when neccessary */
  331. int nmap_main(int argc, char *argv[]);
  332.  
  333. /* general helper functions */
  334. void hdump(unsigned char *packet, int len);
  335. void *safe_malloc(int size);
  336. char *grab_next_host_spec(FILE *inputfd, int argc, char **fakeargv);
  337. int parse_targets(struct targets *targets, char *h);
  338. void options_init();
  339. void nmap_log(char *fmt, ...);
  340. void nmap_machine_log(char *fmt, ...);
  341. char *statenum2str(int state);
  342. void sigdie(int signo);
  343. void reaper(int signo);
  344. char *seqreport(struct seq_info *seq);
  345. char *seqclass2ascii(int clas);
  346. int nmap_fetchfile(char *filename_returned, int bufferlen, char *file);
  347. int fileexistsandisreadable(char *pathname);
  348. void enforce_scan_delay(struct timeval *tv);
  349. int check_firewallmode(struct hoststruct *target, struct scanstats *ss);
  350. int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv);
  351.  
  352. /* The items in ports should be
  353.    in sequential order for space savings and easier to read output */
  354. void output_rangelist_given_ports_to_machine_output(unsigned short *ports,
  355.                             int numports);
  356. /* Output the list of ports scanned to the top of machine parseable
  357.    logs (in a comment, unfortunately).  The items in ports should be
  358.    in sequential order for space savings and easier to read output */
  359. void output_ports_to_machine_parseable_output(unsigned short *ports, 
  360.                           int numports, int tcpscan, 
  361.                           int udpscan);
  362.  
  363. void log_write(int logt, char *fmt, ...);
  364. void log_close(int logt);
  365. void log_flush(int logt);
  366. void log_flush_all();
  367. void skid_output(unsigned char *s);
  368.  
  369. /* From glibc 2.0.6 because Solaris doesn't seem to have this function */
  370. #ifndef HAVE_INET_ATON
  371. int inet_aton(register const char *, struct in_addr *);
  372. #endif
  373. #ifndef HAVE_SNPRINTF
  374. int snprintf ( char *str, size_t n, const char *format, ... );
  375. #endif
  376. #endif /* NMAP_H */
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.