Introduction to CTFd#
CTFd is a free and open-source CTF (Capture the Flag) platform that provides a powerful set of tools and solutions for creating, organizing, managing, and hosting CTF competitions and challenging activities. CTFd is designed to meet the needs of users with various skill levels and backgrounds, offering an easy-to-use and configurable interface.
CTFd supports various types of challenges, including Web, reverse engineering, cryptography, binaries, forensics, and miscellaneous, and provides multiple competition types, including individual competitions, team competitions, and directed competitions.
CTFd also offers a range of powerful plugins and themes that can be configured and extended as needed.
CTFd Installation#
- Set up using this article, simple and easy to understand
https://mp.weixin.qq.com/s/oMI9h_hBc373poVsR2CiVw
The project address based on the above article:
GitHub - Un1kTeam/CTFd: CTFs as you need them
This project version is 3.3.0 and can be localized, and it also includes frp, ctfd-whale @ 138b042, ctf-whale can be downloaded and installed separately.
The general process is as follows:
- Create a cluster with a single server, then join the cluster
sudo docker swarm init
- View nodes and get the id value
sudo docker node ls
- Update the label information on the docker node
sudo docker node update --label-add='name=linux-1' nfvla0597w8zpkoing2mvpe89
- Once the setup is complete, you can start building the image
sudo docker-compose up -d
- After finishing, open the browser and visit http://127.0.0.1:9124
Notes:
- Sometimes due to network issues, you may need to run
docker-compose up -d
multiple times. - When pulling the environment with docker, there may be issues with the internal ubuntu container not being able to access the aliyun source, and you need to set the DNS resolution in ubuntu as follows:
sudo vim /etc/resolve.conf
nameserver 114.114.114.114
nameserver 223.5.5.5
Simplified Installation#
- (Optional) A VMware version already set up by someone else: VMware Virtual Machine Version
Directly using someone else's virtual machine setup can be a bit troublesome to set up yourself; here I will record some issues and experiences during the usage process.
- There is also an automatic script for setting up CTFd, using the nip.io domain.
Project address: GitHub - pwnthebox/ctfd-auto-deploy
sh <(curl -s https://raw.githubusercontent.com/pwnthebox/ctfd-auto-deploy/master/install.sh)
The values that need to be manually entered are as follows:
Http Domain Suffix
: domain/ip
External Http Port
: target machine http mapping port
(cannot be 80 here, as 80 is assigned to CTFd)
Direct Minimum/Maximum Port
: target machine port open range
CTFd Environment Testing#
Open the browser and enter http://127.0.0.1:9124 to access, and the following interface will be returned:
After setting everything step by step, if the banner size is too large, there may be some issues with the style, once the setup is complete, it can be used.
Dynamic Target Field Configuration#
After logging in, enter the management interface and click on the Whale plugin
If there is no domain, you can leave Http Domain Suffix
blank.
Fill in the Direct IP Address
with the IP address of the virtual machine.
Creating Questions#
Select dynamic_docker
Write the question title, category, description, etc. For the docker image, fill in the address of the docker image, change the Frp Redirect Type to Direct, and set the Frp Redirect Port to the internal port of the docker container, usually specified in the dockerfile.
Set the score for the question, Initial Value is the initial score, Decay Limit is the decay count, after a question is answered twice, it will start using the score set in Minimum Value, and Score Type is set to Dynamic Score. If you set the Decay Limit to 0 and do not set a minimum score, then Score Type can only be changed to Static Score.
After creating the question, test it.
Access the question environment
Test submitting the flag.
Thus, the environment setup is complete.
Other Settings and Notes#
Dynamic Flag Generation in Dockerfile#
CMD ["/bin/sh", "-c", "docker-php-entrypoint"]
echo $FLAG > /flag && export FLAG=not_flag && FLAG=not_flag
CTFd Page Management Settings#
- Modify the homepage
<style>
body {
# Replace the homepage background image
background-image: url("/files/f28557e77fc748c85633ae868e2f0742/background.png");
background-size:cover;
}
</div>
</main>
<footer class="footer">
<div class="container text-center">
<a href="https://ctfd.io" class="text-secondary">
<small class="text-muted"></small>
</a>
</div>
</footer>
<script defer src="/themes/core/static/js/vendor.bundle.min.js?d=59b78ea4"></script>
<script defer src="/themes/core/static/js/core.min.js?d=59b78ea4"></script>
<script defer src="/themes/core/static/js/helpers.min.js?d=59b78ea4"></script>
<script defer src="/themes/core/static/js/pages/main.min.js?d=59b78ea4"></script>
</body>
</html>
</style>
Mapping CTFd Platform to the External Network#
After the CTFd platform is installed, settings can be done at any time, not necessarily before setting up the CTFd platform. The following places need to be set:
- Map the platform port (9124) on the router at the internet exit.
- Map the environment port (28000-28200) on the router at the internet exit.
- Configure whale (as shown below)
In the Frps config template [generated]
, set subdomain_host
to the public IP or domain.
The above settings are sufficient.
Read-only File System Solution (Untested)#
Modify the docker-compose.yml
file, remove the :ro
on line 22.
Some Target Fields Unable to Access the Internet (Untested)#
You need to modify the docker-compose.yml file, as shown in the figure below:
The container has started; modifying this area will cause an error.
CTFd Localization#
Import the files into the CTFd directory.
Project address: GitHub - Gu-f/CTFd_chinese_CN: Localization records for various versions of the CTFd platform. key: Chinese, localization, translation, Chinese, CN, CTFd
The localized version has been pushed to the hub docker.
docker pull liangchenga/ctfd-341_ctfd:latest
References#
ctfd-whale/install.zh-cn.md at master · frankli0324/ctfd-whale · GitHub
How to Correctly Use Docker to Create a CTF Question - Von's Blog | Von Blog
GitHub - antlers12/CTFd_sqlilabs
CTFd & ctfd-whale Dynamic Target Machine Setup and Maintenance · Yuque
GitHub - CTFTraining/CTFTraining: CTF Training Classic Problem Reproduction Environment
BUUCTF Question Contribution Guidelines – glzjin