正常apt
安装的binwalk一般都是不完整的,需要我们先卸载后在github
中下载安装,之后才可以正常提取路由器的固件,否则将出现下图错误
git clone https://github.com/devttys0/binwalk.git
sudo apt-get install python-lzma
sudo apt-get install libqt4-opengl python-opengl python-qt4 python-qt4-gl python-numpy python-scipy python-pip
sudo python setup.py install
sudo apt-get install mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract cramfsprogs cramfsswap squashfs-tools
git clone https://github.com/devttys0/sasquatch
sudo ./build.sh
其中可能会出现sasquatch脚本的lzma
编译错误
In file included from xz_wrapper.c:31:0:
xz_wrapper.h:50:2: error: unknown type name ‘lzma_vli’
lzma_vli id;
^
xz_wrapper.h:56:2: error: unknown type name ‘lzma_filter’
lzma_filter filter[3];
^
xz_wrapper.h:64:2: error: unknown type name ‘lzma_options_lzma’
lzma_options_lzma opt;
^
xz_wrapper.c:35:11: error: ‘LZMA_FILTER_X86’ undeclared here (not in a functio
n)
{ "x86", LZMA_FILTER_X86, 0 },
^
xz_wrapper.c:36:15: error: ‘LZMA_FILTER_POWERPC’ undeclared here (not in a fun
ction)
{ "powerpc", LZMA_FILTER_POWERPC, 0 },
^
xz_wrapper.c:37:12: error: ‘LZMA_FILTER_IA64’ undeclared here (not in a functi
on)
{ "ia64", LZMA_FILTER_IA64, 0 },
^
xz_wrapper.c:38:11: error: ‘LZMA_FILTER_ARM’ undeclared here (not in a functio
n)
{ "arm", LZMA_FILTER_ARM, 0 },
解决方法:
修改./sasquatch/squashfs4.3/squashfs-tools
中lzma.h
文件的命名
cd LZMA/lzmadaptive/C/7zip/Compress/LZMA/
mv LZMA.h LZMA2.h
cd LZMA/lzmalt/
mv LZMA.h LZMA3.h
之后将其文件中include
后的文件名修改
➜ LZMA vim lzmadaptive/C/7zip/Compress/LZMA/LZMADecoder.h
➜ LZMA vim lzmadaptive/C/7zip/Compress/LZMA/LZMAEncoder.h
➜ LZMA vim lzmalt/LZMADecoder.h
至此完成,进行编译安装
sudo make clean
sudo make
sudo make install
下载各架构版本的gdbserver https://github.com/e3pem/embedded-toolkit
之后拷贝到qemu虚拟机中
./gdbserver-mips32 0.0.0.0:1234 level1
之后在本机的gdb中进行连接调试
gdb-multiarch level1
pwndbg> set architecture mips
pwndbg> set endian big
pwndbg> target remote ip:1234
正常情况下单个mips的程序运行要有足够的lib库依赖,把qemu-mips-static
放到完整的路由器文件系统squashfs-root
的根目录中运行程序就可以了,即:
cp $(which qemu-mipsel-static) ./
sudo chroot ./ ./qemu-mipsel-static -g 1234 ./bin/level1
之后正常使用GDB或者IDA连接即可
gdb-multiarch level1
> set architecture mips
> target remote :1234
可能出现的问题 :
./stack_bof_01: Invalid ELF image for this architecture
字节序问题,切换qemu-static的大小端版本,如小端qemu-mipsel-static
\大端qemu-mips-static
/lib/ld-uClibc.so.0: No such file or directory
由于程序可能需要某个目录下的依赖所导致
需要将qemu-mipsel-static
文件放到squashfs-root
根目录下,之后chroot ./
。(这个有时候要加./
有时候直接.
就可以)
由于mips的特殊性:
导致shellcode in stack几乎成了mips栈溢出的通用利用方式
git clone https://github.com/fuzzywalls/ida/tree/master/plugins
python ./install.py /path/to/your/ida/install/directory
mipsrop.stackfinder() | 寻找栈数据可控的 rop,建立和 a0、a1 寄存器的关系 |
---|---|
mipsrop.summary() | 列出所有的可用 rop |
mipsrop.system() | 寻找命令执行的的rop |
mipsrop.find(xxx) | 查找 find 函数参数的 rop,类似正则匹配 |
反编译MIPS伪代码,感觉不如下面的JEB好用
ghidra_9.1.2_PUBLIC_20200212 链接:https://pan.baidu.com/s/1m1UjI1qDSif_nxiCoHCXOw 提取码:m6j0
JEB 永远的神
JEB_Decompiler_3.19.1_Professional 链接:https://pan.baidu.com/s/1eNZiRcCfjofH-TxieFLNzw 提取码:r7e7 这个注册的时候需要注意: 先运行jeb_pro,之后复制密钥输入到jebKeygen工具中生成密钥后再返回jeb输入