pwn坑

想了下,还是专门开个文章记录一下学PWN遇到的一些坑(对我自己来说),好比大一那会儿刚接触C语言的时候,各种小问题导致在学校OJ网站上面做题时,一直AC不了。

1.使用asm(shellcraft.sh()) 生成shellcode时,默认生成32位的。如果是64位context(arch="amd64",os="linux",log_level="debug")

2.64位注意堆栈平衡,16字节对齐,可能需要ret 一下,32位函数形参放在上一个函数栈帧上面。64位函数形参放在寄存器里面,读汇编代码时,返回地址可以看到放在rax里面。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ROPgadget //can find the address of ret 
eg: ROPgadget --binary ./pwn38 --only "pop|ret" | grep "ret"
ROPgadget –binary pwn38 –string “cat /ctfshow_flag”

ropper can also find the address
eg: ropper --file pwn72 --search "int 0x80"

ELF //can find the address of some func and args correctly
eg: elf=ELF("./pwn")
systemaddress=elf.sym['system']
backdoor_func_address=elf.sym["backdoor"]
bin_sh_arg_address=next(elf.search("/bin/sh"))

something about IDA
ctrl + s 可以看到各段的一些信息
shift+f12 可以查看参数值
Alt+T 可以根据关键参数去找相应函数
ctrl + f 在函数搜索框里可以看到相应函数

  1. python对导入包的顺序非常敏感,比如PWN73题,我先导入from struct import pack,再去导入from pwn import * 就会出错。得交换一下顺序。