File tree Expand file tree Collapse file tree 7 files changed +76
-25
lines changed
Expand file tree Collapse file tree 7 files changed +76
-25
lines changed Original file line number Diff line number Diff line change 1+ FROM python:3.10.12-slim-bullseye
2+
3+ # 制作者信息
4+ LABEL auther_template="CTF-Archives"
5+
6+ # apt更换镜像源,并更新软件包列表信息
7+ RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && \
8+ sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
9+ RUN apt-get update
10+
11+ # 通过apt,安装xinetd用于服务转发
12+ RUN apt-get install -y xinetd
13+
14+ # 通过tuna源,安装必要的python依赖库
15+ # 镜像中并没有更换源,只是在pip语句中每次制定了镜像源
16+ RUN python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple \
17+ pycryptodome
18+
19+ # 部署xinetd服务
20+ COPY ./config/ctf.xinetd /etc/xinetd.d/ctf
21+ RUN echo "Blocked by ctf_xinetd" > /etc/banner_fail
22+
23+ # 复制容器启动脚本
24+ COPY ./service/docker-entrypoint.sh /
25+ RUN chmod +x /docker-entrypoint.sh
26+
27+ # 新建用户,并进行账户改变
28+ RUN useradd -m ctf
29+ WORKDIR /home/ctf
30+
31+ # 部署程序
32+ COPY ./src/server.py /home/ctf/server.py
33+
34+ # [可选]指定对外暴露端口,对于GZCTF等平台,强制EXPOSE可能会造成非预期端口泄露,请酌情启用
35+ # EXPOSE 9999
36+
37+ CMD ["/docker-entrypoint.sh" ]
Original file line number Diff line number Diff line change 1+ # misc-pyjail-python_3.10
2+
3+ ** 感谢 @gtg2619 师傅对此模板的贡献 **
4+
5+ ## 环境说明
6+
7+ 提供 ` Python 3.10 ` 的基础环境,并已经添加 ` pycryptodome ` 库,并基于 ` xinetd ` 实现服务转发,默认暴露端口位于9999
8+
9+ 实现:当选手连接到对应端口(默认为9999端口,默认选手使用 ` netcat ` )的时候,运行 ` server.py ` ,并将会话转发至选手的连接
10+
11+ 镜像做到:
12+ - 选手通过端口连接到容器/靶机
13+ - xinted服务检测到连接,启动一个 ` python3 ` 会话
14+ - ` python3 ` 通过参数 ` -u /home/ctf/server.py ` 限制了程序运行时的账户权限为` ctf ` ,然后在限制环境中启动程序
15+ - ` xinted ` 将程序会话转发给选手的连接
16+
17+ ## 如何使用
18+
19+ 将程序文件放入 ` ./src ` 目录即可,文件名请修改为 ` server.py ` 作为文件名,便于镜像定位程序位置
20+
21+ 如果需要更改为自己的文件名,需要在 ` ./config/ctf.xinetd ` 、` ./Dockerfile ` 和 ` ./service/docker-entrypoint.sh ` 中进行修改
22+
23+ 程序放置进 ` ./src ` 目录之后,执行
24+ ``` shell
25+ docker build .
26+ ```
27+ 即可开始编译镜像
28+
29+ 也可以在安放好程序文件之后,直接使用 ` ./docker/docker-compose.yml ` 内的 ` docker-compose ` 文件实现一键启动测试容器
30+
31+ ``` shell
32+ cd ./docker
33+ docker-compose up -d
34+ ```
Original file line number Diff line number Diff line change @@ -4,13 +4,12 @@ service ctf
44 socket_type = stream
55 protocol = tcp
66 wait = no
7- user = root
7+ user = ctf
88 type = UNLISTED
99 port = 9999
1010 bind = 0.0.0.0
11- server = /usr/sbin/chroot
12- # replace helloworld to your program(要跑的服务)
13- server_args = --userspec=1000:1000 / python3 /home/server.py
11+ server = /usr/local/bin/python3
12+ server_args = -u /home/ctf/server.py
1413 banner_fail = /etc/banner_fail
1514 # safety options
1615 per_source = 10 # the maximum instances of this service per source IP address
File renamed without changes.
Original file line number Diff line number Diff line change 2323# 将FLAG写入文件 请根据需要修改
2424echo $INSERT_FLAG | tee /flag
2525
26+ chmod 744 /flag
27+
2628
2729# 启动 xinetd 服务
2830/etc/init.d/xinetd start;
File renamed without changes.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments