pwntools
是一个CTF框架和漏洞利用开发库。它以Python编写,专为快速原型设计和开发而设计,旨在使漏洞利用编写尽可能简单。
在CTF比赛中或者一些漏洞的利用过程中,使用pwntools这个优秀而便捷的库可以使原本复杂的脚本变得简单易读,本文会记录我个人在使用PwnTools过程中的一些技巧,长期更新
与程序建立连接
远程连接
1
| io = remote( 'ip' , port )
|
本地连接
1
| p = process( '/bin/sh' )
|
转换为监听端口
1 2
| l = listen() conn = l.wait_for_connection()
|
打包函数/解包函数
将整数转化为字节序列/将字节序列转换为整数
1 2 3 4
| p32(0xdeadbeef) u32(0xdeadbeef) p64(0xdeadbeef) u64(0xdeadbeef)
|
设置目标程序的架构
一次性设定
1
| context(arch='arm', os='linux', endian='big', word_size=32)
|
分开设定
1 2 3 4
| context.arch = 'i386' context.os = 'linux' context.endian = 'little' context.word_size = 32
|
日志信息的详细程度
1
| context.log_level = 'debug'
|
汇编与反汇编
汇编
1 2
| >>> asm('mov eax, 0').encode('hex') 'b800000000'
|
反汇编
1 2 3 4 5
| >>> print disasm('6a0258cd80ebf9'.decode('hex')) 0: 6a 02 push 0x2 2: 58 pop eax 3: cd 80 int 0x80 5: eb f9 jmp 0x0
|
偏移量计算
可以使用gdb自带的偏移计算方法,也可以使用此方法进行自动化的分析
1 2 3 4 5
| >>> print cyclic(20) aaaabaaacaaadaaaeaaa >>> >>> print cyclic_find('faab') 120
|
查看ELF信息
1 2 3 4 5 6 7 8 9
| >>> e = ELF('/bin/cat') >>> print hex(e.address) 0x400000 >>> print hex(e.symbols['write']) 0x401680 >>> print hex(e.got['write']) 0x60b070 >>> print hex(e.plt['write']) 0x401680
|
待更新。。。