Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
50c5716
change display
phannhat17 Sep 7, 2023
8d6561e
change README
phannhat17 Sep 7, 2023
3a1e893
change demo
phannhat17 Sep 7, 2023
c519412
update display tcp connection
phannhat17 Sep 8, 2023
aa5c204
fix update page
phannhat17 Sep 8, 2023
d6c0d38
update readme
phannhat17 Sep 8, 2023
15fb74d
change xhr to fetch
phannhat17 Sep 8, 2023
b13daeb
add filter in admin dashboard
phannhat17 Sep 8, 2023
90067a7
add original details
phannhat17 Sep 19, 2023
dd4e2c0
update user mode
phannhat17 Nov 18, 2023
2d5a384
test
phannhat17 Nov 18, 2023
66cfc88
fix
phannhat17 Nov 18, 2023
a40a01a
update README
phannhat17 Nov 18, 2023
cd9dd1d
update dashboard
phannhat17 Nov 18, 2023
baecdd8
Update to work w core-beta
phannhat17 Feb 28, 2024
dd90bb1
update README
phannhat17 Feb 28, 2024
11c9770
Create LICENSE
phannhat17 Feb 28, 2024
c615263
Remove unnecessary sections from README.md
phannhat17 Feb 28, 2024
453ceb6
fix connection_info
phannhat17 Feb 28, 2024
2de79d3
Add max containers per team/user and add minor optimize
phannhat17 Feb 12, 2025
356d08c
update roadmap
phannhat17 Feb 12, 2025
e3f79eb
Update README
phannhat17 Feb 12, 2025
2a5447a
Update REAME
phannhat17 Feb 12, 2025
364d73c
minor README fix
phannhat17 Feb 12, 2025
4706569
Refactor ContainerChallenge class for improved readability
phannhat17 Feb 17, 2025
56b5135
Refactor container routes and templates for improved structure and re…
phannhat17 Feb 17, 2025
3a178c7
Refactor container routes and improve settings template for enhanced …
phannhat17 Feb 17, 2025
3d786dd
Change admin dashboard frontend
phannhat17 Feb 17, 2025
454bb73
Update container routes and templates for admin access and improved s…
phannhat17 Feb 18, 2025
61a755a
Implement bulk delete functionality for containers in admin routes an…
phannhat17 Feb 18, 2025
1d2901e
Refactor container management and flag handling; remove command input…
phannhat17 Feb 18, 2025
519fb90
Add flag configuration options to challenge creation and update forms
phannhat17 Feb 18, 2025
755f1b0
Enhance container management by killing containers on flag usage and …
phannhat17 Feb 18, 2025
36df23e
Update README and refactor container management for flag handling and…
phannhat17 Feb 18, 2025
45c8f25
Update doc for create and update challenge in frontend
phannhat17 Feb 19, 2025
8083814
Update admin dashboard UI
phannhat17 Feb 19, 2025
fa83974
Minor update on UI
phannhat17 Feb 20, 2025
927efac
Refactor UI components and remove unused clipboard functionality in c…
phannhat17 Feb 21, 2025
c378ba5
Refactor flag submission logic and improve error handling in Containe…
phannhat17 Feb 21, 2025
1104440
Add cheat logging functionality and update README with new features
phannhat17 Feb 21, 2025
e4a3dd7
update cheat UI
phannhat17 Feb 24, 2025
5b66287
Fix serious logic bug
phannhat17 Feb 27, 2025
2e80179
Fixed container port and fixed container expiry
jabb4 May 24, 2025
19aaf56
Added sleep to assure the fetch is complete
jabb4 May 24, 2025
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Andy Smith
Copyright (c) 2024 Phan Nhat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
188 changes: 180 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,191 @@
# CTFd Docker Containers Plugin

This CTFd plugin allows you to run ephemeral Docker containers for specific challenges. Teams can request a container to use as needed, and its lifecycle will be managed by the plugin.
<div align="center">
<h3 align="center">CTFd Docker Containers Plugin</h3>
<p align="center">
A plugin to create containerized challenges for your CTF contest.
</p>
</div>

## Table of Contents
1. [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
2. [Usage](#usage)
- [Using Local Docker Daemon](#using-local-docker-daemon)
- [Using Remote Docker via SSH](#using-remote-docker-via-ssh)
3. [Demo](#demo)
4. [Roadmap](#roadmap)
5. [License](#license)
6. [Contact](#contact)

---

## Getting Started

This section provides instructions for setting up the project locally.

### Prerequisites

To use this plugin, you should have:
- Experience hosting CTFd with Docker
- Basic knowledge of Docker
- SSH access to remote servers (if using remote Docker)

### Installation

1. **Clone this repository:**
```bash
git clone https://github.com/phannhat17/CTFd-Docker-Plugin.git
```
2. **Rename the folder:**
```bash
mv CTFd-Docker-Plugin containers
```
3. **Move the folder to the CTFd plugins directory:**
```bash
mv containers /path/to/CTFd/plugins/
```

[Back to top](#ctfd-docker-containers-plugin)

---

## Usage

Place this plugin in your CTFd/plugins directory. The name of the directory MUST be "containers" (so if you cloned this repo, rename "CTFd-Docker-Plugin" to "containers").
### Using Local Docker Daemon

#### Case A: **CTFd Running Directly on Host:**
- Go to the plugin settings page: `/containers/settings`
- Fill in all fields except the `Base URL`.

![Settings Example](./image-readme/1.png)

#### Case B: **CTFd Running via Docker:**
- Map the Docker socket into the CTFd container by modify the `docker-compose.yml` file:
```bash
services:
ctfd:
...
volumes:
- /var/run/docker.sock:/var/run/docker.sock
...
```
- Restart CTFd
- Go to the plugin settings page: `/containers/settings`
- Fill in all fields except the `Base URL`.

### Using Remote Docker via SSH

For remote Docker, the CTFd host must have SSH access to the remote server.

#### Prerequisites:
- **SSH access** from the CTFd host to the Docker server
- The remote server's fingerprint should be in the `known_hosts` file
- SSH key files (`id_rsa`) and an SSH config file should be available

#### Case A: **CTFd Running via Docker**

1. **Prepare SSH Config:**
```bash
mkdir ssh_config
cp ~/.ssh/id_rsa ~/.ssh/known_hosts ~/.ssh/config ssh_config/
```

2. **Mount SSH Config into the CTFd container:**
```yaml
services:
ctfd:
...
volumes:
- ./ssh_config:/root/.ssh:ro
...
```

3. **Restart CTFd:**
```bash
docker-compose down
docker-compose up -d
```

#### Case B: **CTFd Running Directly on Host**

1. **Ensure SSH Access:**
- Test the connection:
```bash
ssh user@remote-server
```

2. **Configure Docker Base URL:**
- In the CTFd plugin settings page (`/containers/settings`), set:
```
Base URL: ssh://user@remote-server
```

3. **Restart CTFd:**
```bash
sudo systemctl restart ctfd
```

[Back to top](#ctfd-docker-containers-plugin)

---

## Demo

### Admin Dashboard
- Manage running containers
- Filter by challenge or player

![Manage Containers](./image-readme/manage.png)

### Challenge View

**Web Access** | **TCP Access**
:-------------:|:-------------:
![Web](./image-readme/http.png) | ![TCP](./image-readme/tcp.png)

### Live Demo

![Live Demo](./image-readme/demo.gif)

[Back to top](#ctfd-docker-containers-plugin)

---

## Roadmap

- [x] Support for user mode
- [x] Admin dashboard with team/user filtering
- [x] Compatibility with the core-beta theme
- [x] Monitor share flag
- [ ] Monitor detail on share flag
- [ ] Prevent container creation on solved challenge

For more features and known issues, check the [open issues](https://github.com/phannhat17/CTFd-Docker-Plugin/issues).

[Back to top](#ctfd-docker-containers-plugin)

---

## License

Distributed under the MIT License. See `LICENSE.txt` for details.

> This plugin is an upgrade of [andyjsmith's plugin](https://github.com/andyjsmith/CTFd-Docker-Plugin) with additional features.

If there are licensing concerns, please reach out via email (contact below).

To configure the plugin, go to the admin page, click the dropdown in the navbar for plugins, and go to the Containers page. Then you can click the settings button to configure the connection. You will need to specify some values, including the connection string to use. This can either be the local Unix socket, or an SSH connection. If using SSH, make sure the CTFd host can successfully SSH into the Docker target (i.e. set up public key pairs). The other options are described on the page. After saving, the plugin will try to connect to the Docker daemon and the status should show as an error message or as a green symbol.
[Back to top](#ctfd-docker-containers-plugin)

To create challenges, use the container challenge type and configure the options. It is set up with dynamic scoring, so if you want regular scoring, set the maximum and minimum to the same value and the decay to zero.
---

If you need to specify advanced options like the volumes, read the [Docker SDK for Python documentation](https://docker-py.readthedocs.io/en/stable/containers.html) for the syntax, since most options are passed directly to the SDK.
## Contact

When a user clicks on a container challenge, a button labeled "Get Connection Info" appears. Clicking it shows the information below with a random port assignment.
**Phan Nhat**
- **Discord:** ftpotato
- **Email:** contact@phannhat.id.vn
- **Project Link:** [CTFd Docker Plugin](https://github.com/phannhat17/CTFd-Docker-Plugin)

![Challenge dialog](dialog.png)
[Back to top](#ctfd-docker-containers-plugin)

A note, we used hidden teams as non-school teams in PCTF 2022 so if you want them to count for decreasing the dynamic challenge points, you need to remove the `Model.hidden == False,` line from the `calculate_value` function in `__init__.py`.
Loading