以制作一个ubuntu16的靶机为例
    先随便拉一个ubuntu16的镜像:

    1. docker pull ubuntu:16.04

    安装工具:

    1. // 创建一个容器
    2. docker run -it ubuntu:16.04 /bin/bash
    3. // 换源
    4. sed -i "s/http:\/\/archive.ubuntu.com/http:\/\/mirrors.aliyun.com/g" /etc/apt/sources.list
    5. //更新源
    6. apt-get update && apt-get -y dist-upgrade
    7. //下载libc32库与xinetd(网络守护进程服务程序)
    8. apt-get install -y lib32z1 xinetd build-essential python python-dev
    9. exit
    10. //返回

    打包成镜像方便下次使用:

    1. docker commit CONTAINER_HASH pwn_server:16.04

    在home下新建一个ctf文件夹
    里面存放五个文件
    图片.png
    我们创建靶机的时候会将这5个文件放入靶机的/home/ctf文件夹中
    其中:
    pxi为xinetd 脚本,用于配置 pwn题服务

    1. service pwn
    2. {
    3. disable = no
    4. socket_type = stream
    5. protocol = tcp
    6. wait = no
    7. user = root
    8. type = UNLISTED
    9. port = 8888
    10. bind = 0.0.0.0
    11. server = /usr/sbin/chroot
    12. server_args = --userspec=ctf:ctf / timeout 30 ./home/ctf/pwn
    13. banner_fail = /etc/banner_fail
    14. # safety options
    15. per_source = 10 # the maximum instances of this service per source IP address
    16. rlimit_cpu = 60 # the maximum number of CPU seconds that the service may use
    17. rlimit_as = 1024M # the Address Space resource limit for the service
    18. #access_times = 2:00-9:00 12:00-24:00
    19. #Instances = 20 #process limit
    20. #per_source = 5 #link ip limit
    21. #log warning die
    22. log_on_success = PID HOST EXIT DURATION
    23. log_on_failure = HOST ATTEMPT
    24. log_type =FILE /var/log/myservice.log 8388608 15728640
    25. }

    start.sh为启动container时运行的脚本

    1. #!/bin/sh
    2. useradd -m ctf
    3. sleep 2
    4. chmod 555 -R /home/ctf
    5. cp /home/ctf/pxi /etc/xinetd.d/pwn
    6. /etc/init.d/xinetd restart
    7. trap : TERM INT; sleep infinity & wait
    8. # /bin/sh

    find_flag为pwn题
    准备好后就可以用刚才的镜像生成靶机容器了:

    1. docker run -p $PORT:8888 -v `pwd`:/home/ctf -it $IMAGE_NAME /bin/sh

    $PORT为开放的端口,$IMAGE_NAME为镜像
    图片.png
    创建好之后测试一下