home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / nmap254b.zip / global_structures.h < prev    next >
C/C++ Source or Header  |  2001-08-10  |  11KB  |  307 lines

  1.  
  2. /***********************************************************************/
  3. /* global_structures.h -- Common structure definitions used by Nmap    */
  4. /* components.                                                         */
  5. /*                                                                     */
  6. /***********************************************************************/
  7. /*  The Nmap Security Scanner is (C) 1995-2001 Insecure.Com LLC. This  */
  8. /*  program is free software; you can redistribute it and/or modify    */
  9. /*  it under the terms of the GNU General Public License as published  */
  10. /*  by the Free Software Foundation; Version 2.  This guarantees your  */
  11. /*  right to use, modify, and redistribute this software under certain */
  12. /*  conditions.  If this license is unacceptable to you, we may be     */
  13. /*  willing to sell alternative licenses (contact sales@insecure.com). */
  14. /*                                                                     */
  15. /*  If you received these files with a written license agreement       */
  16. /*  stating terms other than the (GPL) terms above, then that          */
  17. /*  alternative license agreement takes precendence over this comment. */
  18. /*                                                                     */
  19. /*  Source is provided to this software because we believe users have  */
  20. /*  a right to know exactly what a program is going to do before they  */
  21. /*  run it.  This also allows you to audit the software for security   */
  22. /*  holes (none have been found so far).                               */
  23. /*                                                                     */
  24. /*  Source code also allows you to port Nmap to new platforms, fix     */
  25. /*  bugs, and add new features.  You are highly encouraged to send     */
  26. /*  your changes to fyodor@insecure.org for possible incorporation     */
  27. /*  into the main distribution.  By sending these changes to Fyodor or */
  28. /*  one the insecure.org development mailing lists, it is assumed that */
  29. /*  you are offering Fyodor the unlimited, non-exclusive right to      */
  30. /*  reuse, modify, and relicense the code.  This is important because  */
  31. /*  the inability to relicense code has caused devastating problems    */
  32. /*  for other Free Software projects (such as KDE and NASM).  Nmap     */
  33. /*  will always be available Open Source.  If you wish to specify      */
  34. /*  special license conditions of your contributions, just say so      */
  35. /*  when you send them.                                                */
  36. /*                                                                     */
  37. /*  This program is distributed in the hope that it will be useful,    */
  38. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of     */
  39. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  */
  40. /*  General Public License for more details (                          */
  41. /*  http://www.gnu.org/copyleft/gpl.html ).                            */
  42. /*                                                                     */
  43. /***********************************************************************/
  44.  
  45. /* $Id: global_structures.h,v 1.34 2001/08/10 05:53:07 fyodor Exp $ */
  46.  
  47.  
  48. #ifndef GLOBAL_STRUCTURES_H
  49. #define GLOBAL_STRUCTURES_H
  50.  
  51. /* Stores "port info" which is TCP/UDP ports or RPC program ids */
  52. struct portinfo {
  53.    unsigned long portno; /* TCP/UDP port or RPC program id or IP protocool */
  54.    short trynum;
  55.    int sd[3]; /* Socket descriptors for connect_scan */
  56.    struct timeval sent[3]; 
  57.    int state;
  58.    int next; /* not struct portinfo * for historical reasons */
  59.    int prev;
  60. };
  61.  
  62. struct portinfolist {
  63.    struct portinfo *openlist;
  64.    struct portinfo *firewalled;
  65.    struct portinfo *testinglist;
  66. };
  67.  
  68. struct udpprobeinfo {
  69.   u16 iptl;
  70.   u16 ipid;
  71.   u16 ipck;
  72.   u16 sport;
  73.   u16 dport;
  74.   u16 udpck;
  75.   u16 udplen;
  76.   u8 patternbyte;
  77.   struct in_addr target;
  78. };
  79.  
  80. struct connectsockinfo {
  81.   fd_set fds_read;
  82.   fd_set fds_write;
  83.   fd_set fds_except;
  84.   struct portinfo *socklookup[2048]; /* index socket descriptor -> scan[] 
  85.                     index.  No OS better give us
  86.                     an SD > 2047!@#$ */
  87.   int maxsd;
  88. };
  89.  
  90. struct firewallmodeinfo {
  91.   int active; /* is firewall mode currently active for the host? */
  92.   int nonresponsive_ports; /* # Of ports we haven't received any response from */
  93.   int responsive_ports; /* # of ports that told us whether they were open/closed/filtered/unfiltered */
  94. };
  95.  
  96. /* The runtime statistics used to decide how fast to proced and how
  97.    many ports we can try at once */
  98. struct scanstats {
  99.   int packet_incr;
  100.   double fallback_percent;
  101.   int numqueries_outstanding; /* How many unexpired queries are on the 'net
  102.                  right now? */
  103.   double numqueries_ideal; /* How many do we WANT to be on the 'net right now? */
  104.   int max_width; /* What is the MOST we will tolerate at once */
  105.   int ports_left;
  106.   int changed; /* Has anything changed since last round? */
  107.   int alreadydecreasedqueries;
  108. };
  109.  
  110. struct ftpinfo {
  111.   char user[64];
  112.   char pass[256]; /* methinks you're paranoid if you need this much space */
  113.   char server_name[MAXHOSTNAMELEN + 1];
  114.   struct in_addr server;
  115.   u16 port;
  116.   int sd; /* socket descriptor */
  117. };
  118.  
  119. struct AVal {
  120.   char *attribute;
  121.   char value[128];
  122.   struct AVal *next;
  123. };
  124.  
  125. typedef struct FingerTest {
  126.   char OS_name[256];
  127.   const char *name;
  128.   struct AVal *results;
  129.   struct FingerTest *next;
  130.  } FingerPrint;
  131.  
  132. /* Maximum number of results allowed in one of these things ... */
  133. #define MAX_FP_RESULTS 8
  134. struct FingerPrintResults {
  135.   double accuracy[MAX_FP_RESULTS]; /* Percentage of match (1.0 == perfect 
  136.                       match) in same order as pritns[] below */
  137.   FingerPrint *prints[MAX_FP_RESULTS]; /* ptrs to matching references -- 
  138.                           highest accuracy matches first */
  139.   int num_perfect_matches; /* Number of 1.0 accuracy matches in prints[] */
  140.   int num_matches; /* Total number of matches in prints */
  141.   int overall_results; /* OSSCAN_TOOMANYMATCHES, OSSCAN_NOMATCHES, 
  142.               OSSCAN_SUCCESS, etc */
  143. };
  144.  
  145. struct timeout_info {
  146.   int srtt; /* Smoothed rtt estimate (microseconds) */
  147.   int rttvar; /* Rout trip time variance */
  148.   int timeout; /* Current timeout threshold (microseconds) */
  149. };
  150.  
  151. struct seq_info {
  152.   int responses;
  153.   int seqclass; /* SEQ_* defines in nmap.h */
  154.   int ts_seqclass; /* TS_SEQ_* defines in nmap.h */
  155.   time_t uptime; /* time of latest system boot (or 0 if unknown ) */
  156.   int ipid_seqclass; /* IPID_SEQ_* defines in nmap.h */
  157.   u32 seqs[NUM_SEQ_SAMPLES];
  158.   u32 timestamps[NUM_SEQ_SAMPLES];
  159.   int index;
  160.   u16 ipids[NUM_SEQ_SAMPLES];
  161.   time_t lastboot; /* 0 means unknown */
  162. };
  163.  
  164. struct targets {
  165.   /* These 4 are used for the '/mask' style of specifying target net*/
  166.   u32 netmask;
  167.   unsigned int maskformat;
  168.   struct in_addr start;
  169.   struct in_addr currentaddr;
  170.   struct in_addr end;
  171.   /* These two are for the '138.[1-7,16,91-95,200-].12.1 style */
  172.   u8 addresses[4][256];
  173.   unsigned int current[4];
  174.   u8 last[4];  
  175.   int nleft; /* Number of IPs left in this structure -- set to 0 if 
  176.         the fields are not valid */
  177. };
  178.  
  179.  
  180. struct hoststruct {
  181.   struct in_addr host;
  182.   struct in_addr source_ip;
  183.   char *name;
  184.   struct seq_info seq;
  185.   struct FingerPrintResults FPR;
  186.   FingerPrint *FPs[10]; /* Fingerprint data obtained from host */
  187.   int osscan_performed; /* nonzero if an osscan was performed */
  188.   int osscan_openport; /* Open port used for scannig (if one found -- 
  189.               otherwise -1) */
  190.   int osscan_closedport; /* Closed port used for scannig (if one found -- 
  191.                 otherwise -1) */
  192.   int numFPs;
  193.   int goodFP;
  194.   portlist ports;
  195.   /*
  196.   unsigned int up;
  197.   unsigned int down; */
  198.   int wierd_responses; /* echo responses from other addresses, Ie a network broadcast address */
  199.   unsigned int flags; /* HOST_UP, HOST_DOWN, HOST_FIREWALLED, HOST_BROADCAST (instead of HOST_BROADCAST use wierd_responses */
  200.   struct timeout_info to;
  201.   struct timeval host_timeout;
  202.   struct firewallmodeinfo firewallmode; /* For supporting "firewall mode" speed optimisations */
  203.   int timedout; /* Nonzero if continued scanning should be aborted due to
  204.            timeout  */
  205.   char device[64]; /* The device we transmit on */
  206. };
  207.  
  208. struct hostgroup_state {
  209.   struct hoststruct *hostbatch;
  210.   int max_batch_sz; /* The size of the hostbatch[] array */
  211.   int current_batch_sz; /* The number of VALID members of hostbatch[] */
  212.   int next_batch_no; /* The index of the next hostbatch[] member to be given 
  213.             back to the user */
  214.   int randomize; /* Whether each bach should be "shuffled" prior to the ping 
  215.             scan (they will also be out of order when given back one
  216.             at a time to the client program */
  217.   char **target_expressions; /* An array of target expression strings, passed
  218.                 to us by the client (client is also in charge
  219.                 of deleting it AFTER it is done with the 
  220.                 hostgroup_state */
  221.   int num_expressions;       /* The number of valid expressions in 
  222.                 target_expressions member above */
  223.   int next_expression;   /* The index of the next expression we have
  224.                 to handle */
  225.   struct targets current_expression; /* For batch chunking */
  226. };
  227.  
  228. struct ops /* someone took struct options, <grrr> */ {
  229.   int debugging;
  230.   int verbose;
  231.   int randomize_hosts;
  232.   int spoofsource; /* -S used */
  233.   struct in_addr *source;
  234.   char device[64];
  235.   int interactivemode;
  236.   int host_group_sz;
  237.   int generate_random_ips; /* -iR option */
  238.   FingerPrint **reference_FPs;
  239.   u16 magic_port;
  240.   unsigned short magic_port_set; /* Was this set by user? */
  241.   u16 tcp_probe_port;
  242.  
  243.   /* Scan timing/politeness issues */
  244.   int max_parallelism;
  245.   int max_rtt_timeout;
  246.   int min_rtt_timeout;
  247.   int extra_payload_length; /* These two are for --data_length op */
  248.   char *extra_payload;
  249.   unsigned long host_timeout;
  250.   int scan_delay;
  251.   int initial_rtt_timeout;
  252.   struct in_addr resume_ip; /* The last IP in the log file if user 
  253.                    requested --restore .  Otherwise 
  254.                    restore_ip.s_addr == 0.  Also 
  255.                    target_struct_get will eventually set it 
  256.                    to 0. */
  257.   int isr00t;
  258.   struct in_addr decoys[MAX_DECOYS];
  259.   int osscan_limit; /* Skip OS Scan if no open or no closed TCP ports */
  260.   int osscan_guess;   /* Be more aggressive in guessing OS type */
  261.   int numdecoys;
  262.   int decoyturn;
  263.   int identscan;
  264.   int osscan;
  265.   int pingtype;
  266.   int listscan;
  267.   int pingscan;
  268.   int allowall;
  269.   int ackscan;
  270.   int bouncescan;
  271.   int connectscan;
  272.   int rpcscan;
  273.   int nullscan;
  274.   int xmasscan;
  275.   int fragscan;
  276.   int synscan;
  277.   int windowscan;
  278.   int maimonscan;
  279.   int idlescan;
  280.   int finscan;
  281.   int udpscan;
  282.   int ipprotscan;
  283.   int noresolve;
  284.   int force; /* force nmap to continue on even when the outcome seems somewhat certain */
  285.   int append_output; /* Append to any output files rather than overwrite */
  286.   FILE *logfd[LOG_TYPES];
  287.   FILE *nmap_stdout; /* Nmap standard output */
  288. };
  289.   
  290.  
  291. /* The various kinds of port/protocol scans we can have
  292.  * Each element is to point to an array of port/protocol numbers
  293.  */
  294. struct scan_lists {
  295.     unsigned short *tcp_ports;
  296.     int tcp_count;
  297.     unsigned short *udp_ports;
  298.     int udp_count;
  299.     unsigned short *prots;
  300.     int prot_count;
  301. };
  302.  
  303.  
  304. typedef enum { ACK_SCAN, SYN_SCAN, FIN_SCAN, XMAS_SCAN, UDP_SCAN, CONNECT_SCAN, NULL_SCAN, WINDOW_SCAN, RPC_SCAN, MAIMON_SCAN, IPPROT_SCAN } stype;
  305.  
  306. #endif /*GLOBAL_STRUCTURES_H */
  307.