sudo apt-get update
sudo apt-get upgrade
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
curl -sSL https://get.daocloud.io/docker | sh
1. 更新系统包索引
sudo apt-get update
2. 添加HTTPS协议,允许apt从HTTPS安装软件包
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
3. 添加Docker公共密钥 Docker 官方源
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
4. 设置版本库类型,软件版本包括三种: stable、edge、test
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
5. 安装最新版docker-ce
sudo apt-get install docker-ce
6. 设置开机自启动并启动docker
sudo systemctl enable docker
sudo systemctl start docker
1. 进入https://github.com/docker/compose/releases 查看最新版本。
sudo curl -L https://github.com/docker/compose/releases/download/1.26.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
2. 设置权限
sudo chmod +x /usr/local/bin/docker-compose
3. 查看是否安装成功
docker-compose --version
出现docker-compose version 1.26.2即安装成功
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo docker-compose --version
因为20.04版本自带默认python版本为3.*,所以直接安装pip即可。
1.安装pip
sudo apt install python3-pip
2.更新库
sudo apt-get update
3.更新pip(一定要更新,不然后面建立容器项目会报错)
sudo pip3 install --upgrade pip
4.安装docker-compose
sudo pip3 install docker-compose
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://******.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
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
sudo cp systemd/* /etc/systemd/system/
sudo mkdir /etc/frp
sudo cp frpc.ini frps.ini /etc/frp/
sudo cp frpc frps /usr/bin/
sudo chmod a+x /usr/bin/frpc /usr/bin/frps
sudo systemctl enable frps
注意:一定要在/root目录下执行,否则后面的文件编辑位置会出错。
sudo vim /etc/frp/frps.ini
[common]
bind_port = 7897
bind_addr = 0.0.0.0
token = thisistoken #token值一定要与frpc文件的保持一致
sudo systemctl start frps
注意:frps与后面要配置的frpc文件的token、port值一定要一样。不然容器会一直保持重启状态。
sudo docker network create ctfd_frp-containers
sudo docker run -d -v ~/frp_0.29.0_linux_amd64/frpc.ini:/etc/frp/frpc.ini --network="ctfd_frp-containers" --restart=always "glzjin/frp"
1. sudo docker network create frpcadmin
2. docker ps //查看frpcadmin容器ID
3. sudo docker network connect frpcadmin <frpc容器ID>
docker network inspect frpcadmin
注意:如果初次执行没有发现地址,多执行几次上面的命令,容器处于up状态时才可以加入。
vim ~/frp_0.29.0_linux_amd64/frpc.ini
[common]
server_addr = 172.17.0.1 //docker0的ip
server_port = 7897
token = thisistoken //与前面frps.ini的token一致
admin_addr = 172.19.0.2 //frpc容器的网络IP,上面记录的IP
admin_port = 7400
log_file = ./frps.log
docker restart
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"
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
更新:有小伙伴私信我说docker build失败,这里可以修改dockerfile文件,我用的是3.7版本,当时我的系统python也是3.7,你们可以根据自己的python3版本指定相关版本。例如3.6版本的可以修改为:FROM python:3.6-alpine,再试一下搭建情况。
FROM python:3.7-alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories &&\
apk update && \
apk add python3 python3-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"]
修改requirements.txt
在最后一行添加banal==0.4.2
构建并启动镜像
docker-compose build
docker-compose up //挂后台可加-d选项
讲ctfd容器连接frpcadmin网络
docker network connect frpcadmin
访问IP:8000即可
第一次进入会要求设置管理员账号密码,按步骤设置即可。
Frp API IP填frpc容器网络的IP
domain没有就填None
Frp Direct IP Address填自己的服务器IP,因为我是搭建线下服务器所以用的内网IP
template里面写上frpc.ini的内容,其他照着填就行
Challenge Type题目类型选择dynamic_docker
Name题目名字
Category题目分类
Initial Value初始分值
Decay Value递减分值
Minimum Value最小分值
Docker Image支持动态flag的镜像
Frp Http Portfrps http开放的端口
Frp Redirect Type没有域名选择Direct
Frp Redirect Port转发到靶机容器的端口
Score Type是否启用动态分数
apt install openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev make
mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.19.2.tar.gz
tar -zxvf nginx-1.19.2.tar.gz
cd nginx-1.19.2.tar.gz
./configure
make
make install
cd /usr/local/nginx/sbin/
./nginx
设置开机自启
vi /etc/rc.local
/usr/local/nginx/sbin/nginx (根据whereis nginx实际的位置为准)
设置执行权限:
chmod 755 rc.local
配置之前需要先运行一下nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s quit
然后再修改配置文件 vim /usr/local/nginx/conf/nginx.conf(whereis nginx 实际情况)
server下的location替换为
location /{
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
docker search lamp
docker pull <容器名>
1.运行一个集成lamp环境的容器
docker run -d --name <自定义名字> -p <宿主机未使用端口>:80 <镜像名字>
2.讲制作好的题目php或html文件放入容器/var/www/html目录下
docker cp <宿主机本地文件> <docker ID/Name>:/var/www/html/
1.若未有dockerhub账号,先去注册一个:hub.docker.com
2.登录到dockerhub
docker login
3.打包镜像
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
-a :提交的镜像作者;
-c :使用Dockerfile指令来创建镜像;
-m :提交时的说明文字;
-p :在commit时,将容器暂停。
4.将打包好的镜像上传到dockerhub
docker push <cintainerID>
后续对题目的管理去dockerhub即可。搭建题目时docker image填写CONTAINER [REPOSITORY[:TAG]]即可。docker