Upload files to "/"

This commit is contained in:
2026-07-24 15:42:19 +00:00
commit f305cecd99
5 changed files with 386 additions and 0 deletions

6
README.md Normal file
View File

@@ -0,0 +1,6 @@
> [!IMPORTANT]
> this is what happens when you ban the developer that coded 90% of the server 🤦
> this is from november 2025, so probally all the things that were in here vulnerabilities wise are patched, go ahead and try though
> oh yeah, removed all of the stuff that was rude to leak so yeah (private key, jwt token secret, mongodb connection url, ect.)
> fuck you supergamer ✌️
> discord.gg/vanillarec

35
Random.cs Normal file
View File

@@ -0,0 +1,35 @@
using System.Text;
namespace Stella
{
public static class Random
{
private static readonly System.Random _random = new();
public static int RandomInt(int range0, int range1)
{
int result = _random.Next(range0, range1);
return result;
}
public static long RandomLong(long range0, long range1)
{
long result = _random.NextInt64(range0, range1);
return result;
}
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}|;:',.<>?/~`";
StringBuilder sb = new();
for (int i = 0; i < length; i++)
{
int index = _random.Next(chars.Length);
sb.Append(chars[index]);
}
return sb.ToString();
}
}
}

265
ServerAPI.cs Normal file
View File

@@ -0,0 +1,265 @@
using Microsoft.AspNetCore.Http.Extensions;
using MongoDB.Driver;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.Json;
namespace Stella
{
public class ServerAPI(WebApplication webApplication)
{
private readonly WebApplication webApplication = webApplication;
private bool hasInit = false;
public RouteHandlerBuilder GET(string endpoint, Delegate action) => webApplication.MapGet(endpoint, action);
public RouteHandlerBuilder POST(string endpoint, Delegate action) => webApplication.MapPost(endpoint, action);
public RouteHandlerBuilder PUT(string endpoint, Delegate action) => webApplication.MapPut(endpoint, action);
public RouteHandlerBuilder MAP(string endpoint, Delegate action) => webApplication.Map(endpoint, action);
private static readonly object ConsoleLock = new();
public void Init()
{
webApplication.Use(async (context, next) =>
{
var request = context.Request;
context.Response.OnStarting(() =>
{
lock (ConsoleLock)
{
var color = context.Response.StatusCode switch
{
200 => ConsoleColor.Green,
405 or 404 or 403 => ConsoleColor.Red,
101 => ConsoleColor.Blue,
_ => ConsoleColor.White
};
Console.ForegroundColor = color;
Console.WriteLine($"{(context.Response.StatusCode == 101 ? "WS" : request.Method)} {request.GetEncodedPathAndQuery()} {context.Response.StatusCode}");
if (request.Method == "POST")
{
}
Console.ResetColor();
}
return Task.CompletedTask;
});
try
{
await next();
}
catch (Exception ex)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"{request.Method} {request.GetEncodedPathAndQuery()} => {ex.Message}");
Console.ResetColor();
}
throw;
}
});
var assembly = Assembly.GetExecutingAssembly();
var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = null,
DictionaryKeyPolicy = null,
WriteIndented = true
};
foreach (var type in assembly.GetTypes())
{
if (!type.IsClass) continue;
object? instance = null;
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
foreach (var method in methods)
{
if (method.GetCustomAttribute<GETAttribute>() is { } getAttr)
{
instance ??= method.IsStatic ? null : Activator.CreateInstance(type);
var del = CreateCompatibleDelegate(method, instance, jsonOptions);
Console.WriteLine($"{type.FullName}.{method.Name} => GET {getAttr.Path}");
GET(getAttr.Path, del);
}
if (method.GetCustomAttribute<POSTAttribute>() is { } postAttr)
{
instance ??= method.IsStatic ? null : Activator.CreateInstance(type);
var del = CreateCompatibleDelegate(method, instance, jsonOptions);
Console.WriteLine($"{type.FullName}.{method.Name} => POST {postAttr.Path}");
POST(postAttr.Path, del);
}
if (method.GetCustomAttribute<PUTAttribute>() is { } putAttr)
{
instance ??= method.IsStatic ? null : Activator.CreateInstance(type);
var del = CreateCompatibleDelegate(method, instance, jsonOptions);
Console.WriteLine($"{type.FullName}.{method.Name} => POST {putAttr.Path}");
PUT(putAttr.Path, del);
}
if (method.GetCustomAttribute<MAPAttribute>() is { } mapAttr)
{
instance ??= method.IsStatic ? null : Activator.CreateInstance(type);
var del = CreateCompatibleDelegate(method, instance, jsonOptions);
Console.WriteLine($"{type.FullName}.{method.Name} => POST {mapAttr.Path}");
MAP(mapAttr.Path, del);
}
}
}
//webApplication.UseHttpsRedirection();
webApplication.UseWebSockets(); // we use a custom SignalR because recrooms is so old its out of date...
hasInit = true;
}
public void Run(string? url = null)
{
if (!hasInit)
throw new InvalidOperationException("Call ServerAPI.Init() before Run().");
webApplication.Run(url);
}
private static Delegate CreateCompatibleDelegate(MethodInfo method, object? instance, JsonSerializerOptions? options = null)
{
options ??= new JsonSerializerOptions
{
PropertyNamingPolicy = null,
DictionaryKeyPolicy = null,
WriteIndented = true
};
var parameters = method.GetParameters();
bool requiresAuth = method.GetCustomAttribute<UseAuthorizationAttribute>() != null;
bool isTask = typeof(Task).IsAssignableFrom(method.ReturnType);
Type? taskResultType = null;
if (isTask && method.ReturnType.IsGenericType)
{
taskResultType = method.ReturnType.GetGenericArguments()[0];
}
return new Func<HttpContext, Task<IResult>>(async ctx =>
{
IDictionary<string, object>? info = null;
MongoDB.User? user = null;
if (requiresAuth)
{
var authHeader = ctx.Request.Headers.Authorization;
info = JsonWebToken.VerifyAndDecode(authHeader);
if (info == null)
return Results.Unauthorized();
long sub = long.Parse((string)info["sub"]);
user = MongoDB.usersCollection
.Find(u => u.AccountId == sub)
.FirstOrDefault();
if (user == null)
return Results.Unauthorized();
}
object?[] args = [.. parameters.Select(p =>
{
if (p.ParameterType == typeof(HttpContext))
return ctx;
if (requiresAuth && p.ParameterType == typeof(MongoDB.User))
return user;
if (ctx.Request.RouteValues.TryGetValue(p.Name, out var value))
{
if (value == null) return null;
if (p.ParameterType.IsEnum)
return Enum.Parse(p.ParameterType, value.ToString()!);
return Convert.ChangeType(value, p.ParameterType);
}
return null;
})];
object? result = method.Invoke(instance, args);
if (isTask)
{
if (result is Task task)
{
await task.ConfigureAwait(false);
if (taskResultType != null)
{
var resultProperty = task.GetType().GetProperty("Result");
result = resultProperty?.GetValue(task);
}
else
{
result = null;
}
}
}
if (result is IResult iResult)
return iResult;
return Results.Json(result, options);
});
}
[AttributeUsage(AttributeTargets.Method)]
public class GETAttribute(string path) : Attribute
{
public string Path { get; } = path;
}
[AttributeUsage(AttributeTargets.Method)]
public class MAPAttribute(string path) : Attribute
{
public string Path { get; } = path;
}
[AttributeUsage(AttributeTargets.Method)]
public class POSTAttribute(string path) : Attribute
{
public string Path { get; } = path;
}
[AttributeUsage(AttributeTargets.Method)]
public class PUTAttribute(string path) : Attribute
{
public string Path { get; } = path;
}
[AttributeUsage(AttributeTargets.Method)]
public class UseAuthorizationAttribute() : Attribute
{
}
}
}

61
Signatures.cs Normal file
View File

@@ -0,0 +1,61 @@
using System.Security.Cryptography;
using System.Text;
namespace Stella
{
public class Signatures
{
private static RSA? _rsa;
public static void Init()
{
try
{
string pem = File.ReadAllText(Path.Combine("Data", "PrivateKey.pem"));
_rsa = RSA.Create();
_rsa.ImportFromPem(pem.ToCharArray());
}
catch (Exception ex)
{
throw new Exception("Error setting up Signatures: " + ex.Message);
}
}
public static string Sign(byte[] data)
{
if (_rsa == null)
throw new InvalidOperationException("Signatures not initialized. Call Init() first.");
byte[] signatureBytes = _rsa.SignData(data, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
return Convert.ToBase64String(signatureBytes);
}
public static string Sign(dynamic data)
{
if (_rsa == null)
return "never called init";
string json = System.Text.Json.JsonSerializer.Serialize(data);
byte[] dataBytes = Encoding.UTF8.GetBytes(json);
byte[] signature = _rsa.SignData(dataBytes, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
return Convert.ToBase64String(signature);
}
public static string Sign(string data)
{
if (_rsa == null)
return "never called init";
string json = System.Text.Json.JsonSerializer.Serialize(data);
byte[] dataBytes = Encoding.UTF8.GetBytes(json);
byte[] signature = _rsa.SignData(dataBytes, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
return Convert.ToBase64String(signature);
}
}
}

19
Stella.csproj Normal file
View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="Models\NewFile.txt" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="3.5.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
</ItemGroup>
</Project>