Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CVE-2024-2961@HackerSir StudyGroup
Search
YJK
July 23, 2025
0
2
CVE-2024-2961@HackerSir StudyGroup
YJK
July 23, 2025
Tweet
Share
More Decks by YJK
See All by YJK
From 0 to Shell PWN Basic
yjk0805
0
7
Master of ROP:PWN Advanced
yjk0805
0
12
Basic Reverse-逆要做什麼@THUHC
yjk0805
0
15
Reproducing Vulnerability in IoT@HackerSir StudyGroup
yjk0805
0
22
你 PWN 不動我@HackerSir 10th
yjk0805
0
11
Reverse 0x1@HackerSir 10th
yjk0805
0
13
Reverse 0x2@HackerSir 10th
yjk0805
0
9
不要亂 PWN 我@HackerSir 10th
yjk0805
0
14
Assembly@HackerSir 10th
yjk0805
0
11
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
Producing Creativity
orderedlist
PRO
346
40k
Designing for humans not robots
tammielis
253
25k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Gamification - CAS2011
davidbonilla
81
5.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
We Have a Design System, Now What?
morganepeng
53
7.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
1k
Transcript
CVE-2024-2961 GLIBC iconv() vulnerability YJK@HackerSir
Table of contents 01 03 02 Vulnerability php filter php
heap 04 php filter to CVE-2024-2961 05 Reproduce
Vulnerability 01
Vulnerability • iconv() • convert type • Ex: UTF-8->UTF-16 or
???
Vulnerability • iconv() • iconv_t iconv_open(const char *tocode, const char
*fromcode);
Vulnerability • iconv() • iconv_t iconv_open(const char *tocode, const char
*fromcode); • 理論上 buffer 皆由呼叫方決定,如果有狀況要出 error message
Vulnerability • But?? • ISO-2022-CN-EXT,用於轉換中文,擴充 ISO-2022-CN • 應該要確認 output buffer
是否足夠 • 只有確認一個部分 • source code • oob write • overflow 1~3 bytes
Vulnerability • $*H [24 2A 48] • $+I [24 2B
49] • $+J [24 2B 4A] • $+K [24 2B 4B] • $+L [24 2B 4C] • $+M [24 2B 4D] • 劄、䂚、峛、湿 會有狀況
php filter 02
php protocol • file:// — Accessing local filesystem • ftp://
— Accessing FTP(s) URLs • php:// — Accessing various I/O streams • zlib:// — Compression Streams • data:// — Data (RFC 2397) • glob:// — Find pathnames matching pattern • phar:// — PHP Archive • manual
php filter • 有很多 filter,處理某些 stream 的資訊 • php://filter/convert.base64-encode/resource=/etc/passwd •
string.upper:convert to uppercase • string.lower:convert to lowercase • string.rot13:ROT13 • convert.iconv.X.Y:converts charset from X to Y • ......
還可以? • 一直串下去
還可以? • 一直串下去 • php filter chain (LFI to RCE)
convert.iconv.X.Y • iconv API 在 Linux 中會呼叫到 glibc 實現 •
利用 php filter 搭配 convert.iconv.X.Y 來實現 RCE
php heap 03
php heap • emalloc(n)、efree(ptr) • 各種 size(0x10、0x20、0x25…) • 分為 512
pages 的 0x1000 bytes • 每個 page 大小都不相同 (ex: page11: 0x40、page12: 0x180…) • free 掉 chunk 後會被丟到 free list 的 singly linked list • 每個 size 都有自己的 free list
allocate 流程 • 先看相對應 size 的 free list,有東西就拿他的 head •
沒有就看有無未使用的空間,在空的空間拿一塊並放入相對應的 list • LIFO • 後 free 會先被拿,跟 GLIBC 的 tcache 類似,無空間限制 • _zend_mm_heap
allocate 流程
特點 • 未分配的 chunk 都有 8 bytes 指向下一塊 free chunk
的 Pointer • 可以 overflow 到下一個 chunk 的 pointer,藉此修改 free list
特點 • 未分配的 chunk 都有 8 bytes 指向下一塊 free chunk
的 Pointer • 可以 overflow 到下一個 chunk 的 pointer,藉此修改 free list • 但 php 會在每次 request create 一個新的 heap,所以不好利用
php filter to CVE-2024-2961 04
Bucket brigade • 從 stream 拿資料,存在 bucket,使用 doubly-linked list •
如果串了各種 filter ▪ 一個 buckets 一個 buckets 處理,依照順序 • _php_stream_bucket
Bucket brigade • 轉換方式
zlib_inflate • 正常一個 stream 都只會有一個 bucket • 但如果有 dechunk 解壓縮超過
0x8000 就會建新的 bucket • 建到直到裝得完為止
dechunk
dechunk
dechunk
convert.iconv.L1.L1 • latin1.latin1 • 單純只是用來 trigger realloac
暫時總結 • zlib.inflate • dechunk ▪ 控 input buf 到
0x100 • convert.iconv.L1.L1 ▪ trigger realloc • dechunk ▪ 控 input buf 到 16 • convert.iconv.L1.L1 ▪ trigger realloc (free prev)
Arbitraty Write
暫時總結 • zlib.inflate • dechunk + convert.iconv.L1.L1 ▪ alloc 0x100*3
• dechunk + convert.iconv.L1.L1 ▪ free 0x100*3 ▪ alloc 0x100*2 • dechunk + trigger bug • 任意寫
RCE • 跟 zend_mm_heap 有關 • 寫 malloc、free、realloc • free->system、use_custom_heap->1
RCE • 跟 zend_mm_heap 有關 • 寫 malloc、free、realloc • 目標:free->system、use_custom_heap->1
• heap_base、system address? • 有回顯->讀 /proc/self/maps、libc.so • 沒回顯->想辦法讀 /proc/self/maps、libc.so • 要想辦法不要弄壞任何部分,不然可能只有一次機會
RCE • zlib.inflate • dechunk + convert.iconv.L1.L1 • dechunk +
convert.iconv.L1.L1 • dechunk + trigger bug • convert.quoted-printable-decode + convert.iconv.L1.L1
Reproduce 05
Reference • Iconv, set the charset to RCE: Exploiting the
glibc to hack the PHP engine • Analysis of CVE-2024–2961 Vulnerability • CVE-2024-2961 调试复现分析 • cnext-exploits • DEFCON 32 talk
None