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

« back to all changes in this revision

Viewing changes to libs-external/USI++/samples/filter.cc

  • 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
// Small program to find out packet-filtered ports
 
2
// (SYN) (C) 2001 Sebastian Krahmer, use at your own risk
 
3
#include <stdio.h>
 
4
#include <usi++/tcp.h>
 
5
#include <signal.h>
 
6
#include <unistd.h>
 
7
#include <setjmp.h>
 
8
#include <time.h>
 
9
#include <map>
 
10
 
 
11
using namespace usipp;
 
12
using namespace std;
 
13
 
 
14
#define MINPORT 1
 
15
#define MAXPORT 2 
 
16
 
 
17
 
 
18
int main(int argc, char **argv)
 
19
{
 
20
        char s[1000], filter[1000];
 
21
 
 
22
        // only TRUEs allowed. Closed ports dont
 
23
        // appear here
 
24
        map<unsigned short, bool> push_open, syn_open;
 
25
        
 
26
        unsigned short port = 0;
 
27
        struct timeval tv;
 
28
        
 
29
        if (argc <= 3) {
 
30
                printf("usage: %s <target> <source> <interface>\n", argv[0]);
 
31
                exit(1);
 
32
        }
 
33
 
 
34
        TCP tcp(argv[1]), sn("localhost");      
 
35
        
 
36
        // setting port to >1023 will avoid source-port alerts in IDS
 
37
        tcp.set_srcport(7350);
 
38
 
 
39
        if (strcmp(argv[2], "0") != 0)
 
40
                tcp.set_src(argv[2]);
 
41
        
 
42
        // one might change this to TH_URG to have an urgent-scan then
 
43
        tcp.set_flags(TH_PUSH);
 
44
 
 
45
        // Do push-scan
 
46
        sn.init_device(argv[3], 1, 60);
 
47
        snprintf(filter, sizeof(filter), 
 
48
                "tcp and src %s and dst %s and port 7350", argv[1], argv[2]);
 
49
        sn.setfilter(filter);
 
50
        for (port = MINPORT; port <= MAXPORT; port++) {
 
51
                tcp.set_dstport(port);
 
52
                tcp.sendpack("");
 
53
                tv.tv_usec = 0;
 
54
                tv.tv_sec = 2;
 
55
                sn.timeout(tv);
 
56
                if (sn.sniffpack(s, 60) == 0 && sn.timeout())
 
57
                        push_open[port] = true;
 
58
 
 
59
        }
 
60
 
 
61
        tcp.set_flags(TH_SYN);
 
62
        for (port = MINPORT; port <= MAXPORT; port++) {
 
63
                tcp.set_dstport(port);
 
64
                tcp.sendpack("");
 
65
                tv.tv_usec = 0;
 
66
                tv.tv_sec = 2;
 
67
                sn.timeout(tv);
 
68
                if (sn.sniffpack(s, 60) == 0 && sn.timeout())
 
69
                        continue;
 
70
                if (sn.get_flags() == (TH_ACK|TH_SYN))
 
71
                        syn_open[port] = true;
 
72
        }
 
73
        map<unsigned short, bool>::iterator i;
 
74
        for (i = push_open.begin(); i != push_open.end(); ++i)
 
75
                printf("%d P-open.\n", i->first);
 
76
 
 
77
        printf("---\n");
 
78
        for (i = syn_open.begin(); i != syn_open.end(); ++i)
 
79
                printf("%d S-open.\n", i->first);
 
80
 
 
81
        return 0;
 
82
}
 
83