1.最近准备毕业设计,准备搭建CTFd动态独立靶机的靶场(ctfd+ctfd-whale)
2.动态独立靶机:每做一道题,就会自动生成一个虚拟题目环境,每一个环境刚刚生成的时候都是崭新的,且能为每个队伍生成一个独一无二的flag,防止flag分享作弊的行为
3.官方教程:https://www.zhaoj.in/read-6333.html
4.部分参考赵师傅、fjh1997师傅博客
1.准备一台具有公网IP的服务器
2.镜像采用CentOs 7.3,方便环境安装
(一)、安装一切需要安装的环境,这里我是centos的镜像,直接可以用yum源安装,首先更新yum源
yum update
yum install -y git nginx mariadb mariadb-server Mysql-python python-pip gcc python-devel yum-utils device-mapper-persistent-data lvm2 epel-release
1.开启mysql服务
systemctl start mariadb
2.初始化mysql,设置数据库root密码,首先enter然后问你是否设置root密码,输入y,然后设置密码,然后一直都是y
mysql_secure_installation
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum -y install docker-ce-17.12.1.ce
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
docker --version
systemctl start docker
(四)、安装docker-compose
1.三种安装方式:直接下载、pip安装、离线安装,如果直接下载慢可以用pip安装,pip安装也慢直接用离线安装,但是建议前两种方法
直接下载:
# 下载docker compose
curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 添加可执行权限
chmod +x /usr/local/bin/docker-compose
# 将文件copy到 /usr/bin/目录下
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# 查看版本
docker-compose --version
pip install --upgrade pip
pip install docker-compose
yum install python3-pip
4.使用pip3安装docker-compose即不会发生以上问题
pip3 install docker-compose
docker-compose --version
chmod +x /usr/local/bin/docker-compose
cd
wget https://github.com/fatedier/frp/releases/download/v0.29.0/frp_0.29.0_linux_amd64.tar.gz
tar -zxvf frp_0.29.0_linux_amd64.tar.gz
cd frp_0.29.0_linux_amd64
cp systemd/* /etc/systemd/system/
mkdir /etc/frp
cp frpc.ini frps.ini /etc/frp/
cp frpc frps /usr/bin/
chmod a+x /usr/bin/frpc /usr/bin/frps
systemctl enable frps
vim /etc/frp/frps.ini
内容如下:
[common]
bind_port = 7897
bind_addr = 0.0.0.0
token =thisistoken
3.启动frps系统服务
systemctl start frps
4.配置docker镜像加速:部署下阿里云的docker加速器:https://help.aliyun.com/document_detail/60750.html
5.编辑frpc.ini
修改/etc/frp/frpc.ini的配置文件
vim /etc/frp/frpc.ini
[common]
server_addr = 172.17.0.1
server_port = 7897
token=thisistoken
再修改/frp_0.29.0_linux_amd64/frpc.ini
[common]
server_addr = 172.17.0.1 # 这里填写宿主机ifconfig之后docker0的ip,因人而异,不要一摸一样填
server_port = 7897
token=thisistoken
admin_addr = 172.19.0.2 #这里填写frpc容器在frpcadmin网络里的ip,因人而异,不要一摸一样填
admin_port = 7400
log_file = ./frps.log
6.创建网络并启动frpc容器并配置frpc.ini
docker network create ctfd_frp-containers
docker run -d -v ~/frp_0.29.0_linux_amd64/frpc.ini:/etc/frp/frpc.ini --network="ctfd_frp-containers" --restart=always "glzjin/frp"
7.创建网络frpcadmin用于ctfd容器和frpc容器通信
docker network create frpcadmin
docker network connect frpcadmin id #
#将frpc和ctfd容器单独连接到网络frpcadmin,注意要等容器创建好之后再连接,因此ctfd将在稍后连接
8.docker ps查看刚刚创建的frp容器id,将frp容器加入frpcadmin,重启docker服务
docker network connect frpcadmin b05cafb1b224
systemctl restart docker
9.查看frpcadmin网络的连接情况并记录frpc容器的网络IP
docker network inspect frpcadmin
1.下载靶场和插件
git clone https://github.com/CTFd/CTFd.git
cd CTFd/
~~git reset 6c5c63d667a17aec159c8e26ea53dccfbc4d0fa3 --hard
#回滚到当前教程适合的版本~~
cd CTFd/plugins #打开ctfd插件目录
git clone https://github.com/glzjin/CTFd-Whale.git ctfd-whale #确保插件文件夹小写
cd ctfd-whale
~~git reset 5b32f457e9f56ee9b2b29495f4b3b118be3c57bd --hard #回滚到当前教程适合的版本~~
cd ../.. #返回ctfd主目录
vim docker-compose.yml
version: '2.2'
services:
ctfd:
build: .
user: root
restart: always
ports:
- "8000:8000" #第一个是访问ctfd的端口,第二个是docker端口映射出去的端口
environment:
- UPLOAD_FOLDER=/var/uploads
- DATABASE_URL=mysql+pymysql://root:ctfd@db/ctfd
- REDIS_URL=redis://cache:6379
- WORKERS=1
- LOG_FOLDER=/var/log/CTFd
- ACCESS_LOG=-
- ERROR_LOG=-
volumes:
- .data/CTFd/logs:/var/log/CTFd
- .data/CTFd/uploads:/var/uploads
- .:/opt/CTFd:ro
- /var/run/docker.sock:/var/run/docker.sock #添加这句即可,别的基本按照官方的不用动
depends_on:
- db
networks:
default:
internal:
db:
image: mariadb:10.4.12 #这里改成10.4.12,10.4.13会出错
restart: always
environment:
- MYSQL_ROOT_PASSWORD=ctfd
- MYSQL_USER=ctfd
- MYSQL_PASSWORD=ctfd
- MYSQL_DATABASE=ctfd
volumes:
- .data/mysql:/var/lib/mysql
networks:
internal:
# This command is required to set important mariadb defaults
command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --wait_timeout=28800, --log-warnings=0]
cache:
image: redis:4
restart: always
volumes:
- .data/redis:/data
networks:
internal:
networks:
default:
internal:
internal: true
~~3.改Dockerfile为以下来使用豆瓣源or阿里源:
进入CTFd目录 vim Dockerfile ,复制以下内容
FROM python:2.7-alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories &&\
apk update && \
apk add python python-dev linux-headers libffi-dev gcc make musl-dev py-pip mysql-client git openssl-dev
RUN adduser -D -u 1001 -s /bin/bash ctfd
WORKDIR /opt/CTFd
RUN mkdir -p /opt/CTFd /var/log/CTFd /var/uploads
RUN pip config set global.index-url https://pypi.doubanio.com/simple
RUN pip config set install.trusted-host pypi.doubanio.com
COPY requirements.txt .
RUN pip install -r requirements.txt -i https://pypi.doubanio.com/simple
COPY . /opt/CTFd
RUN for d in CTFd/plugins/*; do \
if [ -f "$d/requirements.txt" ]; then \
pip install -r $d/requirements.txt -i https://pypi.doubanio.com/simple; \
fi; \
done;
RUN chmod +x /opt/CTFd/docker-entrypoint.sh
RUN chown -R 1001:1001 /opt/CTFd
RUN chown -R 1001:1001 /var/log/CTFd /var/uploads
USER 1001
EXPOSE 8000
ENTRYPOINT ["/opt/CTFd/docker-entrypoint.sh"]
4.在CTFd目录qiurements.txt添加:banal==0.4.2
~~
5.构建启动镜像
docker-compose build
docker-compose up -d
7.将ctfd连接frpcadmin网络
docker ps查看ctfd的ID
docker network connect frpcadmin 8fc7550bc51f
8.查看是否加入成功docker network inspect frpcadmin
9.访问公网ip:8000端口即可
1.注册完admin账号之后点击
2.填写相关参数,注意要在template里面写上frpc.ini的内容,里面domain填写自己的。
3.配置完添加题目
5.测试,创建完点击,不出意外点击创建环境就能访问
6.靶机管理,查看flag