docker

入门参考资料:https://www.runoob.com/docker

https://yeasy.gitbook.io/docker_practice/

一、安装

使用官方脚本安装docker

curl -fsSL https://get.docker.com | bash -s docker –mirror Aliyun

手动安装(不如脚本稳定少出错)

开启docker

systemctl enable docker

systemctl start docker

测试是否安装成功: docker run –rm hello-world

hello-world是测试容器, –rm表示退出容器后,自动删除容器

二、使用入门

1.镜像

  • docker images 查看本地镜像

  • docker pull xxxx 拉去镜像, 例如docker pull ubuntu:18.04

​ 不给镜像仓库地址的话, 会从 Docker Hub (docker.io)获取镜像, 而镜像名称是 ubuntu:18.04,因此将会获取官方镜像 library/ubuntu 仓库中标签为 18.04 的镜像。docker pull命令的输出结果最后一行给出了镜像的完整名称,例如: docker.io/library/ubuntu:18.04

  • docker rmi xxxx 删除镜像

  • docker build -t xxxx . 用dockerfile构建镜像

2.容器

  • docker ps 查看容器 -a查看所有(包括停止的)

  • docker run -it ubuntu:18.04 bash

​ -it: -i 交互式操作 -t 终端

​ bash 命令,希望有交互式shell,所以用这个,或者/bin/sh之类的

  • docker stop xxx 停止容器

CTF-pwn出题环境搭建

​ pwn出题主要用到了 https://github.com/Eadom/ctf_xinetd

环境搭建

https://blog.csdn.net/weixin_53757397/article/details/128489015

https://blog.csdn.net/mylyylmy/article/details/79917776

https://nocbtm.github.io/2019/09/25/pwn题的搭建/

https://blog.csdn.net/weixin_53757397/article/details/128489015 感觉有点啰嗦,不一定需要上传docker仓库

https://blog.csdn.net/weixin_46521144/article/details/120572274 排错

搭建步骤

git clone https://github.com/Eadom/ctf_xinetd.git

  1. 将编译好的libc、flag、题目文件拷贝到bin目录下

​ 如果需要特定的libc

​ 提前patchelf好,把libc文件页拷贝到ctf_xinetd的bin目录下

​ patchelf –set-interpreter ./2.31-0ubuntu9_amd64/ld-linux-x86-64.so.2 ./timu
​ patchelf –set-rpath ./2.31-0ubuntu9_amd64/ ./timu

​ 用绝对路径不知道为什么不行????

  1. 创建docker-compose.yml文件,这里的3389改成题目要映射的端口(物理机的),9999是docker里面的端口,image名字要和后面创建的docker images名字一样
1
2
3
4
5
6
7
8
9
10
11
12
version: '3'

services:
pwn:
build: ./
image: pwn1 #这里修改的是images名,将和 docker build -t "pwn1" . 该命令有关
ports:
- "3389:9999"
pids_limit: 1024
# cpus: 0.5
restart: unless-stopped
# privileged: true

Dockerfile

1
2
3
4
FROM ubuntu:22.04 根据情况修改版本

RUN cp -R /lib* /home/ctf &&\ 版本高于18.04要删除这一句??为啥呢??
cp -R /usr/lib* /home/ctf

ctf.xinetd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
service ctf
{
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
type = UNLISTED
port = 9999
bind = 0.0.0.0
server = /usr/sbin/chroot
# replace helloworld to your program
server_args = --userspec=1000:1000 /home/ctf ./timu 这里timu是题目bin文件名
banner_fail = /etc/banner_fail
# safety options
per_source = 10 # the maximum instances of this service per source IP address
rlimit_cpu = 20 # the maximum number of CPU seconds that the service may use
#rlimit_as = 1024M # the Address Space resource limit for the service
#access_times = 2:00-9:00 12:00-24:00
}
  1. 制作镜像

​ 建立容器,pwn1名字就是镜像的名字

1
docker build -t "pwn1" .

4.创建运行容器

​ docker run -d -p 0.0.0.0:3389:9999 pwn1 运行容器,这里就部署好了,可以进行打了,3389是暴露出来的端口

​ docker exec -it 16a224caf905 /bin/bash 和容器进行交互,(这个是退出后再次进入,和run时候-it不一样)

文件拷贝 https://blog.csdn.net/sunhuaqiang1/article/details/88354410

docker cp /root/chuti/uaf/timu pwncp:/home/ctf/timu

https://blog.csdn.net/yue7603835/article/details/122456650