因为是准备给学校搭的靶场,所以用的是阿里云的学生机
CPU: 1核
内存: 2 GiB
带宽: 1Mbps
操作系统: CentOS 7.3c’la’e 64位
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
开启mysql服务
systemctl start mariadb
设置数据库root账户密码
先回车,然后u,输入准备设置的密码,然后一路y
mysql_secure_installation
添加一个docker的yum源(我这里是阿里云)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker ce
yum -y install docker-ce-17.12.1.ce
DaoCloud配置docker镜像源加速
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
重启docker服务
sudo systemctl restart docker
确认安装成功
docker --version
# 下载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
frp 是一个高性能的反向代理应用,可以帮助您轻松地进行内网穿透,对外网提供服务,支持 tcp, http, https 等协议类型,并且 web 服务支持根据域名进行路由转发。
下载frp并安装(没那啥的话很慢)
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
编辑/etc/frp/frps.ini
[common]
bind_port = 7897
bind_addr = 0.0.0.0
token =thisistoken
启动frps系统服务
systemctl start frps
创建网络并启动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"
这部分有错误的话
docker logs name #看下contain日志
docker stop <name> # =停止对应容器
docker system prune #自动清理
创建网络frpcadmin用于ctfd容器和frpc容器通信
docker network create frpcadmin
docker network connect frpcadmin id #
#将frpc和ctfd容器单独连接到网络frpcadmin,注意要等容器创建好之后再连接,因此ctfd将在稍后连接
查看frpcadmin网络的连接情况并记录frpc容器的网络IP
docker network inspect frpcadmin
编辑/etc/frp/frpc.ini
[common]
server_addr = 172.17.0.1
server_port = 7897
token=thisistoken
编辑/frp_0.33.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
这里用的老版本,然而ctfd有个版本有问题,暂且不管了
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
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"]
docker-compose build
docker-compose up -d
docker network connect frpcadmin <ctfd容器名或者ID>
docker network inspect frpcadmin
这部分建议直接看赵总博客
最后给大家分享个长亭Xray高级版破解的项目,项目地址
CTFd-Whale 推荐部署实践
从零开始利用docker搭建CTFd动态独立靶机的靶场