Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/DDOS Scripts/AMP YUBINA SCRIPTS/chargen_scanner_source.c
4607 views
1
/* priv8 chargen scanner. lel */
2
3
#include <pthread.h>
4
#include <unistd.h>
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <string.h>
8
#include <sys/socket.h>
9
#include <netinet/in.h>
10
#include <signal.h>
11
#include <sys/time.h>
12
#include <sys/types.h>
13
#include <math.h>
14
#include <ctype.h>
15
#include <errno.h>
16
#include <arpa/inet.h>
17
#include <netinet/ip.h>
18
#include <netinet/udp.h>
19
20
volatile int running_threads = 0;
21
volatile int found_srvs = 0;
22
volatile unsigned long per_thread = 0;
23
volatile unsigned long start = 0;
24
volatile unsigned long scanned = 0;
25
volatile int sleep_between = 0;
26
volatile int bytes_sent = 0;
27
volatile unsigned long hosts_done = 0;
28
FILE *fd;
29
30
void *flood(void *par1)
31
{
32
running_threads++;
33
int thread_id = (int)par1;
34
unsigned long start_ip = htonl(ntohl(start)+(per_thread*thread_id));
35
unsigned long end = htonl(ntohl(start)+(per_thread*(thread_id+1)));
36
unsigned long w;
37
int y;
38
unsigned char buf[65536];
39
memset(buf, 0x01, 1);
40
int sizeofpayload = 1;
41
int sock;
42
if((sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))<0) {
43
perror("cant open socket");
44
exit(-1);
45
}
46
for(w=ntohl(start_ip);w<htonl(end);w++)
47
{
48
struct sockaddr_in servaddr;
49
bzero(&servaddr, sizeof(servaddr));
50
servaddr.sin_family = AF_INET;
51
servaddr.sin_addr.s_addr=htonl(w);
52
servaddr.sin_port=htons(19);
53
sendto(sock,(char *)buf,sizeofpayload,0, (struct sockaddr *)&servaddr,sizeof(servaddr));
54
bytes_sent+=sizeofpayload;
55
scanned++;
56
hosts_done++;
57
}
58
close(sock);
59
running_threads--;
60
return;
61
}
62
63
void sighandler(int sig)
64
{
65
fclose(fd);
66
printf("\n");
67
exit(0);
68
}
69
70
void *recievethread()
71
{
72
printf("Started Listening Thread\n");
73
int saddr_size, data_size, sock_raw;
74
struct sockaddr_in saddr;
75
struct in_addr in;
76
77
unsigned char *buffer = (unsigned char *)malloc(65536);
78
sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_UDP);
79
if(sock_raw < 0)
80
{
81
printf("Socket Error\n");
82
exit(1);
83
}
84
while(1)
85
{
86
saddr_size = sizeof saddr;
87
data_size = recvfrom(sock_raw , buffer , 65536 , 0 , (struct sockaddr *)&saddr , &saddr_size);
88
if(data_size <0 )
89
{
90
printf("Recvfrom error , failed to get packets\n");
91
exit(1);
92
}
93
struct iphdr *iph = (struct iphdr*)buffer;
94
if(iph->protocol == 17)
95
{
96
unsigned short iphdrlen = iph->ihl*4;
97
struct udphdr *udph = (struct udphdr*)(buffer + iphdrlen);
98
unsigned char* payload = buffer + iphdrlen + 1;
99
if(ntohs(udph->source) == 19)
100
{
101
int body_length = data_size - iphdrlen - 1;
102
found_srvs++;
103
fprintf(fd,"%s %d\n",inet_ntoa(saddr.sin_addr),body_length);
104
fflush(fd);
105
106
}
107
}
108
109
}
110
close(sock_raw);
111
112
}
113
114
int main(int argc, char *argv[ ])
115
{
116
117
if(argc < 6){
118
fprintf(stderr, "Invalid parameters!\n");
119
fprintf(stdout, "Usage: %s <ip range start (192.168.0.0)> <ip range end (192.168.255.255)> <outfile> <threads> <scan delay in ms>\n", argv[0]);
120
exit(-1);
121
}
122
fd = fopen(argv[3], "a");
123
sleep_between = atoi(argv[5]);
124
125
signal(SIGINT, &sighandler);
126
127
int threads = atoi(argv[4]);
128
pthread_t thread;
129
130
pthread_t listenthread;
131
pthread_create( &listenthread, NULL, &recievethread, NULL);
132
133
char *str_start = malloc(18);
134
memset(str_start, 0, 18);
135
str_start = argv[1];
136
char *str_end = malloc(18);
137
memset(str_end, 0, 18);
138
str_end = argv[2];
139
start = inet_addr(str_start);
140
per_thread = (ntohl(inet_addr(str_end)) - ntohl(inet_addr(str_start))) / threads;
141
unsigned long toscan = (ntohl(inet_addr(str_end)) - ntohl(inet_addr(str_start)));
142
int i;
143
for(i = 0;i<threads;i++){
144
pthread_create( &thread, NULL, &flood, (void *) i);
145
}
146
sleep(1);
147
printf("Starting Scan...\n");
148
char *temp = (char *)malloc(17);
149
memset(temp, 0, 17);
150
sprintf(temp, "Found");
151
printf("%-16s", temp);
152
memset(temp, 0, 17);
153
sprintf(temp, "Host/s");
154
printf("%-16s", temp);
155
memset(temp, 0, 17);
156
sprintf(temp, "B/s");
157
printf("%-16s", temp);
158
memset(temp, 0, 17);
159
sprintf(temp, "Running Thrds");
160
printf("%-16s", temp);
161
memset(temp, 0, 17);
162
sprintf(temp, "Done");
163
printf("%s", temp);
164
printf("\n");
165
166
char *new;
167
new = (char *)malloc(16*6);
168
while (running_threads > 0)
169
{
170
printf("\r");
171
memset(new, '\0', 16*6);
172
sprintf(new, "%s|%-15lu", new, found_srvs);
173
sprintf(new, "%s|%-15d", new, scanned);
174
sprintf(new, "%s|%-15d", new, bytes_sent);
175
sprintf(new, "%s|%-15d", new, running_threads);
176
memset(temp, 0, 17);
177
int percent_done=((double)(hosts_done)/(double)(toscan))*100;
178
sprintf(temp, "%d%%", percent_done);
179
sprintf(new, "%s|%s", new, temp);
180
printf("%s", new);
181
fflush(stdout);
182
bytes_sent=0;
183
scanned = 0;
184
sleep(1);
185
}
186
printf("\n");
187
fclose(fd);
188
return 0;
189
}
190