Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2d1df72
Fix: fix util prompt int function (#452)
kunrex Feb 9, 2026
d3a8728
Add Empty Spawn Instance Handler
gqvz Jan 17, 2026
9b1168e
Add redis cache backup and restore commands
gqvz Jan 17, 2026
b873f82
Refactor Redis command execution to use environment variable for pass…
gqvz Jan 31, 2026
d0707e5
Enhance Redis backup command to conditionally include user and passwo…
gqvz Jan 31, 2026
07cec29
Cleanup: add cache cleanup
kunrex Feb 3, 2026
3d967ef
Feat: Add redis set up to beast init and beast config
kunrex Feb 5, 2026
4961b17
Add instanced challenges
kunrex Feb 3, 2026
f068061
Add redis config setup
kunrex Feb 6, 2026
27575b2
Fix: fix beast setup postgres dsn
kunrex Feb 6, 2026
cd6ca21
Feat: Add healthproiber init to beast init
kunrex Feb 9, 2026
66f44b7
Warn: add redis warning
kunrex Feb 9, 2026
42be447
Feat: add acl save to redis init
kunrex Feb 9, 2026
bc814f5
Erros: Add better error messages
kunrex Feb 11, 2026
4e1eb19
Fix: fix readme port mapping
kunrex Feb 18, 2026
53d1f18
Feat: Add util functions for executing commands
kunrex Feb 7, 2026
944fa0f
Feat: Add check.sh validation for instance challenges
kunrex Feb 7, 2026
ba713b7
Feat: Add check route with validation
kunrex Feb 7, 2026
be6db2b
Fix: fix unnecessary change
kunrex Feb 7, 2026
8aca4ca
Checks: Check if port 22 is exposed on all containers and refactor ut…
kunrex Feb 7, 2026
cef3871
Add: Add chmod to challenge setup
kunrex Feb 11, 2026
eef3cac
Fix: fix check path bugs and confirm test
kunrex Feb 11, 2026
e496285
Fix: fix bugs, update typos, add temp utils
kunrex Feb 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions _examples/example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ default_cpu_shares = 1024
default_memory_limit = 1024
default_pids_limit = 100

# Port range for localhost deployments (format: START:END)
local_host_port_range = "30000:40000"

# List of ip addresses of all the servers where challenge could be deployed for
# balanced load accross servers.
[available_servers]
Expand All @@ -44,6 +47,9 @@ username = "user1"
# Path to private SSH key for interacting with the server.
ssh_key_path = "/path/to/your/private/key1"

# Port range for this server (format: START:END)
port_range = "30000:40000"

# Status of remote server to be used
# If it is set to false then that remote server will not be used
active = false
Expand All @@ -53,10 +59,13 @@ active = false
host = "localhost"

# Username to be used for ssh connection (Leave empty for localhost)
username = "user1"
username = ""

# Path to private SSH key for interacting with the server. (Leave empty for localhost)
ssh_key_path = "/path/to/your/private/key1"
ssh_key_path = ""

# Port range for this server (format: START:END) - uses local_host_port_range if empty
port_range = ""

# Status of remote server to be used
active = true
Expand Down Expand Up @@ -113,6 +122,19 @@ host = "localhost"
port = "5432"
sslmode = "prefer"

[redis_config]
host = "localhost"
port = "6379"
password = ""
user = ""

[instance_config]
# Port Range for localhost. per-server this is configured via `port-range`
local_host_port_range = '10000:11000'
default_expiration = 300
max_extension = 600
max_instances_per_user = 3

# The following fields are required only while hosting a competition on beast
# This section contains information about the competition to be hosted
# Structure of the sections with the acceptable fields are:
Expand Down
12 changes: 12 additions & 0 deletions _examples/instanced-compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:7.4-apache

# Install MySQL extension
RUN docker-php-ext-install mysqli pdo pdo_mysql

# Copy challenge files
COPY challenge/ /var/www/html/

# Set permissions
RUN chown -R www-data:www-data /var/www/html

EXPOSE 80
89 changes: 89 additions & 0 deletions _examples/instanced-compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Instanced Docker Compose Challenge Example

This is an example of an **instanced challenge using Docker Compose** - a multi-container challenge where each user gets their own isolated environment with a web server and database.

## Architecture

```
┌──────────────────────────────────────────┐
│ User's Instanced Environment │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ PHP/Apache │ ───▶ │ MySQL │ │
│ │ (web) │ │ (db) │ │
│ └─────────────┘ └─────────────┘ │
│ │ │
│ ▼ │
│ Port: 31234 (dynamically assigned) │
└──────────────────────────────────────────┘
```

## Key Configuration

In `beast.toml`:

```toml
[challenge.metadata]
instanced = true
instance_expiration = 600 # 10 minutes

[challenge.env]
docker_compose = "docker-compose.yml"
default_port = 8080
```

In `docker-compose.yml`, use the `INSTANCE_PORT` environment variable:

```yaml
services:
web:
ports:
- "${INSTANCE_PORT:-8080}:80"
```

## Challenge Details

This is a SQL injection challenge:

1. The login form is vulnerable to SQL injection
2. Bypass authentication to login as admin
3. The flag is stored in the `secrets` table

### Solution

```
Username: admin' OR '1'='1' --
Password: anything
```

Or use UNION-based injection to extract data directly.

## Testing Locally

```bash
# Build and run locally (for testing)
cd _examples/instanced-compose
docker-compose up -d

# Access at http://localhost:8080
```

## Usage via Beast API

```bash
# Spawn your instance
curl -X POST -H "Authorization: Bearer $TOKEN" \
http://localhost:8080/api/instances/instanced-compose/spawn

# Response:
# {
# "instance_id": "abc123def456",
# "challenge_name": "instanced-compose",
# "hosted_address": "localhost",
# "port": 31234,
# "expires_at": "2024-01-15T10:40:00Z",
# "ttl_seconds": 600
# }

# Access your instance
open http://localhost:31234
```
33 changes: 33 additions & 0 deletions _examples/instanced-compose/beast.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[author]
name = "beast-admin"
email = "admin@beast.local"
ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ"

[challenge.metadata]
name = "instanced-compose"
flag = "FLAG{c0mp0s3_1nst4nc3s_r0ck!}"
type = "web"
description = "A web challenge with database backend. Each user gets their own isolated environment!"
points = 200
difficulty = "medium"
tags = ["web", "sql", "instanced"]
maxAttemptLimit = 100
instanced = true
instance_expiration = 12

[[challenge.metadata.hints]]
text = "Check for SQL injection vulnerabilities"
points = 30

[[challenge.metadata.hints]]
text = "The admin password might be in the database..."
points = 50

[challenge.env]
docker_compose = "docker-compose.yml"
default_port = 8080

[resource]
cpu_shares = 1024
memory_limit = 536870912
pids_limit = 100
158 changes: 158 additions & 0 deletions _examples/instanced-compose/challenge/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<!DOCTYPE html>
<html>
<head>
<title>Secret Vault - Login</title>
<style>
body {
font-family: 'Segoe UI', Arial, sans-serif;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
color: #fff;
}
.container {
background: rgba(255, 255, 255, 0.1);
padding: 40px;
border-radius: 15px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
width: 350px;
}
h1 {
text-align: center;
margin-bottom: 30px;
color: #00d9ff;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
color: #aaa;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 12px;
border: none;
border-radius: 8px;
background: rgba(255, 255, 255, 0.1);
color: #fff;
font-size: 16px;
box-sizing: border-box;
}
input[type="submit"] {
width: 100%;
padding: 14px;
border: none;
border-radius: 8px;
background: #00d9ff;
color: #1a1a2e;
font-size: 16px;
font-weight: bold;
cursor: pointer;
transition: background 0.3s;
}
input[type="submit"]:hover {
background: #00b8d4;
}
.error {
background: rgba(255, 0, 0, 0.2);
padding: 10px;
border-radius: 8px;
margin-bottom: 20px;
text-align: center;
}
.success {
background: rgba(0, 255, 0, 0.2);
padding: 10px;
border-radius: 8px;
margin-bottom: 20px;
text-align: center;
}
.hint {
text-align: center;
margin-top: 20px;
color: #666;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<h1>Secret Vault</h1>

<?php
$error = '';
$success = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$host = getenv('DB_HOST') ?: 'db';
$user = getenv('DB_USER') ?: 'challenge';
$pass = getenv('DB_PASS') ?: 'challengepass';
$dbname = getenv('DB_NAME') ?: 'ctf';

$conn = new mysqli($host, $user, $pass, $dbname);

if ($conn->connect_error) {
$error = "Connection failed. Please try again.";
} else {
$username = $_POST['username'];
$password = $_POST['password'];

// VULNERABLE: SQL Injection!
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = $conn->query($query);
Comment on lines +107 to +108

Copilot AI Feb 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The login handler builds an SQL query by directly interpolating $_POST['username'] and $_POST['password'] into the string, which makes this endpoint vulnerable to SQL injection. An attacker can craft input such as admin' OR '1'='1 in the username field to bypass authentication and read arbitrary data from the users and secrets tables (including the flag). Use parameterized queries/prepared statements and avoid concatenating raw user input into SQL strings.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @gqvz


if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();

if ($row['role'] === 'admin') {
// Admin login - show secrets
$secrets_query = "SELECT * FROM secrets";
$secrets_result = $conn->query($secrets_query);

$success = "Welcome Admin! Here are your secrets:<br><br>";
while ($secret = $secrets_result->fetch_assoc()) {
$success .= "<b>" . htmlspecialchars($secret['secret_name']) . ":</b> " .
htmlspecialchars($secret['secret_value']) . "<br>";
}
} else {
$success = "Welcome, " . htmlspecialchars($row['username']) . "! You're logged in as a regular user.";
}
} else {
$error = "Invalid username or password!";
}

$conn->close();
}
}
?>

<?php if ($error): ?>
<div class="error"><?php echo $error; ?></div>
<?php endif; ?>

<?php if ($success): ?>
<div class="success"><?php echo $success; ?></div>
<?php else: ?>
<form method="POST">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" required placeholder="Enter username">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" required placeholder="Enter password">
</div>
<input type="submit" value="Login">
</form>
<?php endif; ?>

<p class="hint">Hint: Try logging in as admin to see the secrets!</p>
</div>
</body>
</html>
29 changes: 29 additions & 0 deletions _examples/instanced-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'

services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
# Use INSTANCE_PORT env var if available, otherwise default to 8080
- "${INSTANCE_PORT:-8080}:80"
environment:
- DB_HOST=db
- DB_USER=challenge
- DB_PASS=challengepass
- DB_NAME=ctf
depends_on:
- db
restart: unless-stopped

db:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=rootpass
- MYSQL_DATABASE=ctf
- MYSQL_USER=challenge
- MYSQL_PASSWORD=challengepass
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
restart: unless-stopped
Loading