forked from nomoresat/DPITunnel-cli
-
Notifications
You must be signed in to change notification settings - Fork 5
/
desync.cpp
589 lines (512 loc) · 22.9 KB
/
desync.cpp
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
#include "dpitunnel.h"
#include "desync.h"
#include "socket.h"
#include "utils.h"
#include <arpa/inet.h>
#include <cerrno>
#include <chrono>
#include <cstring>
#include <iostream>
#include <future>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <unistd.h>
#include <RawSocket/CheckSum.h>
extern struct Settings_perst_s Settings_perst;
extern struct Profile_s Profile;
const std::string FAKE_TLS_PACKET(
"\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\x9a\x8f\xa7\x6a\x5d"
"\x57\xf3\x62\x19\xbe\x46\x82\x45\xe2\x59\x5c\xb4\x48\x31\x12\x15"
"\x14\x79\x2c\xaa\xcd\xea\xda\xf0\xe1\xfd\xbb\x20\xf4\x83\x2a\x94"
"\xf1\x48\x3b\x9d\xb6\x74\xba\x3c\x81\x63\xbc\x18\xcc\x14\x45\x57"
"\x6c\x80\xf9\x25\xcf\x9c\x86\x60\x50\x31\x2e\xe9\x00\x22\x13\x01"
"\x13\x03\x13\x02\xc0\x2b\xc0\x2f\xcc\xa9\xcc\xa8\xc0\x2c\xc0\x30"
"\xc0\x0a\xc0\x09\xc0\x13\xc0\x14\x00\x33\x00\x39\x00\x2f\x00\x35"
"\x01\x00\x01\x91\x00\x00\x00\x0f\x00\x0d\x00\x00\x0a\x77\x77\x77"
"\x2e\x77\x33\x2e\x6f\x72\x67\x00\x17\x00\x00\xff\x01\x00\x01\x00"
"\x00\x0a\x00\x0e\x00\x0c\x00\x1d\x00\x17\x00\x18\x00\x19\x01\x00"
"\x01\x01\x00\x0b\x00\x02\x01\x00\x00\x23\x00\x00\x00\x10\x00\x0e"
"\x00\x0c\x02\x68\x32\x08\x68\x74\x74\x70\x2f\x31\x2e\x31\x00\x05"
"\x00\x05\x01\x00\x00\x00\x00\x00\x33\x00\x6b\x00\x69\x00\x1d\x00"
"\x20\xb0\xe4\xda\x34\xb4\x29\x8d\xd3\x5c\x70\xd3\xbe\xe8\xa7\x2a"
"\x6b\xe4\x11\x19\x8b\x18\x9d\x83\x9a\x49\x7c\x83\x7f\xa9\x03\x8c"
"\x3c\x00\x17\x00\x41\x04\x4c\x04\xa4\x71\x4c\x49\x75\x55\xd1\x18"
"\x1e\x22\x62\x19\x53\x00\xde\x74\x2f\xb3\xde\x13\x54\xe6\x78\x07"
"\x94\x55\x0e\xb2\x6c\xb0\x03\xee\x79\xa9\x96\x1e\x0e\x98\x17\x78"
"\x24\x44\x0c\x88\x80\x06\x8b\xd4\x80\xbf\x67\x7c\x37\x6a\x5b\x46"
"\x4c\xa7\x98\x6f\xb9\x22\x00\x2b\x00\x09\x08\x03\x04\x03\x03\x03"
"\x02\x03\x01\x00\x0d\x00\x18\x00\x16\x04\x03\x05\x03\x06\x03\x08"
"\x04\x08\x05\x08\x06\x04\x01\x05\x01\x06\x01\x02\x03\x02\x01\x00"
"\x2d\x00\x02\x01\x01\x00\x1c\x00\x02\x40\x01\x00\x15\x00\x96\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00",
517
);
const std::string FAKE_HTTP_PACKET(
"GET / HTTP/1.1\r\nHost: www.w3.org\r\n"
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0\r\n"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*" "/" "*;q=0.8\r\n"
"Accept-Encoding: gzip, deflate\r\n\r\n"
);
int sniff_ack_packet(std::string *packet, std::string ip_srv, int port_srv,
int port_local, std::atomic<bool> *flag) {
if (packet == NULL || flag == NULL) return -1;
// Create raw socket to sniff packet
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
if (sockfd == -1) {
std::cerr << "Sniff raw socket creation failure. Errno: " << std::strerror(errno)
<< std::endl;
return -1;
}
struct pollfd fds[1];
// fds[0] is sniff socket
fds[0].fd = sockfd;
fds[0].events = POLLIN;
// Set poll() timeout
int timeout = 100;
std::string buffer(100, ' ');
struct sockaddr_in ip_srv_sockaddr;
inet_aton(ip_srv.c_str(), &ip_srv_sockaddr.sin_addr);
while ((*flag).load()) {
int ret = poll(fds, 1, timeout);
// Check state
if (ret == -1) {
std::cerr << "Poll error. Errno:" << std::strerror(errno) << std::endl;
break;
} else if (ret == 0)
continue; // Timeout happened
else {
if (fds[0].revents & POLLERR ||
fds[0].revents & POLLHUP ||
fds[0].revents & POLLNVAL)
break;
// Get data
if (fds[0].revents & POLLIN) {
ssize_t read_size = recv(sockfd, &buffer[0], buffer.size(), 0);
if (read_size < 0) {
std::cerr << "ACK packet read error. Errno: "
<< std::strerror(errno) << std::endl;
break;
}
// Get IP header of received packet
iphdr *ip_h = (iphdr *) &buffer[0];
// Get TCP header of received packet
tcphdr *tcp_h = (tcphdr *) (&buffer[0] + ip_h->ihl * 4);
// Get source port (server port)
int port_src_recv = ntohs(tcp_h->source);
// Get dest port (client port)
int port_dst_recv = ntohs(tcp_h->dest);
// Compare received IP/port and IP/port we're waiting for
if (ip_h->saddr == ip_srv_sockaddr.sin_addr.s_addr &&
port_srv == port_src_recv && port_local == port_dst_recv) {
*packet = buffer;
(*flag).store(false);
}
}
fds[0].revents = 0;
}
}
close(sockfd);
return 0;
}
int sniff_handshake_packet(std::string *packet, std::string ip_srv,
int port_srv, std::atomic<int> *local_port_atom, std::atomic<bool> *flag,
std::atomic<int> *status,
std::promise<void> *ready) {
if (packet == NULL || flag == NULL) return -1;
std::map<int, std::string> packets;
// Create raw socket to sniff packet
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
if (sockfd == -1) {
std::cerr << "Sniff raw socket creation failure. Errno: " << std::strerror(errno)
<< std::endl;
return -1;
}
struct pollfd fds[1];
// fds[0] is sniff socket
fds[0].fd = sockfd;
fds[0].events = POLLIN;
// Set poll() timeout
int timeout = 100;
std::string buffer(100, ' ');
struct sockaddr_in ip_srv_sockaddr;
inet_aton(ip_srv.c_str(), &ip_srv_sockaddr.sin_addr);
int local_port = (*local_port_atom).load();
bool is_searched = false;
// Sniff thread ready
(*ready).set_value();
// Handle timeout
auto start = std::chrono::high_resolution_clock::now();
while ((*flag).load()) {
if (!is_searched && (local_port = (*local_port_atom).load()) != -1) {
auto search = packets.find(local_port);
if (search != packets.end()) {
// Found correct packet
*packet = search->second;
break;
}
is_searched = true;
}
int ret = poll(fds, 1, timeout);
// Check timeout
auto stop = std::chrono::high_resolution_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count() >
Settings_perst.packet_capture_timeout) {
close(sockfd);
(*status).store(-1);
return -1;
}
// Check state
if (ret == -1) {
std::cerr << "Poll error. Errno:" << std::strerror(errno) << std::endl;
break;
} else if (ret == 0)
continue; // Timeout happened
else {
if (fds[0].revents & POLLERR ||
fds[0].revents & POLLHUP ||
fds[0].revents & POLLNVAL)
break;
// Get data
if (fds[0].revents & POLLIN) {
ssize_t read_size = recv(sockfd, &buffer[0], buffer.size(), 0);
if (read_size < 0) {
std::cerr << "ACK packet read error. Errno: "
<< std::strerror(errno) << std::endl;
break;
}
// Get IP header of received packet
iphdr *ip_h = (iphdr *) &buffer[0];
// Get TCP header of received packet
tcphdr *tcp_h = (tcphdr *) (&buffer[0] + ip_h->ihl * 4);
// Get source port (server port)
int port_src_recv = ntohs(tcp_h->source);
// Get dest port (client port)
int port_dst_recv = ntohs(tcp_h->dest);
// Compare received IP/port and IP/port we're waiting for
if (ip_h->saddr == ip_srv_sockaddr.sin_addr.s_addr &&
port_srv == port_src_recv) {
if (!is_searched)
packets[port_dst_recv] = buffer;
else if (local_port == port_dst_recv) {
// Found correct packet
*packet = buffer;
break;
}
}
}
fds[0].revents = 0;
}
}
close(sockfd);
(*status).store(0);
return 0;
}
std::string
form_packet(std::string packet_raw, const char *packet_data, unsigned int packet_data_size,
unsigned short id,
unsigned short ttl, unsigned int seq, unsigned int ack_seq,
unsigned int window_size, bool is_swap_addr, uint8_t *flags /*= NULL*/) {
// Save only headers
packet_raw.resize(sizeof(struct iphdr) + sizeof(struct tcphdr));
// Append data
if (packet_data != NULL && packet_data_size != 0)
packet_raw.append(packet_data, packet_data_size);
// Get IP header
iphdr *ip_h = (iphdr *) &packet_raw[0];
// Get TCP header
tcphdr *tcp_h = (tcphdr *) (&packet_raw[0] + ip_h->ihl * 4);
// Fill proper data in IP header
ip_h->tos = 0;
ip_h->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + packet_data_size);
ip_h->id = htons(id);
ip_h->frag_off = htons(0x4000); // Don't fragment
ip_h->ttl = ttl;
ip_h->check = 0;
if (is_swap_addr)
std::swap(ip_h->saddr, ip_h->daddr);
// Check sum IP
ip_h->check = cksumIp(ip_h);
// Fill proper data in TCP header
if (is_swap_addr) {
std::swap(tcp_h->source, tcp_h->dest);
std::swap(tcp_h->seq, tcp_h->ack_seq);
}
tcp_h->ack_seq = htonl(ntohl(tcp_h->ack_seq) + ack_seq);
tcp_h->seq = htonl(ntohl(tcp_h->seq) + seq);
tcp_h->window = htons(window_size);
tcp_h->doff = 5;
if (flags == NULL) {
tcp_h->fin = 0;
tcp_h->syn = 0;
tcp_h->rst = 0;
tcp_h->psh = 1;
tcp_h->ack = 1;
} else
*((uint8_t *) tcp_h + 13) = *flags;
tcp_h->urg = 0;
tcp_h->check = 0;
tcp_h->urg_ptr = 0;
// Check sum TCP
tcp_h->check = cksumTcp(ip_h, tcp_h);
ip_h = NULL;
tcp_h = NULL;
return packet_raw;
}
int set_ttl(int socket, int ttl) {
if (setsockopt(socket, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) < 0) {
std::cerr << "Failed to set TTL on socket. Errno: " << std::strerror(errno) << std::endl;
return -1;
}
return 0;
}
int do_desync_attack(int socket_srv, const std::string &ip_srv, int port_srv, int port_local,
bool is_https,
const std::string &packet_raw, const std::string &packet_data,
unsigned int last_char, unsigned int split_pos) {
// Map IP header of server SYN, ACK packet
iphdr *srv_pack_ip_h = (iphdr *) &packet_raw[0];
// Create raw socket to send fake packets
int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
if (sockfd == -1) {
std::cerr << "Fake raw socket creation failure. Errno: " << std::strerror(errno)
<< std::endl;
return -1;
}
// Disable send buffer to send packets immediately
int sndbuf_size = 0;
if (setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sndbuf_size, sizeof(sndbuf_size)) < 0) {
std::cerr << "Failed to set raw socket buffer size to 0. Errno: "
<< std::strerror(errno) << std::endl;
close(sockfd);
return -1;
}
// Tell system we will include IP header in packet
int yes = 1;
if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &yes, sizeof(yes)) < 0) {
std::cerr << "Failed to enable IP_HDRINCL. Errno: " << std::strerror(errno) << std::endl;
close(sockfd);
return -1;
}
// Store default TTL
int default_ttl;
socklen_t size = sizeof(default_ttl);
if (getsockopt(socket_srv, IPPROTO_IP, IP_TTL, &default_ttl, &size) < 0) {
std::cerr << "Failed to get default ttl from remote server socket. Errno: "
<< std::strerror(errno) << std::endl;
close(sockfd);
return -1;
}
// Store window
int window_size;
size = sizeof(window_size);
if (getsockopt(socket_srv, IPPROTO_TCP, TCP_MAXSEG, &window_size, &size) < 0) {
std::cerr << "Failed to get default MSS from remote server socket. Errno: "
<< std::strerror(errno) << std::endl;
close(sockfd);
return -1;
}
// Fill server address
struct sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(ip_srv.c_str());
serv_addr.sin_port = htons(port_srv);
memset(serv_addr.sin_zero, '\0', sizeof(serv_addr.sin_zero));
// Fill local address
struct sockaddr_in local_addr;
local_addr.sin_family = AF_INET;
local_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
local_addr.sin_port = htons(port_local);
memset(local_addr.sin_zero, '\0', sizeof(local_addr.sin_zero));
uint8_t fake_ttl = Profile.fake_packets_ttl != 0 ? Profile.fake_packets_ttl : default_ttl;
std::string packet_fake;
uint8_t flags;
std::string packet_mod;
std::string data_empty(last_char, '\x00');
unsigned short ip_id_first = rand() % 65535;
if (Profile.auto_ttl) {
fake_ttl = tcp_get_auto_ttl(srv_pack_ip_h->ttl, Profile.auto_ttl_a1, Profile.auto_ttl_a2,
Profile.min_ttl, Profile.auto_ttl_max);
} else if (Profile.min_ttl) {
if (tcp_get_auto_ttl(srv_pack_ip_h->ttl, 0, 0, Profile.min_ttl, 0)) {
// DON'T send fakes
// Send data packet
packet_mod = form_packet(packet_raw, packet_data.c_str(), last_char,
rand() % 65535, default_ttl, 0, 1,
Profile.window_size == 0 ? window_size : Profile.window_size,
true);
if (send_string_raw(sockfd, packet_mod, packet_mod.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
close(sockfd);
return -1;
}
}
// Do zero type attacks (fake, rst)
switch (Profile.desync_zero_attack) {
case DESYNC_ZERO_FAKE:
// If it's https connection send TLS ClientHello
if (is_https)
packet_fake = form_packet(packet_raw, FAKE_TLS_PACKET.c_str(),
FAKE_TLS_PACKET.size(),
rand() % 65535, fake_ttl,
Profile.wrong_seq ? Profile.wrong_seq_drift_seq : 0,
Profile.wrong_seq ? Profile.wrong_seq_drift_ack : 1,
window_size, true);
// If http send GET request
else
packet_fake = form_packet(packet_raw, FAKE_HTTP_PACKET.c_str(),
FAKE_HTTP_PACKET.size(),
rand() % 65535, fake_ttl,
Profile.wrong_seq ? Profile.wrong_seq_drift_seq : 0,
Profile.wrong_seq ? Profile.wrong_seq_drift_ack : 1,
window_size, true);
if (send_string_raw(sockfd, packet_fake, packet_fake.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
break;
case DESYNC_ZERO_RST:
case DESYNC_ZERO_RSTACK:
flags = TH_RST;
if (Profile.desync_zero_attack == DESYNC_ZERO_RSTACK)
flags |= TH_ACK;
packet_fake = form_packet(packet_raw, NULL, 0, rand() % 65535,
fake_ttl, Profile.wrong_seq ? Profile.wrong_seq_drift_seq : 0,
Profile.wrong_seq ? Profile.wrong_seq_drift_ack : 1,
window_size, true, &flags);
if (send_string_raw(sockfd, packet_fake, packet_fake.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
break;
case DESYNC_ZERO_NONE:
break;
default:
std::cerr << "Non valid zero desync attack type" << std::endl;
break;
}
// Do first type attacks (disorder, split)
switch (Profile.desync_first_attack) {
case DESYNC_FIRST_DISORDER:
case DESYNC_FIRST_DISORDER_FAKE:
// Send second data packet(out-of-order)
packet_mod = form_packet(packet_raw, packet_data.c_str() + split_pos,
last_char - split_pos,
rand() % 65535, default_ttl, split_pos, 1,
Profile.window_size == 0 ? window_size : Profile.window_size,
true);
if (send_string_raw(sockfd, packet_mod, packet_mod.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
// Send first fake packet
if (Profile.desync_first_attack == DESYNC_FIRST_DISORDER_FAKE) {
packet_fake = form_packet(packet_raw, data_empty.c_str(), split_pos,
ip_id_first, fake_ttl,
Profile.wrong_seq ? Profile.wrong_seq_drift_seq : 0,
Profile.wrong_seq ? Profile.wrong_seq_drift_ack : 1,
window_size, true);
if (send_string_raw(sockfd, packet_fake, packet_fake.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
}
// Send first data packet
packet_mod = form_packet(packet_raw, packet_data.c_str(), split_pos,
ip_id_first, default_ttl, 0, 1,
Profile.window_size == 0 ? window_size : Profile.window_size,
true);
if (send_string_raw(sockfd, packet_mod, packet_mod.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
// Send first fake packet (again)
if (Profile.desync_first_attack == DESYNC_FIRST_DISORDER_FAKE)
if (send_string_raw(sockfd, packet_fake, packet_fake.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
break;
case DESYNC_FIRST_SPLIT:
case DESYNC_FIRST_SPLIT_FAKE:
// Send first fake packet
if (Profile.desync_first_attack == DESYNC_FIRST_SPLIT_FAKE) {
packet_fake = form_packet(packet_raw, data_empty.c_str(), split_pos,
ip_id_first, fake_ttl,
Profile.wrong_seq ? Profile.wrong_seq_drift_seq : 0,
Profile.wrong_seq ? Profile.wrong_seq_drift_ack : 1,
window_size, true);
if (send_string_raw(sockfd, packet_fake, packet_fake.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
}
// Send first data packet
packet_mod = form_packet(packet_raw, packet_data.c_str(), split_pos,
ip_id_first, default_ttl, 0, 1,
Profile.window_size == 0 ? window_size : Profile.window_size,
true);
if (send_string_raw(sockfd, packet_mod, packet_mod.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
// Send first fake packet (again)
if (Profile.desync_first_attack == DESYNC_FIRST_SPLIT_FAKE)
if (send_string_raw(sockfd, packet_fake, packet_fake.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
// Send second data packet
packet_mod = form_packet(packet_raw, packet_data.c_str() + split_pos,
last_char - split_pos,
rand() % 65535, default_ttl, split_pos, 1,
Profile.window_size == 0 ? window_size : Profile.window_size,
true);
if (send_string_raw(sockfd, packet_mod, packet_mod.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
break;
case DESYNC_FIRST_NONE:
// Just send packet without bypass techniques
// Send data packet
packet_mod = form_packet(packet_raw, packet_data.c_str(), last_char,
rand() % 65535, default_ttl, 0, 1,
Profile.window_size == 0 ? window_size : Profile.window_size,
true);
if (send_string_raw(sockfd, packet_mod, packet_mod.size(),
(struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) {
close(sockfd);
return -1;
}
break;
default:
std::cerr << "Non valid first desync attack type" << std::endl;
break;
}
close(sockfd);
return 0;
}