pwn环境配置
配置环境
笔者选择在 Windows 11 中的 WSL2 中的 kali-linux 中安装 docker
安装wsl2
(由于wsl2是我过去安装的,读者可以自行搜索安装过程,或者待笔者补充)
将 kali 从 C盘 迁移到其他盘: 1
2
3
4
5
6
7
8
9
10
11# 导出 WSL 分发版(确保路径存在)
wsl --export kali-linux E:\WSL\kali-backup.tar
# 注销当前分发版
wsl --unregister kali-linux
# 创建新的安装目录
New-Item -Path "E:\WSL\kali" -ItemType Directory
# 重新导入到新位置
wsl --import kali-linux E:\WSL\kali E:\WSL\kali-backup.tar
安装docker
kali 基于 Debian 12 开发,因此我们按照 Debian 安装 docker
的方法安装即可,官网
根据 Note 将
$(. /etc/os-release && echo "$VERSION_CODENAME")
改为 bookworm ,如下: 1
2
3
4
5
6
7
8
9
10
11
12
13
14# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
bookworm stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Failed to fetch
https://download.docker.com/linux/debian/dists/bookworm/InRelease
Could not handshake: Error in the pull function.
可以尝试在 /etc/resolv.conf
中添加以下 DNS 服务器:
1
2nameserver 8.8.8.8
nameserver 8.8.4.41
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
测试运行: 1
sudo docker run hello-world
可能出现的错误:
1. docker: Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon running?
解决办法:启动 docker : sudo service docker start
2. Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get
"https://registry-1.docker.io/v2/": context deadline exceeded
(Client.Timeout exceeded while awaiting headers).
解决办法:添加镜像:在 /etc/docker/daemon.json
文件中添加内容如下: 1
2
3{
"registry-mirrors": ["https://docker.1panel.live"]
}
安装pwn相关工具
参照 ctf wiki,使用 Dokerfile 搭建环境
可能出现的问题:
1. 无法访问github, 导致最后一步失败
解决办法: 配置代理的方式笔者还没有走通,选择了镜像源的方式:
1
2
3
4# 修改原 Dockerfile 中的
# RUN git clone https://github.com/pwndbg/pwndbg && \
# 为
RUN git clone https://gitclone.com/github.com/pwndbg/pwndbg && \setup.sh
脚本时出现超时
(TimeoutError) 的错误
解决办法:尝试了一些增加超时时长的方式,无果。将 Dockerfile 中的最后
cd pwndbg && chmod +x setup.sh && ./setup.sh
删掉,可以完成镜像的创建,然后根据这个镜像再创建容器,再在容器中手动执行
setup.sh
, 没有出现超时问题(当然也有可能是偶然) 3.
setup.sh
安装 pt
时无法访问到 github
导致错误
解决办法:手动进入之前 setup.sh
安好的 .venv
虚拟环境,在 /pwndbg/pyporject.toml
中可以找到如下内容,大约在第174行: 1
pt = { git = "https://github.com/martinradev/gdb-pt-dump", rev = "50227bda0b6332e94027f811a15879588de6d5cb" }
1
2
3
4git clone https://gitclone.com/github.com/martinradev/gdb-pt-dump.git
cd gdb-pt-dump
git checkout 50227bda0b6332e94027f811a15879588de6d5cb
pip install
或者开启Tun模式,上述的网络问题应该就都不存在了
运行容器: 1
2
3
4
5
6
7docker run \
-d \
-p 25000:22 \
--name=pwn24 \
--privileged \
-v /mnt/e/ctf:/home/ubuntu/ctf \
pwnenv_ubuntu24:latest--privileged
是为了能够修改 /proc
中的一些文件
因为 pwndbg 是以 root 身份安装的,若想使普通的 ubuntu
用户也可以使用这个插件,只需要将 /root/.gdbinit
复制到
ubuntu 的家目录下即可