CTF比赛平台搭建
克隆CTFd
GitHub:https://github.com/CTFd/CTFd
1 | ┌──(kali㉿kali)-[/var/www/html] |
安装docker
1 | ┌──(kali㉿kali)-[/var/www/html/CTFd] |
1 | ┌──(kali㉿kali)-[/var/www/html/CTFd] |
添加执行权限
1 | ┌──(kali㉿kali)-[/var/www/html/CTFd] |
在CTFd根目录下启动docker
1 | ┌──(kali㉿kali)-[/var/www/html/CTFd] |
注:首次启动由于下载依赖等会比较慢
平台配置
打开浏览器,输入127.0.0.1:8000配置赛事相关信息
添加题目
在GitHub上找题目,clone到本地
1 | ┌──(kali㉿kali)-[/var/www/html/CTFd/ctf_training] |
实际测试发现不能把所有的题目都clone下来,就先试一道题
1 | ┌──(kali㉿kali)-[/var/www/html/CTFd/ctf_training] |
docker images 命令查看已有镜像
docker build ./ -t [镜像名称] 启动Dockerfile文件,创建镜像
1 | ┌──(kali㉿kali)-[/var/…/html/CTFd/ctf_training/0ctf_2016_unserialize] |
1 | ┌──(kali㉿kali)-[/var/…/html/CTFd/ctf_training/0ctf_2016_unserialize] |
再通过镜像创建容器:
1 | ┌──(kali㉿kali)-[/var/…/html/CTFd/ctf_training/0ctf_2016_unserialize] |
查看现有容器:
1 | ┌──(kali㉿kali)-[/var/…/html/CTFd/ctf_training/0ctf_2016_unserialize] |
访问127.0.0.1:20000即可访问到刚刚添加的题目,20000是刚刚指定的端口
打开题目容器:
1 | docker exec -i -t <container> /bin/sh |
为题目添加flag:
1 | ┌──(kali㉿kali)-[/var/…/html/CTFd/ctf_training/0ctf_2016_unserialize] |
最后在后台添加题目地址等信息
同理可添加其他题目
搭建中遇到的问题
- git clone 命令克隆失败:
1 | ┌──(kali㉿kali)-[/var/www/html/CTFd/ctf_training] |
由于网络问题,可能需要多克隆几次,实在不行可以试试把压缩包下载下来
有些题目克隆下来可能有问题,运行过程中可能会报错(目前仍不了解是什么原因)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32┌──(kali㉿kali)-[/var/…/html/CTFd/ctf_training/34c3ctf_2017_urlstorage]
└─$ sudo docker build ./ -t urlstorage 1 ⨯
Sending build context to Docker daemon 282.6kB
Step 1/7 : FROM ubuntu:18.10
18.10: Pulling from library/ubuntu
8a532469799e: Pull complete
32f4dcec3531: Pull complete
230f0701585e: Pull complete
e01f70622967: Pull complete
Digest: sha256:7d657275047118bb77b052c4c0ae43e8a289ca2879ebfa78a703c93aa8fd686c
Status: Downloaded newer image for ubuntu:18.10
---> 9dc19675e327
Step 2/7 : ENV DOCKER=1 PHANTOMJS_VERSION="2.1.1"
---> Running in 98e854ac92f3
Removing intermediate container 98e854ac92f3
---> 154a521cb653
Step 3/7 : RUN sed -i 's/http:\/\/archive.ubuntu.com\//http:\/\/mirrors.tuna.tsinghua.edu.cn\//g' /etc/apt/sources.list && sed -i '/security/d' /etc/apt/sources.list && apt-get -y update && apt-get -yqq install curl python3 python3-pip mariadb-server libmysqlclient-dev nginx wget bzip2 libfreetype6 libfontconfig && mkdir -p /srv/var && wget --local-encoding=UTF-8 --no-check-certificate -O /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 && tar -xjf /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -C /tmp && rm -f /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 && mv /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/ /srv/var/phantomjs && ln -s /srv/var/phantomjs/bin/phantomjs /usr/bin/phantomjs && pip3 install django gunicorn mysqlclient requests lxml pyyaml django-simple-captcha
---> Running in 8d702a730242
Ign:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic InRelease
Ign:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic-updates InRelease
Ign:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic-backports InRelease
Err:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic Release
404 Not Found [IP: 101.6.15.130 80]
Err:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic-updates Release
404 Not Found [IP: 101.6.15.130 80]
Err:6 http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic-backports Release
404 Not Found [IP: 101.6.15.130 80]
Reading package lists...
E: The repository 'http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic Release' does not have a Release file.
E: The repository 'http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic-updates Release' does not have a Release file.
E: The repository 'http://mirrors.tuna.tsinghua.edu.cn/ubuntu cosmic-backports Release' does not have a Release file.
The command '/bin/sh -c sed -i 's/http:\/\/archive.ubuntu.com\//http:\/\/mirrors.tuna.tsinghua.edu.cn\//g' /etc/apt/sources.list && sed -i '/security/d' /etc/apt/sources.list && apt-get -y update && apt-get -yqq install curl python3 python3-pip mariadb-server libmysqlclient-dev nginx wget bzip2 libfreetype6 libfontconfig && mkdir -p /srv/var && wget --local-encoding=UTF-8 --no-check-certificate -O /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 && tar -xjf /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -C /tmp && rm -f /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 && mv /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/ /srv/var/phantomjs && ln -s /srv/var/phantomjs/bin/phantomjs /usr/bin/phantomjs && pip3 install django gunicorn mysqlclient requests lxml pyyaml django-simple-captcha' returned a non-zero code: 100许多命令都需要root权限,如果在哪一步运行报错了可以检查以下是否是权限问题