~ubuntu-branches/ubuntu/trusty/xprobe/trusty

« back to all changes in this revision

Viewing changes to logic_tree.c

  • Committer: Bazaar Package Importer
  • Author(s): Richard Atterer
  • Date: 2005-02-22 22:54:24 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050222225424-6cqy8rr45pkna819
Tags: 0.2.2-1
New upstream version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: logic_tree.c,v 1.10 2001/10/20 15:23:55 fygrave Exp $ */
2
 
/*
3
 
** Copyright (C) 2001 Fyodor Yarochkin <fygrave@tigerteam.net>,
4
 
**                    Ofir Arkin       <ofir@sys-security.com>
5
 
**
6
 
** This program is free software; you can redistribute it and/or modify
7
 
** it under the terms of the GNU General Public License as published by
8
 
** the Free Software Foundation; either version 2 of the License, or
9
 
** (at your option) any later version.
10
 
**
11
 
** All material for nonprofit, educational use only.
12
 
**
13
 
** This program is distributed in the hope that it will be useful,
14
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
** GNU General Public License for more details.
17
 
**
18
 
** You should have received a copy of the GNU General Public License
19
 
** along with this program; if not, write to the Free Software
20
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
 
*/
22
 
 
23
 
 
24
 
#include "xprobe.h"
25
 
 
26
 
 
27
 
int do_logic(struct sockaddr_in to) {
28
 
    rpack_t *udp_res, *icmpecho_res, *icmpts_res, *icmpam_res,
29
 
    *icmpir_res;
30
 
    ssize_t hdr_len;
31
 
    int retval = -1;
32
 
 
33
 
    if ((udp_res = send_udp(to)) == NULL) {
34
 
        fprintf(stderr, "Error while sending UDP query. Quiting\n");
35
 
        return -1;
36
 
    }
37
 
 
38
 
 
39
 
/* make some generic calculations */
40
 
 
41
 
    hdr_len = (udp_res->ip->ip_hl<<2) + 8;
42
 
    
43
 
    /* precedence bits check */
44
 
 
45
 
    if (((udp_res->ip->ip_tos) & 0xc0) != 0) {
46
 
 
47
 
        /* if our ip->tos was 0xf8 we would get:
48
 
            0xd8 --> from linux boxes
49
 
            0xf8 --> from hpux/aix/??
50
 
            0xc0 --> from cisco (may utilize it later
51
 
        */    
52
 
        tree_message("Cisco IOS 11.x-12.x! Extreme Network Switches.Linux 2.0.x!2.2.x!2.4.x.");
53
 
 
54
 
    /* received datagram size check */
55
 
        
56
 
        if (ntohs(udp_res->ip->ip_len) != (hdr_len + UDP_LEN_ALL)) {
57
 
            tree_message("Cisco IOS 11.x-12x! Extreme Network Switches.");
58
 
 
59
 
            if (udp_checksum_ver(udp_res) == UDP_CKSUM_ZERO) {
60
 
                fin_message("Extreme Network Switches.");
61
 
                retval = 1;
62
 
            } else {
63
 
                fin_message("Cisco IOS 11.x-12.x");
64
 
                retval = 2;
65
 
            }
66
 
            free_res(&udp_res);
67
 
            return retval;
68
 
        } else {
69
 
            /* the whole datagram echo'ed */
70
 
            tree_message("Linux kernel 2.0.x!2.2.x!2.4.x! Based.");
71
 
 
72
 
            /* ttl test.. abit dodgy (would work precisely in LAN */
73
 
            if (udp_res->ip->ip_ttl < 65) {
74
 
                free_res(&udp_res);
75
 
                fin_message("Linux kernel 2.0.x");
76
 
                return 3;
77
 
            }
78
 
            tree_message("Linux kernel 2.2.x!2.4.x! Based.");
79
 
            free_res(&udp_res);
80
 
            /* do ICMP ECHO REQUEST test here */
81
 
            if ((icmpecho_res = send_icmpecho_req(to)) == NULL) {
82
 
                fprintf(stderr, "Error while sending ICMP echo request.");
83
 
                fin_message("Linux kernel 2.2.x! 2.4.x! assumed.");
84
 
                return 4;
85
 
            }
86
 
            tree_message("ICMP echo/echo reply are not filtered");
87
 
 
88
 
            if (icmpecho_res->ip->ip_id == 0) {
89
 
                fin_message("Linux 2.4.x kernel");
90
 
                retval = 5;
91
 
            } else {
92
 
                if (icmpecho_res->ip->ip_off & htons(IP_DF)) {
93
 
                    fin_message("Linux 2.4.x kernel");
94
 
                    retval = 5;
95
 
                } else {
96
 
                    fin_message("Linux 2.2.x/2.4.5+ kernel");
97
 
                    retval = 6;
98
 
                }
99
 
            }
100
 
        free_res(&icmpecho_res);
101
 
        return retval; /* linux type diag done here */
102
 
        } /* endif echo'ed dgrm size" */
103
 
    } else {
104
 
        /* tos doesn't have 0xc0 then... */
105
 
        /* amount of echo'ed data check */ 
106
 
 
107
 
        switch(ntohs(udp_res->ip->ip_len) - hdr_len - sizeof(struct ip)) {
108
 
            case 64:
109
 
                tree_message("Sun Solaris 2.3-2.8! HP-UX 11.x!MacOS 7.x-9.x");
110
 
                free_res(&udp_res);
111
 
                if ((icmpts_res = send_icmpts_req(to)) == NULL) {
112
 
                    fin_message("HP-UX 11.x!MacOS 7.x-9.x (no ts response received)");
113
 
                    return 9;
114
 
                } else {
115
 
                    free_res(&icmpts_res);
116
 
                    fin_message("Sun Solaris 2.3-2.8");
117
 
                    return 10;
118
 
                }
119
 
                /* UNREACH */
120
 
                break;
121
 
 
122
 
            case 8:
123
 
                break;
124
 
            default:
125
 
                fin_message("3Com SuperStack II Switch SWNBBSI-CF,11.1.0.00S38\n"
126
 
                            "Nokia IPSO 3.2-2.3.1 releng 783-849\n" 
127
 
                            "Ricoh Aficio AP4500 Network Laster Printer\n"
128
 
                            "Linux 2.0.x/2.2.x/2.4.x\n"
129
 
                            "Shiva AccessPort Bridge/Router Software V.2.1.0");
130
 
                free_res(&udp_res);
131
 
                return 7;
132
 
        } /* switch (diff packlen */
133
 
 
134
 
        /* other */
135
 
        /* ip tocal length integrity check */
136
 
 
137
 
        /* XXX: make sure we do it right
138
 
         */
139
 
        switch (icmp_unreach_lencheck(udp_res)) {
140
 
            case ICMPUNREACH_LEN_GT:
141
 
                tree_message("IP total length field value is >20 bytes from the original");
142
 
                tree_message("*** AIX!BSDI!NetBSD 1.1.x-1.2.x!MacOS X 1.0-1.2");
143
 
                if (ip_checksum_ok(udp_res)) {
144
 
                    fin_message("AIX");
145
 
                    free_res(&udp_res);
146
 
                    return 26;
147
 
                }
148
 
                tree_message("BSDI. NetBSD 1.1.x-1.2.x! MacOS X 1.0-1.2");
149
 
                if (udp_res->ip->ip_id != udp_res->orig_ip->ip_id) {
150
 
                    fin_message("Little endian BSDI/NetBSD 1.1.x-1.2.x! MacOS X 1.0-1.2");
151
 
                    free_res(&udp_res);
152
 
                    return 27;
153
 
                } else {
154
 
                    fin_message("Big endian BSDI/NetBSD 1.1.x-1.2.x MacOS X 1.0-1.2");
155
 
                    free_res(&udp_res);
156
 
                    return 28;
157
 
                }
158
 
                /* UNREACH */
159
 
                break;
160
 
            case ICMPUNREACH_LEN_LS:    
161
 
                tree_message("IP total length field value is <20 bytes from the original");
162
 
                tree_message("*** OpenBSD 2.6-2.9, Apollo Domain/OS SR 10.4 NFR IDS Appliance");
163
 
                tree_message("*** Extreme Networks switch Network Systems Router NS6114 (NSC 6600 Series)");
164
 
                tree_message("*** Cabletron Systems SSR 8000 Systems Software Version 3.1 B16");
165
 
                switch(udp_checksum_ver(udp_res)) {
166
 
                    case UDP_CKSUM_ZERO:
167
 
                        fin_message("Extreme Networks switch Network Systems Router NS6114 (NSC 6600 Series)");
168
 
                        fin_message("Cabletron Systems SSR 8000 Systems Software Version 3.1 B16");
169
 
                        free_res(&udp_res);
170
 
                        return 22;
171
 
                    case UDP_CKSUM_BAD:
172
 
                        fin_message("NFR IDS Appliance");
173
 
                        free_res(&udp_res);
174
 
                        return 23;
175
 
                   case UDP_CKSUM_GOOD:
176
 
                        tree_message("OpenBSD 2.6-2.9, Apollo Domain/OS SR 10.4 NFR IDS Appliance");
177
 
                        break;
178
 
                }
179
 
 
180
 
                if (ip_checksum_ok(udp_res)) {
181
 
                    fin_message(" OpenBSD 2.6-2.9");
182
 
                    free_res(&udp_res);
183
 
                    return 24;
184
 
                } else {
185
 
                    fin_message("Apollo Domain/OS SR 10.4 NFR IDS Appliance");
186
 
                    free_res(&udp_res);
187
 
                    return 25;
188
 
                }
189
 
                /* UNREACH */
190
 
                break;
191
 
            case ICMPUNREACH_LEN_OK:    
192
 
                tree_message("IP total length field value is OK");
193
 
                if(frag_bits_flipped(udp_res)) {
194
 
                    if (frag_bits_flipped(udp_res) == FRAG_BITS_ZERO) {
195
 
                        tree_message("Frag bits are zeroed");
196
 
                        fin_message("ULTRIX");
197
 
                        free_res(&udp_res);
198
 
                        return 35;
199
 
                    }
200
 
                    tree_message("Frag bits are flipped");
201
 
                    tree_message("*** FreeBSD 2.2.x - 4.1!NetBSD");
202
 
                    if (ip_checksum_ok(udp_res)) {
203
 
                        fin_message("FreeBSD 2.2.x - 4.1");
204
 
                        free_res(&udp_res);
205
 
                        return 12;
206
 
                    } else {
207
 
                        fin_message("NetBSD");
208
 
                        free_res(&udp_res);
209
 
                        return 13;
210
 
                    }
211
 
                } else {
212
 
                    /* frags are not flipped */
213
 
                    tree_message("Frag bits are OK");
214
 
                    if ((icmpecho_res = send_icmpecho_req(to)) == NULL) {
215
 
                        fprintf(stderr, "Error while sending ICMP echo request.\n");
216
 
                        /* XXX: very generic msg */
217
 
                        fin_message("Windows Based.  Open/Net/FreeBSD/DG-UX/HP-UX 10.x etc");
218
 
                        free_res(&udp_res);
219
 
                        return 14;
220
 
                    }
221
 
                    if (icmpecho_res->icmp->icmp_code) {
222
 
                        tree_message("ICMP code !=0");
223
 
                        /* XXX: to be expanded! */
224
 
                        if (!(icmpecho_res->ip->ip_off & htons(IP_DF))) {
225
 
                            tree_message("DF bit in icmp echo response not echoed");
226
 
                            if (icmpecho_res->ip->ip_ttl < 129) {
227
 
                                fin_message("Novell (FreeBSD 4.3-current(?)");
228
 
                                free_res(&icmpecho_res);
229
 
                                free_res(&udp_res);
230
 
                                return 29;
231
 
                            } else {
232
 
                                fin_message("Ultrix!HPUX 10.20(?)");
233
 
                                free_res(&icmpecho_res);
234
 
                                free_res(&udp_res);
235
 
                                return 30;
236
 
                            }
237
 
                        } /* else */ 
238
 
                        tree_message("DF bit in icmp echo response is echoed");
239
 
                        if (!(udp_res->ip->ip_off & htons(IP_DF))) {
240
 
                            tree_message("DF bit in icmp unreach is not echoed");
241
 
                            tree_message("OpenBSD 2.1-2.3,2.4-2.5!NetBSD 1.5, 1.4.1, 1.4!IBM OS/390");
242
 
                            if (udp_checksum_ver(udp_res) ==
243
 
                                 UDP_CKSUM_ZERO) {
244
 
                                fin_message("OpenBSD 2.1-2.3");
245
 
                                free_res(&udp_res);
246
 
                                free_res(&icmpecho_res);
247
 
                                return 31;
248
 
                            } else {
249
 
                                tree_message("OpenBSD 2.4-2.5!NetBSD"
250
 
                                " 1.5, 1.4.1, 1.4!IBM OS/390");
251
 
                                if (udp_res->ip->ip_ttl > 64) {
252
 
                                    fin_message("OpenBSD 2.4-2.5!NetBSD 1.5, 1.4.1, 1.4");
253
 
                                    free_res(&udp_res);
254
 
                                    free_res(&icmpecho_res);
255
 
                                    return 32;
256
 
                                }
257
 
                                fin_message("IBM OS/390");
258
 
                                free_res(&udp_res);
259
 
                                free_res(&icmpecho_res);
260
 
                                return 33;
261
 
                            }
262
 
                        } 
263
 
                        free_res(&icmpecho_res);
264
 
                        if ((icmpir_res = send_icmpireq_req(to)) == NULL) {
265
 
                            fin_message("Unknown Unix (Accuracy dropped)");
266
 
                            free_res(&udp_res);
267
 
                           return 0; 
268
 
                           /* XXX: yellow line here */
269
 
                        }
270
 
                        tree_message("OpenVMS!HPUX 10.x!DGUX!SunOS4.x");
271
 
                        if (((struct ip *)((char *)(udp_res->icmp) + 8))->ip_id !=
272
 
                            udp_res->orig_ip->ip_id) {
273
 
                            fin_message("OpenVMS with Digital TCP Services");
274
 
                            free_res(&icmpir_res);
275
 
                            free_res(&udp_res);
276
 
                            return 34;
277
 
                        }
278
 
                        tree_message("IP ID is ok");
279
 
                        tree_message("DGUX/HPUX 10.x/OpenVMS with "
280
 
                                     "Process Software TCPWare!SunOS4.x");
281
 
                        if (!ip_checksum_ok(udp_res)) {
282
 
                            fin_message("HPUX 10.x");
283
 
                            free_res(&icmpir_res);
284
 
                            free_res(&udp_res);
285
 
                            return 35;
286
 
                        }
287
 
                        tree_message("DGUX/OpenVMS with Process Software TCPWare!SunOS4.x");
288
 
                            
289
 
                        if (udp_checksum_ver(udp_res) == UDP_CKSUM_ZERO) {
290
 
                            tree_message("DGUX/Compaq Tru64!SunOS4.x");
291
 
                            if (udp_res->ip->ip_ttl > 64) {
292
 
                                fin_message("SunOS4.x");
293
 
                                free_res(&udp_res);
294
 
                                free_res(&icmpecho_res);
295
 
                                return 36;
296
 
                            }
297
 
                            fin_message("DGUX/Compaq Tru64");
298
 
                            free_res(&udp_res);
299
 
                            free_res(&icmpecho_res);
300
 
                            return 37;
301
 
                        }
302
 
                            
303
 
                        free_res(&udp_res);
304
 
                        free_res(&icmpir_res);
305
 
                        fin_message("OpenVMS with Process Software TCPWare");
306
 
                        return 15;
307
 
                    } else {
308
 
                        tree_message("Microsoft Windows Family TCP stack");
309
 
                        if(icmpecho_res->ip->ip_ttl < 33) {
310
 
                            fin_message("Windows 95");
311
 
                            free_res(&icmpecho_res);
312
 
                            return 16;
313
 
                        } 
314
 
                        tree_message("Other Windows-based OS (ttl: %d)",icmpecho_res->ip->ip_ttl);
315
 
                        if (!icmpecho_res->ip->ip_tos) {
316
 
                            free_res(&icmpecho_res);
317
 
                            fin_message("Windows 2k. SP1, SP2/Windows XP");
318
 
                            return 17;
319
 
                        }
320
 
                        free_res(&icmpecho_res);
321
 
                        tree_message("Other Windows-based OS (98/98SE/NTsp3-/NTsp4+)");
322
 
                        if ((icmpts_res = send_icmpts_req(to)) == NULL) {
323
 
                            tree_message("Windows NTsp3-!Windows NTsp4+");
324
 
                            if ((icmpam_res = send_icmpmaskreq_req(to)) == NULL) {
325
 
                                fin_message("Windows NTsp4+");
326
 
                                return 18;
327
 
                            } else {
328
 
                                free_res(&icmpam_res);
329
 
                                fin_message("Windows NTsp3-");
330
 
                                return 19;
331
 
                            }
332
 
                        } else {
333
 
                            tree_message("Windows 98/98SE/ME");
334
 
                            free_res(&icmpts_res);
335
 
                            if ((icmpam_res = send_icmpmaskreq_req(to)) == NULL) {
336
 
                                fin_message("Windows ME");
337
 
                                return 20;
338
 
                            } else {
339
 
                                fin_message("Windows 98/98SE");
340
 
                                return 21;
341
 
                            }
342
 
                        } /* if (send_icmpts_req */
343
 
 
344
 
                        /* NOTREACH */
345
 
                    }
346
 
                } /* if(frag_flipped... */
347
 
 
348
 
               /* NOTREACH */
349
 
        } /* switch(icmp_unreach.. */
350
 
        fin_message("UNKNOWN");
351
 
    } /* else (tos) endif */
352
 
    free_res(&udp_res);
353
 
 
354
 
return 1;
355
 
}