Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/Botnets/Scanning/SSH/class.c
5038 views
1
#include <libnet.h>
2
#include <stdio.h>
3
#include <sys/socket.h>
4
#include <netinet/in.h>
5
#include <arpa/inet.h>
6
#include <sys/types.h>
7
#include <unistd.h>
8
#include <pcap.h>
9
#include <time.h>
10
11
#define COLOR_RED "\x1b[31m"
12
#define COLOR_GREEN "\x1b[32m"
13
#define COLOR_YELLOW "\x1b[33m"
14
#define COLOR_BLUE "\x1b[34m"
15
#define COLOR_MAGENTA "\x1b[35m"
16
#define COLOR_CYAN "\x1b[36m"
17
#define COLOR_RESET "\x1b[0m"
18
19
int main(int argc, char **argv) {
20
libnet_t *l;
21
libnet_ptag_t t;
22
unsigned short burst=50;
23
unsigned short ct=0;
24
char errbuff[LIBNET_ERRBUF_SIZE];
25
unsigned long myip;
26
struct in_addr sc;
27
unsigned char tcpopt[]="\x02\x04\x05\xb4\x01\x01\x04\x02";
28
29
unsigned short port;
30
unsigned long usec;
31
//unsigned char outstr[1024];
32
char cc;
33
int i;
34
pid_t pid;
35
pcap_t *handle;
36
char *temp_char;
37
bpf_u_int32 mask;
38
bpf_u_int32 net;
39
char errbuf[PCAP_ERRBUF_SIZE];
40
char filter[1024];
41
struct bpf_program cfilter;
42
struct pcap_pkthdr header;
43
const unsigned char *packet;
44
struct in_addr ekkt;
45
unsigned char ip[50];
46
47
unsigned long dstip=0;
48
unsigned short sport;
49
char *interface=NULL;
50
unsigned char bclass=0;
51
unsigned char aclass=0;
52
unsigned char rclass=1;
53
unsigned int a=0,b=0,c=0,d=0;
54
55
srand(time(NULL));
56
sport=rand();
57
usec=1000000;
58
if(argc<2) {
59
system("clear");
60
printf("\x1b[33m============================================\n");
61
printf(" *Nos Security Team* \n");
62
printf("============================================\x1b[0m\n");
63
printf("============================================\n");
64
printf(" Advanced TCP Port Scanner \n");
65
printf("============================================\n");
66
printf("============================================\n");
67
printf(" *Version : 2.0 / 2016 \n");
68
printf(" *Made by : Binary \n");
69
printf("============================================\n");
70
printf(" *Works on : Linux \n");
71
printf("============================================\n");
72
printf("\x1b[32m============================================\n");
73
printf(" *Usage : %s port <opt> \n",argv[0]);
74
printf(" *Example : %s 22 -a 24 -s 10 -i eth0\n",argv[0]);
75
printf(" *Example : %s 22 -b 24.1 -s 10 -i eth0\n",argv[0]);
76
printf("============================================\x1b[0m\n");
77
printf("\x1b[35m *Options : -a Class A (ex: 24) \n");
78
printf(" : -b Class B (ex: 213.14) \n");
79
printf(" : -s speed (from 1 to 10) \n");
80
printf(" : -i interfce (ex: eth0) \x1b[0m\n");
81
printf("============================================\n");
82
printf("\x1b[35m *Bonus : %s -fix Auto Filter \x1b[0m\n",argv[0]);
83
printf("============================================\n");
84
exit(0x01);
85
}
86
for(i=1;i<argc;i++) {
87
if(strstr(argv[i],"-s")) {
88
if(i+1<argc) {
89
switch (atoi(argv[i+1])) {
90
case 1:usec=1000000;break;
91
case 2:usec=500000;break;
92
case 3:usec=250000;break;
93
case 4:usec=125000;break;
94
case 5:usec=60000;break;
95
case 6:usec=30000;break;
96
case 7:usec=10000;break;
97
case 8:usec=1000;break;
98
case 9:usec=100;break;
99
case 10:usec=0;burst=65535;
100
}
101
} else {
102
printf("\x1b[31m-s requires an argument\x1b[0m\n");
103
exit(0x01);
104
}
105
}
106
if(strstr(argv[i],"-fix")) {
107
system("clear");
108
printf("\x1b[34mFucking FILTERING shit nigga\x1b[0m\n");
109
system("cat bios.txt | sort | uniq > mfu.txt");
110
system("wc -l mfu.txt");
111
exit(0x02);
112
}
113
if(strstr(argv[i],"-i")) {
114
if(i+1<argc) interface=argv[i+1];
115
else {
116
printf("\x1b[31m-i requires an argument\x1b[0m\n");
117
exit(0x01);
118
}
119
}
120
if(strstr(argv[i],"-a")) {
121
if(i+1<argc) {
122
aclass=1;
123
bclass=0;
124
rclass=0;
125
a=atoi(argv[i+1]);
126
b=0;
127
c=0;
128
d=0;
129
//printf("%d\n",a);
130
if((a<1) || (a>254)) {
131
printf("\x1b[31mA must be between 1 and 254\x1b[0m\n");
132
exit(0x02);
133
}
134
printf("\x1b[31;4mScanning network \e[32;1m%d.*.*.*\x1b[0m\n",a);
135
} else {
136
printf("\x1b[31m-a requires an A network as argument\x1b[0m\n");
137
exit(0x01);
138
}
139
}
140
if(strstr(argv[i],"-b")) {
141
if(i+1<argc) {
142
aclass=0;
143
bclass=1;
144
rclass=0;
145
a=atoi(strtok(argv[i+1],"."));
146
temp_char=strtok(NULL,".");
147
if(temp_char==NULL)
148
b=0;else b=atoi(temp_char);
149
c=0;
150
d=0;
151
//printf("%d\n",a);
152
if((a<1) || (a>254)) {
153
printf("\x1b[31mA must be between 1 and 254\x1b[0m\n");
154
exit(0x02);
155
}
156
printf("\x1b[31;4mScanning network \e[32;1m%d.%d.*.*\x1b[0m\n",a,b);
157
} else {
158
printf("\x1b[31m-b requires an B network as argument(e.g. 192.168)\n");
159
exit(0x01);
160
}
161
}
162
}
163
printf("\e[34;4mUsec: %ld, Burst packets %d\n",usec,burst);
164
port=(unsigned short)atoi(argv[1]);
165
if((port<1) || (port>65535))
166
exit(printf("\x1b[31mPort numbers are in 1 .. 65535\x1b[0m\n"));
167
if(interface!=NULL)
168
printf("\e[34;4mUsing inteface %s\x1b[0m\n",interface);
169
l=libnet_init(LIBNET_RAW4,interface,errbuff);
170
if(!l) {
171
printf("\x1b[31mERROR: %s\x1b[0m\n",errbuff);
172
exit(0x02);
173
}
174
myip=libnet_get_ipaddr4(l);
175
sc.s_addr=myip;
176
sprintf(filter,"(tcp[tcpflags]=0x12) and (src port %d) and (dst port %d)",port,sport);
177
printf("\e[34;4mUsing \"%s\" as pcap filter\n",filter);
178
printf("\e[34;4mMy detected ip on %s is %s\n",l->device,inet_ntoa(sc));
179
pcap_lookupnet(l->device, &net, &mask, errbuf);
180
pid=fork();
181
handle=NULL;
182
handle = pcap_open_live(l->device, BUFSIZ, 1, 0, errbuf);
183
if(handle==NULL) {
184
printf("\x1b[31mERROR: pcap_open_live() : %s\x1b[0m\n",errbuff);
185
exit(0x05);
186
}
187
cc=pcap_compile(handle, &cfilter, filter, 0, net);
188
if(cc!=0) {
189
printf("\x1b[31mERROR: pcap_compile() failed!!!\x1b[0m\n");
190
exit(0);
191
}
192
cc=pcap_setfilter(handle, &cfilter);
193
if(cc!=0) {
194
printf("\x1b[31mERROR: pcap_setfilter() failed!!!\x1b[0m\n");
195
exit(0);
196
}
197
if(pid==0) {
198
/* sniff */
199
while(1){
200
packet = pcap_next(handle, &header);
201
memcpy(&ekkt.s_addr,packet+26,4);
202
printf("%s\n",inet_ntoa(ekkt));
203
FILE * fp;
204
fp=fopen("bios.txt","a+");
205
fprintf(fp,"%s\n",inet_ntoa(ekkt));
206
fclose(fp);
207
}
208
}
209
if(pid > 0) {
210
printf("\e[34;4mCapturing process started pid %d\x1b[0m\n",pid);
211
usleep(500000);
212
while(1) {
213
t=LIBNET_PTAG_INITIALIZER;
214
t=libnet_build_tcp_options(tcpopt, 8, l,0);
215
//t=LIBNET_PTAG_INITIALIZER;
216
t=libnet_build_tcp(sport,port,rand(),rand(),TH_SYN,65535,0,0,LIBNET_TCP_H+8,NULL,0,l,0);
217
if(rclass)
218
dstip=rand();
219
if(aclass) {
220
if(d==0)
221
printf("\x1b[31;4mScanning \e[32;1m%d.%d.%d.*\x1b[0m\n",a,b,c);
222
d++;
223
if(d>255) {c++;d=0;}
224
if(c>255) {b++;c=0;}
225
sprintf(ip,"%d.%d.%d.%d\n",a,b,c,d);
226
//printf("%s\n",ip);
227
if((b==255)&& (c==255) && (d==255)) {
228
printf("\e[34;4mScanning has Stopped\x1b[0m\n");
229
sleep(10);
230
kill(pid,2);
231
return 0;
232
}
233
sc.s_addr=inet_addr(ip);
234
dstip=sc.s_addr;
235
}
236
if(bclass) {
237
if(d==0)
238
printf("\x1b[31;4mScanning \e[32;1m%d.%d.%d.*\x1b[0m\n",a,b,c);
239
d++;
240
if(d>255) {
241
c++;d=0;
242
}
243
sprintf(ip,"%d.%d.%d.%d",a,b,c,d);
244
if((c==255) && (d==255)) {
245
printf("%s\n",ip);
246
printf("\e[34;4mScanning has Stopped\x1b[0m\n");
247
sleep(10);
248
kill(pid,2);
249
return 0;
250
}
251
sc.s_addr=inet_addr(ip);
252
dstip=sc.s_addr;
253
}
254
libnet_build_ipv4(LIBNET_TCP_H+LIBNET_IPV4_H+8,0,rand(),0,128,IPPROTO_TCP,0,myip,dstip,NULL,0,l,0);
255
cc=libnet_write(l);
256
if(cc<=0)
257
printf("\x1b[31mlibnet_write() wtf %d\x1b[0m\n",cc);
258
libnet_clear_packet(l);
259
if(ct==burst) {
260
usleep(usec);
261
ct=0;
262
};
263
ct++;
264
}
265
}
266
if(pid<0) {
267
printf("\x1b[31mCannot fork()\x1b[0m\n");
268
exit(0x05);
269
}
270
return 0;
271
}
272
273
274