00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef osfinger_h
00014 #define osfinger_h
00015
00016 #include "util.h"
00017 #include "Dict.h"
00018
00019
00020
00021 #define PACKET_BIG 100
00022
00023
00024 #define MAXSIGS 1024
00025
00026
00027 #define MAXLINE 1024
00028
00029
00030
00031
00032 #define MAXDIST 40
00033
00034
00035
00036
00037
00038 #define MAXOPT 64
00039
00040 declare(PDict,int);
00041
00042 struct os_type {
00043 char* os;
00044 char* desc;
00045 uint8 dist;
00046 uint16 gadgets;
00047 uint16 match;
00048 uint32 uptime;
00049 };
00050
00051 struct fp_entry {
00052 struct fp_entry* next;
00053 char* os;
00054 char* desc;
00055 uint8 no_detail;
00056 uint8 generic;
00057 uint8 userland;
00058 uint16 wsize;
00059 uint8 wsize_mod;
00060 uint8 ttl;
00061 uint8 df;
00062 uint8 zero_stamp;
00063 uint16 size;
00064 uint8 optcnt;
00065 uint8 opt[MAXOPT];
00066 uint16 wsc;
00067 uint16 mss;
00068 uint8 wsc_mod;
00069 uint8 mss_mod;
00070 uint32 quirks;
00071 uint32 line;
00072 };
00073
00074 struct mtu_def {
00075 uint16 mtu;
00076 char* dev;
00077 };
00078
00079 enum FingerprintMode {
00080 SYN_FINGERPRINT_MODE, SYN_ACK_FINGERPRINT_MODE, RST_FINGERPRINT_MODE,
00081 };
00082
00083 class OSFingerprint {
00084 public:
00085 OSFingerprint(FingerprintMode mode);
00086 ~OSFingerprint() {}
00087
00088 bool Error() const { return err; }
00089
00090 int FindMatch(struct os_type* retval, uint16 tot, uint8 DF_flag,
00091 uint8 TTL, uint16 WSS, uint8 ocnt, uint8* op, uint16 MSS,
00092 uint8 win_scale, uint32 tstamp, uint32 quirks, uint8 ECN) const;
00093 bool CacheMatch(uint32 addr, int id);
00094
00095 int Get_OS_From_SYN(struct os_type* retval,
00096 uint16 tot, uint8 DF_flag, uint8 TTL, uint16 WSS,
00097 uint8 ocnt, uint8* op, uint16 MSS, uint8 win_scale,
00098 uint32 tstamp, uint32 quirks,
00099 uint8 ecn) const;
00100
00101 void load_config(char* file);
00102
00103 protected:
00104 void collide(uint32 id);
00105
00106 void Error(const char* msg)
00107 {
00108 error(msg);
00109 err = true;
00110 }
00111
00112 void Error(const char* msg, int n)
00113 {
00114 error(msg, n);
00115 err = true;
00116 }
00117
00118 void Error(const char* msg, const char* s)
00119 {
00120 error(msg, s);
00121 err = true;
00122 }
00123
00124 private:
00125 bool err;
00126 unsigned int mode;
00127 uint32 sigcnt, gencnt;
00128 uint8 problems;
00129 struct fp_entry sig[MAXSIGS];
00130
00131
00132 #define OSHSIZE 16
00133 struct fp_entry* bh[OSHSIZE];
00134
00135 PDict(int) os_matches;
00136 };
00137
00138 #define SIGHASH(tsize, optcnt, q, df) \
00139 ((uint8(((tsize) << 1) ^ ((optcnt) << 1) ^ (df) ^ (q) )) & 0x0f)
00140
00141 #define MOD_NONE 0
00142 #define MOD_CONST 1
00143 #define MOD_MSS 2
00144 #define MOD_MTU 3
00145
00146 #define QUIRK_PAST 0x1
00147 #define QUIRK_ZEROID 0x2
00148 #define QUIRK_IPOPT 0x4
00149 #define QUIRK_URG 0x8
00150 #define QUIRK_X2 0x10
00151 #define QUIRK_ACK 0x20
00152 #define QUIRK_T2 0x40
00153 #define QUIRK_FLAGS 0x80
00154 #define QUIRK_DATA 0x100
00155 #define QUIRK_BROKEN 0x200
00156 #define QUIRK_RSTACK 0x400
00157 #define QUIRK_SEQEQ 0x800
00158 #define QUIRK_SEQ0 0x1000
00159
00160 #define GADGETNAT 0x1
00161 #define GADGETNAT2 0x2
00162 #define GADGETFIREWALL 0x4
00163 #define GADGETECN 0x8
00164 #define GADGETUPTIME 0x10
00165
00166 #define MATCHGENERIC 0x1
00167 #define MATCHFUZZY 0x2
00168
00169 #endif