CTF-pwn-Ubuntu2404-环境搭建

0 温馨提醒

温馨提醒,需要科学上网,且提前在主机上配置好虚拟机的VPN(最简单的是TUN模式)
提前在windows电脑上安装tabby用于ssh连接

1 ubuntu

下载好ubuntu镜像后直接在vmware中傻瓜式安装,建议设置一个CPU八个核心,不要设置多个CPU

attachments/Pasted image 20260312161728.png
attachments/Pasted image 20260312161728.png

0x1 vmtools

sudo apt install open-vm-tools-desktop
安装vmtools

attachments/Pasted image 20260310120329.png
attachments/Pasted image 20260310120329.png

第一次安装完vmtools需要重启,不然可能复制粘贴等一些功能无法使用

0x2 设置不息屏

在电源设置里设置从不息屏

attachments/Pasted image 20260310112746.png
attachments/Pasted image 20260310112746.png

0x3 一部分环境依赖

安装开发环境(后面软件的依赖)

1
2
3
4
5
6
sudo apt update
sudo apt install build-essential -y
sudo apt install git curl wget vim fish
sudo apt install -y software-properties-common
sudo apt install python3-pip
sudo apt install autoconf automake libtool

安装了fish后可以切换为fish
用vim打开~/.bashrc,翻到最下面,按I进入编辑模式,在~/.bashrc的末尾加上fish

attachments/Pasted image 20260310195652.png
attachments/Pasted image 20260310195652.png

ESC退出编辑模式,按下:后输入wq,保存更改并退出,w表示保存,q表示退出
然后重启终端即可

0x4 neovim

安装neovim

1
2
3
4
5
6
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.appimage
# 如果报错,可前往https://github.com/neovim/neovim/releases/latest页面获取下载链接或直接下载对应安装包(一般是x86_64的)
# 如果上面的还报错,就前往https://github.com/neovim/neovim/releases页面挑选一个较新的版本获取下载链接或直接下载对应安装包
# 如果还是报错,那可能是网络的问题了
chmod +x nvim-linux-x86_64.appimage
sudo mv ./nvim-linux-x86_64.appimage /usr/local/bin/nvim

attachments/Pasted image 20260310210607.png
attachments/Pasted image 20260310210607.png

0x5 Nerd Fonts

安装nerd fonts
在ubuntu内部打开https://www.nerdfonts.com/font-downloads
在此处寻找喜欢的字体并下载

attachments/Pasted image 20260310201235.png
attachments/Pasted image 20260310201235.png

解压后安装字体,mono表示等宽,安装mono版本即可,bold是加粗,italic是斜体,regular是通用,都安装。
在字体所在文件夹打开终端,输入
cp ./CodeNewRomanNerdFontMono-* ~/.local/share/fonts/
CodeNewRomanNerdFontMono-*是字体名,*是通配符
然后刷新缓存
fc-cache -fv
attachments/Pasted image 20260310203002.png
attachments/Pasted image 20260310203002.png

看见我们刚刚放入字体的文件夹有新增内容,接下来更换字体进行验证
attachments/Pasted image 20260310203112.png
attachments/Pasted image 20260310203112.png

右键选择配置文件首选项
attachments/Pasted image 20260310203225.png
attachments/Pasted image 20260310203225.png

勾选自定义字体后发现刚刚下载的字体存在,说明安装成功,切换到该字体。

0x6 NvChad

安装NvChad(Lazyvim也可以,但是这里试试NvChad)
https://nvchad.com/docs/quickstart/install
直接git clone
git clone https://github.com/NvChad/starter ~/.config/nvim && nvim

attachments/Pasted image 20260310210853.png
attachments/Pasted image 20260310210853.png

出现广告按q关掉
然后删掉.git文件夹
rm -rf ~/.config/nvim/.git/
输入nvim,后按空格后按t和h出现选择主题界面
attachments/Pasted image 20260310212007.png
attachments/Pasted image 20260310212007.png

选择喜欢的主题

NvChad 默认禁用了 vimtutor,为了开启它,需要进入 Neovim 配置文件夹~/.config/nvim,然后用文本编辑器打开 lua/configs/lazy.lua 文件,找到 "tutor", 这一行,并在这一行前面加上 -- 把它注释掉。

attachments/Pasted image 20260310212631.png
attachments/Pasted image 20260310212631.png

然后打开nvim,输入:Tutor就可以学习nvim的操作了
attachments/Pasted image 20260310212728.png
attachments/Pasted image 20260310212728.png

按下 空格+e 组合键打开文件浏览器侧边栏(这实际上基于 Nvim-tree 插件),通过键盘上的 j k Enter 几个按键来浏览和打开文件,通过Ctrl+h/j/k/l在上下左右的窗口之间切换焦点
alt h和alt v打开内置终端,ctrl x光标焦点离开终端
常用功能
attachments/Pasted image 20260310213706.png
attachments/Pasted image 20260310213706.png

更多的可以看这篇教学
https://zhuanlan.zhihu.com/p/712125953

0x7 ssh连接

配置ssh
安装openssh-server
sudo apt install openssh-server
启动ssh服务
sudo systemctl enable --now ssh

attachments/Pasted image 20260310214652.png
attachments/Pasted image 20260310214652.png

输入ip addr查看自己的ip
attachments/Pasted image 20260310214731.png
attachments/Pasted image 20260310214731.png

然后就可以用ssh连接了
attachments/Pasted image 20260310214825.png
attachments/Pasted image 20260310214825.png

0x8 docker

1
2
3
4
5
6
7
8
sudo apt update

sudo apt install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release

将docker的源添加到apt列表中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

## 官方源

## $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

## $ echo \

## "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \

## $ stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

然后更新一下源,进行安装

1
2
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

建立docker用户组,方便使用docker时不用加sudo

1
2
sudo groupadd docker
sudo usermod -aG docker $USER

然后重启,打开终端,输入以下指令

1
2
3
groups

docker run --rm hello-world

未报错且出现Hello from Docker则为安装成功

attachments/Pasted image 20260312020937.png
attachments/Pasted image 20260312020937.png

2 工具安装

0x1 ida pro

安装ida pro
通过ssh连接的sftp功能将ida pro安装包传入ubuntu
在终端给予执行权限后安装
(建议创建好几个文件夹进行分类,不然后期东西多了会很乱)

attachments/Pasted image 20260311131029.png
attachments/Pasted image 20260311131029.png

安装完后在软件中心可以看见ida了
attachments/Pasted image 20260311131212.png
attachments/Pasted image 20260311131212.png

右键将其固定到快捷栏
attachments/Pasted image 20260311131227.png
attachments/Pasted image 20260311131227.png

接下来安装nodejs

1
2
3
4
5
6
7
8
9
10
# 下载并安装 nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# 代替重启 shell (须在sh, dash, bash, ksh, zsh下运行)
\. "$HOME/.nvm/nvm.sh"
# 下载并安装 Node.js:
nvm install 24
# 验证 Node.js 版本:
node -v # Should print "v24.14.0".
# 验证 npm 版本:
npm -v # Should print "11.9.0".

在bash环境下(在fish下按ctrl + d退出fish)执行nvm install 24

attachments/Pasted image 20260313014933.png
attachments/Pasted image 20260313014933.png

安装好后将keygen.js移到刚刚安装ida时所选择的目录

attachments/Pasted image 20260311131349.png
attachments/Pasted image 20260311131349.png

切换到该目录,确保keygen存在
attachments/Pasted image 20260311131422.png
attachments/Pasted image 20260311131422.png

输入node 93keygen.js执行破解程序
attachments/Pasted image 20260311131459.png
attachments/Pasted image 20260311131459.png

启动ida pro检查是否成功,点开new后没有提醒输入密钥就是成功了
attachments/Pasted image 20260311131604.png
attachments/Pasted image 20260311131604.png

0x2 pwntools

pwntools用pip安装,版本更新

1
pip install pwntools --break-system-packages

如果不加后面这串则会报错,原因是默认不让破坏系统的python环境,但是我们这是虚拟机所以无所谓。

attachments/Pasted image 20260311131933.png
attachments/Pasted image 20260311131933.png

关于pwntools的学习可以前往
https://github.com/Gallopsled/pwntools-tutorial/

0x3 pwndbg

安装pwndbg,注意指令执行时所在的文件夹

1
2
3
git clone https://github.com/pwndbg/pwndbg
cd pwndbg
./setup.sh

时间可能有点久,主要是网络问题,等待一会

attachments/Pasted image 20260311132831.png
attachments/Pasted image 20260311132831.png

安装后按照提示,在~/.gdbinit中加入source /home/a4/0x1.Tools/pwndbg/gdbinit.py,具体路径根据你们的安装路径来更改
attachments/Pasted image 20260311133256.png
attachments/Pasted image 20260311133256.png

attachments/Pasted image 20260311133507.png
attachments/Pasted image 20260311133507.png

(如果提示权限不够可能是前面setup.sh用root权限执行了,输入sudo chown -R $USER:$USER /home/a4/0x1.Tools/pwndbg更改权限为用户权限即可,路径根据实际路径更改
输入gdb进入后显示了pwndbg就是成功了
attachments/Pasted image 20260311133645.png
attachments/Pasted image 20260311133645.png

0x4 patchelf

接下来是patchelf,依旧注意指令执行时所在的文件夹
git clone https://github.com/NixOS/patchelf.git

attachments/Pasted image 20260311134006.png
attachments/Pasted image 20260311134006.png

1
2
3
4
5
6
cd ./patchelf
./bootstrap.sh
./configure
make
make check
sudo make install

attachments/Pasted image 20260311134345.png
attachments/Pasted image 20260311134345.png

输入patchelf显示如下则是安装成功

0x5 glibc-all-in-one

一个很老的项目,当你需要patchelf时会用上

1
2
3
4
5
6
git clone https://github.com/matrix1001/glibc-all-in-one.git
cd ./glibc-all-in-one
./update_list
cat list
# 选择要下载的版本直接复制
sudo ./download 2.31-0ubuntu9_amd64

attachments/Pasted image 20260312003247.png
attachments/Pasted image 20260312003247.png

下载好的glibc会在该目录下的libs文件夹中
attachments/Pasted image 20260312003332.png
attachments/Pasted image 20260312003332.png

0x6 ROPgadget

保护眼睛,让脚本帮你找gadget

1
pip install ROPgadget --break-system-packages

attachments/Pasted image 20260312004150.png
attachments/Pasted image 20260312004150.png

如果你也出现和我一样的问题,是因为pip将可执行文件安装到了用户目录(~/.local/bin),但该目录不在环境变量$PATH中。
我们将~/.local/bin加入到$PATH中即可

1
2
3
4
5
6
7
8
# 由于我们使用的是fish,所以
nvim ~/.config/fish/config.fish
# 再大括号内加上
fish_add_path $HOME/.local/bin
# 保存退出重新打开终端即可

# 如果你没有切换shell的话
# echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc

attachments/Pasted image 20260312005155.png
attachments/Pasted image 20260312005155.png

attachments/Pasted image 20260312005215.png
attachments/Pasted image 20260312005215.png

0x7 one_gadget

当只能执行一个gadget时,也许会有奇效

1
2
sudo apt install ruby-rubygems
sudo gem install one_gadget

attachments/Pasted image 20260312005722.png
attachments/Pasted image 20260312005722.png

0x8 libcsearcher

当题目没给libc,而你又懒得去找对应libc时可以用它

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# clone this repo
git clone --recursive https://github.com/rycbar77/LibcSearcher.git
cd LibcSearcher
sudo python3 setup.py develop

# download libc file
cd libc-database

apt-get update
sudo apt-get install -y \
binutils file \
wget \
rpm2cpio cpio \
zstd jq

./get ubuntu

需要等待一段时间(挺长的,建议用wifi,但是校园网很慢的话。。。那就会更慢了)

attachments/Pasted image 20260312010646.png
attachments/Pasted image 20260312010646.png

安装完毕
attachments/Pasted image 20260312014950.png
attachments/Pasted image 20260312014950.png

0x9 seccomp-tools

检查程序是否有沙盒保护,以及保护的是什么(听说有的时候会不准?)

1
2
3
sudo apt install gcc ruby-dev make

sudo gem install seccomp-tools

attachments/Pasted image 20260312015223.png
attachments/Pasted image 20260312015223.png


自此x86架构下的用户态pwn环境配置完毕

本作品由 automata 于 2026-03-21 00:00:00 发布
作品地址:CTF-pwn-Ubuntu2404-环境搭建
除特别声明外,本站作品均采用 CC BY-NC-SA 4.0 许可协议,转载请注明来自 凹凸麦塔
Logo
上一篇0x2.DIR-815 漏洞复现 新手入门下一篇RUST漏洞点