https://github.com/thealpha16/c2server
A multi-threaded http server written in C#
https://github.com/thealpha16/c2server
c-sharp dotnet-console http-server socket-programming
Last synced: 10 months ago
JSON representation
A multi-threaded http server written in C#
- Host: GitHub
- URL: https://github.com/thealpha16/c2server
- Owner: TheAlpha16
- License: gpl-3.0
- Created: 2024-11-01T14:48:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-01T16:31:50.000Z (over 1 year ago)
- Last Synced: 2025-06-17T04:05:20.736Z (12 months ago)
- Topics: c-sharp, dotnet-console, http-server, socket-programming
- Language: C#
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# C2 Server
An efficient and lightweight C2 (Command and Control) server built for secure communication and control over remote devices or clients in real-time. This server offers flexible routing, request handling, and built-in cookie management, designed for custom integration with tools and security projects.
## Features
- **Flexible Request Handling**: Supports custom HTTP methods, query parameters, and request parsing.
- **Cookie Management**: Efficient cookie parsing and support for managing session data.
- **Error Handling**: Defined HTTP error classes for custom exception handling.
- **Routing**: Custom routing for handling requests and responses.
- **Custom Protocol**: Built-in support for custom protocols and data serialization.
## Contents
- [Usage](#usage)
- [Configuration](#configuration)
- [API Reference](#api-reference)
- [License](#license)
## Usage
1. Clone the repsitory and navigate to the project directory.
```bash
git clone
cd C2Server
```
2. Use .NET SDK to build the project.
```bash
dotnet build
```
3. Run the server using the .NET CLI.
```bash
dotnet run
```
4. Server can be accessed at `8989` port.
```bash
curl -X GET http://localhost:8989/ping
```
## Configuration
- You can change the default port it binds to in the `.env` file.
- Define your routes as an async function in the `Routes.cs` file.
```csharp
public async static Task Ping(HTTPRequest request)
{
return new HTTPResponse().Text("Pong!");
}
```
## API Reference
- Access request data using the `HTTPRequest` object.
```csharp
Cookie token = request.Cookies["token"];
string someParameter = request.Queries["someKey"];
string body = request.Body;
string Referer = request.Headers["Referer"];
```
- Return response using `HTTPResponse` object from the handlers.
```csharp
HTTPResponse response = new HTTPResponse();
// Set cookie
var cookie = new Cookie("SessionID", "abc123")
{
Expiration = DateTime.UtcNow.AddHours(1),
Secure = true,
HttpOnly = true
};
response.AddCookie(cookie);
// Send text data in response
return response.Text("Welcome to C2Server!");
// Send JSON data
return response.JSON(new {
"status": "success",
"message": "ready to fire"
});
// Set a different HTTP status
return response.SetStatus(HTTPStatus.Accepted).JSON(new {
"status": "success",
"message": "ready to fire"
});
```
## License
This project is licensed under the GNU General Public License.