Write-ups: Program Security (Dynamic Allocator Misuse) series
Table of contents
前言
为了 2.9 的 Nu1L Junior 招新赛被迫先学点 Heap 的知识,本来是打算学完 FmtStr 和 Sandbox 再开这章的……想想还是得先开点堆的知识,因为栈我能临场自学,但堆是一点也不会啊。
看完讲义后,我果然没猜错,刚接触 Heap 是有点难度,一开始就要先被一堆新知识狠狠的冲击,要垮啦……打完 Pwn College 的 Heap 应该只能算有点基础知识,还得刷别的题,看 glibc
源码,要崩啦……
想想如果能成为 Heap ✌️ 得有多牛逼吧 LMAO
Level 1.0
Information
- Category: Pwn
Description
Exploit a use-after-free vulnerability to get the flag.
Write-up
atoi
,即 ASCII to Integer.
这题就是一个菜单程序,存在一个 UAF (Use After Free)
漏洞,简单来说就是在释放了一块内存后使用了指向已经被释放的内存的指针,这很容易造成的一个问题就是 Data disclosure.
简单分析这个程序我们发现,read_flag
会 malloc
一块空间,然后把 flag 写进去;puts
会输出 ptr
处的内容。我们的目的是输出 flag,那这个 ptr
就必须指向 flag 的起始地址才行。再观察 malloc
,它会将分配后返回的地址赋值给 ptr
。那思路就很清晰了:我们先使用 malloc
分配足够存下 flag 的内存,这会设置 ptr
,之后 free
它,接着使用 read_flag
,这会把 flag 写入 malloc
返回的地址处(同 ptr
保存的地址),最后调用 puts
就可以输出我们的 flag 了。
Exploit
Flag
Flag: pwn.college{8_UCfYUIGnvHU86NU1Qe-H6dK1o.0VM3MDL5cTNxgzW}
Level 1.1
Information
- Category: Pwn
Description
Exploit a use-after-free vulnerability to get the flag.
Write-up
参见 Level 1.0。
Exploit
Flag
Flag: pwn.college{8oPO3KqdZU5lZfzl5xftjR2IZif.0lM3MDL5cTNxgzW}
Level 2.0
Information
- Category: Pwn
Description
Create and exploit a use-after-free vulnerability to get the flag.
Write-up
与 Level 1 区别不大。
Exploit
Flag
Flag: pwn.college{ME7LG_Jy8T-xEw9H_njxpD2aJ4z.01M3MDL5cTNxgzW}
Level 2.1
Information
- Category: Pwn
Description
Create and exploit a use-after-free vulnerability to get the flag.
Write-up
参见 Level 2.0。
Exploit
Flag
Flag: pwn.college{MihEcPIR1bQBmiQGOoGELSrscgW.0FN3MDL5cTNxgzW}
Level 3.0
Information
- Category: Pwn
Description
Create and exploit a use-after-free vulnerability to get the flag when multiple allocations occur.
Write-up
这题的问题就在于标绿部分,把 flag 写入到 size_4
前会先进行两次 malloc
。所以我们应该先 malloc
出对应的两个块,然后 free
掉,这么做是为了令标绿部分的 malloc
分配空间到我们的数组中而不是别的地方,因为 puts
只能输出数组中的内容。之后再次调用 malloc
会从最近 free
掉的那个地址开始分配,如果我们想让 flag 出现在 idx 0 的话我们的 free
顺序应该是先 free 0
再 free 1
,之后再调用 read_flag
就会把 flag
写入 idx 0,我们用 puts
输出 idx 0 的内容即可。
Exploit
Flag
Flag: pwn.college{wvvL-j9QzjeoJrOsQS4Vval7exq.0VN3MDL5cTNxgzW}
Level 3.1
Information
- Category: Pwn
Description
Create and exploit a use-after-free vulnerability to get the flag when multiple allocations occur.
Write-up
参见 Level 3.0。
Exploit
Flag
Flag: pwn.college{wDLulwEpEQfpi78_Z4CAniTrByQ.0lN3MDL5cTNxgzW}