怎么出题部署环境?
docker部署
首先肯定是安装docker
1 sudo apt install docker.io
写题目
1 2 3 4 5 chall ├── flag.txt ├── vuln ├── vuln.c └── Makefile
docker 部署,在同级目录添加 Dockerfile,同时配合 xinetd
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 33 34 35 36 37 38 FROM ubuntu:20.04 ENV DEBIAN_FRONTEND noninteractiveRUN apt-get -y update --fix-missing && apt-get -y dist-upgrade RUN apt-get -y install lib32z1 xinetd RUN groupadd -r pwn && useradd -r -g pwn pwn RUN echo '#!/bin/bash\n \ service xinetd restart && /bin/sleep infinity' > /etc/init.shRUN echo 'service pwn\n \ {\n \ type = UNLISTED\n \ disable = no\n \ socket_type = stream\n \ protocol = tcp\n \ wait = no\n \ user = pwn\n \ bind = 0.0.0.0\n \ port = 9999\n \ server = /home/pwn/vuln\n \ }' > /etc/xinetd.d/pwn RUN chmod 500 /etc/init.sh RUN chmod 444 /etc/xinetd.d/pwn RUN chmod 1733 /tmp /var/tmp /dev/shm ADD chall/flag.txt /flag.txt ####### change flag RUN chmod 444 /flag.txt RUN mv /flag.txt /flag-$(md5sum flag.txt | awk ' {print $1 }').txt WORKDIR /home/pwn ADD chall/vuln . ###### change chall file RUN chmod 550 vuln RUN chown -R root:pwn /home/pwn RUN service xinetd restart
docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 version: '3' services: vuln: build: . ulimits: nproc: 65535 core: 0 ports: - "1234:9999" entrypoint: /etc/init.sh restart: unless-stopped
启动
坑点 :docker部署题目时,在程序里必须将缓冲器置为0,否则不会显示?
ctf_xinetd 下载这个链接 ctf_xinetd ,部署比较简单。
修改 bin目录 里的 二进制文件和 flag 文件
dockerfile 修改一行
1 2 3 4 5 RUN cp -R /lib* /home/ctf && \ cp -R /usr/lib* /home/ctf RUN cp -R /usr/lib* /home/ctf
ctf.xinetd 修改
1 2 3 4 server_args = --userspec=1000:1000 /home/ctf ./helloworld # 修改 server_args = --userspec=1000:1000 /home/ctf 自己的漏洞程序
最后执行README 里的 两条命令就行,比如
1 2 3 4 docker build -t "vuln" . docker run -d -p "0.0.0.0:pub_port:9999" -h "vuln" --name="vuln" vuln
查看了一眼其内容,使用 chroot沙盒,将文件系统的根目录转化为原先的 /home/ctf
目录,所以要在dockerfile中将lib全部拷贝一份
1 server = /usr/sbin/chroot
pwn_deploy_chroot
kernel
1 2 3 4 5 6 7 8 9 chall ├── ctf.xinetd ├── Dockerfile ├── bin │ ├── run.sh │ ├── bzImage │ └── rootfs.cpio ├── README.md └── start.sh
docker 安装环境
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 FROM ubuntu:20.04 DEBIAN_FRONTEND=noninteractive RUN sed -i "s/http:\/\/archive.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list && \ apt-get update && apt-get -y dist-upgrade && \ apt-get install -y lib32z1 xinetd git libglib2.0 -dev libfdt-dev \ libpixman-1 -dev zlib1g-dev qemu qemu-system-x86 RUN useradd -m pwn WORKDIR / COPY ./ctf.xinetd /etc/xinetd.d/ctf COPY ./start.sh /start.sh RUN echo "Blocked by ctf_xinetd" > /etc/banner_fail RUN chmod +x /start.sh COPY ./chall/ / CMD ["/run.sh" ] EXPOSE 25000
重要的是修改 ctf.xinetd 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 service ctf { disable = no socket_type = stream protocol = tcp wait = no user = pwn type = UNLISTED port = 25000 bind = 0.0.0.0 server = /run.sh banner_fail = /etc/banner_fail per_source = 10 rlimit_cpu = 20 }