记录一下安装 pwntools 的过程和基本使用
如果出现下面的 warning
WARNING: The scripts asm, checksec, common, constgrep, cyclic, debug, disablenx, disasm, elfdiff, elfpatch, errno, hex, main, phd, pwn, pwnstrip, scramble, shellcraft, template, unhex, update and version are installed in '/home/yahu/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
1 2 3 4 export PATH=~/.local/bin:$PATH source ~/.bashrc
这样就可以直接使用 pwntools 自带的工具,如 checksec、cyclic 等
常用工具 checksec 用于查看文件的保护机制、架构信息等
1 2 3 4 5 6 7 $ checksec test Arch: i386-32-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x8048000)
cyclic 用于随机生成一串有序字符串
1 2 $ cyclic 50 aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaama
常用 python 模块 环境设置 1 2 context(os='linux' , arch='i386/amd64' , log_level='debug' )
引入程序 1 2 3 4 5 6 7 8 from pwn import * r = remote('8.8.8.8' , 8888 ) p = process('./test' ) r.interactive() p.interactive()
ELF文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def ELF (path : str )elf = ELF('./test' ) = p.elf addr_func = elf.sym['func_name' ] plt_func = elf.plt['func_name' ] got_func = elf.got['func_name' ] >>> elf.sym['main' ]134514548
发送数据 1 2 3 4 def send (data : bytes )def sendafter (delim : bytes , data : bytes )p.sendline(bytes ) p.sendlineafter(bytes , bytes )
接受数据 1 2 3 4 5 p.recv() p.recv(int ) p.recvline() p.recvuntil(bytes ) p.recvafter(bytes )
数据处理 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 def p8 (number : bytes ) -> int p16(bytes ) p32(bytes ) p64(bytes ) >>> p32(114514 )b'R\xbf\x01\x00' def u8 (number : int ) -> bytes u16(int ) u32(int ) u64(int ) >>> u32(b'R\xbf\x01\x00' )114514
其他常用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 def fmtstr_payload (offset : int , writes : map ) -> bytes >>> fmtstr_payload(1 , {2 : 3 , 6 : 7 })b'%3c%6$lln%4c%7$hhnaa\x02\x00\x00\x00\x06\x00\x00\x00' shellcraft.sh() shellcraft.i386.sh() shellcraft.amd64.sh() shellcraft.arm.sh() asm() >>> asm(shellcraft.sh())b'jhh///sh/bin\x89\xe3h\x01\x01\x01\x01\x814$ri\x01\x011\xc9Qj\x04Y\x01\xe1Q\x89\xe11\xd2j\x0bX\xcd\x80'
一般流程 1 2 3 4 5 6 7 8 9 10 11 from pwn import *context(os='linux' , arch='i386' , log_level='debug' ) p = process('./test' ) elf = ELF('./test' ) ... p.send(payload) p.interactive()