本文编写于 442 天前,最后修改于 441 天前,其中某些信息可能已经过时。
pwn工具,用python脚本调用capstone快速反汇编shellcode
学习exp时看到预置shellcode不再懵逼
0x00 介绍 Intro
Capstone 是一个反汇编框架,它的目标是成为最好的反汇编引擎 。
Core: Arm, Arm64, M68K, Mips, PPC, Sparc, SystemZ, X86, X86_64, XCore 等
Bindings: Python, Java, Ocaml, PowerShell
看exp的时候发现老是看到写好的shellcode不知道是什么,于是学习下怎么用capstone反汇编。
直接查 文档 硬看也是可以的,不过麻烦易错 ,python-capstone还是方便好用得多
0x01 安装 Install
Ubuntu安装
仓库安装
$sudo apt-get install python-capstone
Git安装
#安装Capstone
git clone http://github.com/aquynh/capstone #下载Capstone源码到本地
cd capstone
make #编译源文件
sudo make install #编译并安装
各平台的花式安装方法参照官方文档。
0x02 用法 Usage
通过python接口简单调用

Example:
#!/usr/bin/env python
from capstone import *
#添加shellcode
Shellcode = ""
shellcode += ""
#初始化类,设置反汇编模式
md = Cs(CS_ARCH_X86, CS_MODE_32)
#反汇编HEX并打印地址与操作数
for i in md.disasm(shellcode, 0x00):
print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str))
显示更多细节
from capstone import *
from capstone.arm import *
CODE = b"\xf1\x02\x03\x0e\x00\x00\xa0\xe3\x02\x30\xc1\xe7\x00\x00\x53\xe3"
md = Cs(CS_ARCH_ARM, CS_MODE_ARM)
md.detail = True
for i in md.disasm(CODE, 0x1000):
if i.id in (ARM_INS_BL, ARM_INS_CMP):
print("0x%x:\t%s\t%s" %(i.address, i.mnemonic, i.op_str))
if len(i.regs_read) > 0:
print("\tImplicit registers read: "),
for r in i.regs_read:
print("%s " %i.reg_name(r)),
print
if len(i.groups) > 0:
print("\tThis instruction belongs to groups:"),
for g in i.groups:
print("%u" %g),
print
官方仓库里的示例代码挺全的,capstone对于二进制分析工具的编写还是很方便的
暂无评论