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
AIS3-Firmware Security Analysis
Search
terrynini
July 30, 2019
Technology
1.3k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AIS3-Firmware Security Analysis
terrynini
July 30, 2019
More Decks by terrynini
See All by terrynini
2020 交大程式安全:逆向工程上課講義-第二週(第一段)
terrynini
1
630
2020 交大程式安全:逆向工程上課講義-第二週(第二段)
terrynini
0
320
2020 交大程式安全:逆向工程上課講義-第一週(第一段)
terrynini
1
1.3k
2020 交大程式安全:逆向工程上課講義-第一週(第二段)
terrynini
1
680
2020 交大程式安全:逆向工程上課講義-第一週(第三段)
terrynini
3
2.2k
NTUST.pdf
terrynini
0
420
別pwn那裡.pdf
terrynini
0
530
逆逆_忍術_F5_消失之術_.pdf
terrynini
1
1.1k
成功高中講義.pdf
terrynini
0
870
Other Decks in Technology
See All in Technology
kintone の AI コワーカーを、 Anthropic にエージェントを"ホストさせて"作った話 #devkinmeetup
sugimomoto
0
110
SRE本の知られざる名シーン / The Hidden Gems of Google SRE Book
nari_ex
1
410
ruby.wasmとPicoRuby.wasmに対応した仮想DOMライブラリを作ってる話 #kaigieffect_kaigi
sue445
PRO
0
150
AI Agent SaaS を支える自社仮想化基盤への挑戦と実運用 / ai-agent-saas-virtualization
flatt_security
3
4k
AICoEでAIネイティブ組織への進化
yukiogawa
0
190
Terraform共通モジュールをチーム横断で“変えられる”運用へ ― リリースと適用の分離
kekke_n
1
3.2k
事業価値を⽣み出すSREへ SREが担うべき意思決定の5層
kenta_hi
2
3.8k
Foxgloveについて 実際にExtensionを開発して公開するまでの話 / About Foxglove: The Story of Developing and Releasing an Extension
ry0_ka
0
290
誤解だらけの開発生産性 / Myths and Misconceptions about Developer Productivity
i35_267
2
750
そのドキュメント、自動化しませんか?
yuksew
1
240
End-to-Endで考える信頼性 —LINEアプリにおけるクライアント開発×SRE連携の実践
maruloop
4
4.4k
Kaggleで成長するために意識したこと
prgckwb
2
400
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Prompt Engineering for Job Search
mfonobong
0
370
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
Between Models and Reality
mayunak
4
370
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
950
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
230
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
720
Context Engineering - Making Every Token Count
addyosmani
9
1k
Skip the Path - Find Your Career Trail
mkilby
1
170
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.7k
Transcript
Firmware Security Analysis 李倫銓 Alan, NiNi
About Linkit7697 LinkIt7697 是一塊針對物聯網應用的開發版,基於 MT7697 系統單晶片, 具有含浮點運算的 ARM Cortex-M4 微控制器,
並整合了 802.11b/g/n WiFi 無線網路與 Bluetooth 4.2 低功耗藍牙。
What is firmware ROM EPROM flash memory firmware firmware firmware
Firmware is a piece of code stored in ROM, EPROM, flash memory. It may provide some functions to software to control hardware. Or, it may be the only program that will run on the embedded system.
Before starting…. 先把 firmware 燒上去
UART UART 1 UART 2 Tx Rx Tx Rx
UART UART 1 UART 2 Tx Rx 1 0 1
1 1 0 1
PC RAM BIOS Hard Disk MBR boot loader Boot loader
PC RAM BIOS Hard Disk MBR boot loader Boot loader
BIOS 抓
PC RAM BIOS Hard Disk boot loader MBR Boot loader
MBR BIOS 抓完
Boot loader PC RAM Hard Disk boot loader MBR MBR
MBR 抓
Boot loader PC RAM Hard Disk boot loader MBR MBR
Boot MBR 抓沒完
Boot loader PC RAM Hard Disk boot loader MBR MBR
Boot MBR 再抓
Boot loader PC RAM Hard Disk boot loader MBR MBR
Boot loader Boot loader完成載入
Boot loader DEMO
ARM ARM 架構有需多版本, 從最早的 ARMv1 到現在的 ARMv8 每個版本都有引入一些新的特色。
ARM ARM不賣晶片,而是靠授權架構賺錢, 實作則是由購買的公司進行(一般不能改架構), CPU 名字跟架構版本沒有關係, 如 ARM7EJ 對應 ARMv5,ARM11 對應
ARMv6。
ARM 但 ARM11 之後改變了命名的方式,改為 Cortex-A Application profile Cortex-R Real-time profile
Cortex-M Microcontroller profile
ARM ARM 有兩個模式 一個 ARM,一個 Thumb Thumb 是 ARM 的子集,
ARM 一條指令需要 4Byte 的編碼 , Thumb 則是 2 or 4 byte
ARM 00010400 <main>: 10400: b580 push {r7, lr} 10402: af00
add r7, sp, #0 10404: 4b03 ldr r3, [pc, #12] ; (10414 <main+0x14>) 10406: 0018 movs r0, r3 10408: f7ff ff68 bl 102dc <puts@plt> 1040c: 2300 movs r3, #0 1040e: 0018 movs r0, r3 10410: 46bd mov sp, r7 10412: bd80 pop {r7, pc} 000103fc <main>: 103fc: e92d4800 push {fp, lr} 10400: e28db004 add fp, sp, #4 10404: e59f000c ldr r0, [pc, #12] ; 10418 <main+0x1c> 10408: ebffffb3 bl 102dc <puts@plt> 1040c: e3a03000 mov r3, #0 10410: e1a00003 mov r0, r3 10414: e8bd8800 pop {fp, pc}
ARM 後來則增強為 Thumb2 ,code density 與 Thumb 接近 但有類似 ARM
的性能
ARM 快問快答
ARM http://infocenter.arm.com/help/topic/com.arm.doc.dui0553b/DUI0553.pdf http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001m/QRC0001_UAL.pdf Cortex-M4 Manual ARM Thumb2 cheatsheet
ARM 暫存器 R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 2.1.3 Core registers
ARM 基本運算 opcode Rd, Rn opcode Rd, Rn, Op2
ARM MOV R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0x0000FA05 MOV R1, #0xFA05 3.5.6 MOV and MVN
ARM R0 R1 R2 R3 R4 R5 R6 R7 R8
R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0x0000FA05 0x00000100 MOV R1, #0xFA05 MOV R5, #256 MOV 3.5.6 MOV and MVN
ARM R0 R1 R2 R3 R4 R5 R6 R7 R8
R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0x0000FA05 0x0000BEEF 0x00000100 MOV R1, #0xFA05 MOV R5, #256 MOVW R3, #0xBEEF MOV 3.5.6 MOV and MVN
ARM R0 R1 R2 R3 R4 R5 R6 R7 R8
R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0x0000FA05 0xDEADBEEF 0x00000100 MOV R1, #0xFA05 MOV R5, #256 MOVW R3, #0xBEEF MOVT R3, #0xDEAD MOV 3.5.6 MOV and MVN
ARM R0 R1 R2 R3 R4 R5 R6 R7 R8
R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0x0000FA05 0xFFFFFFF0 0xDEADBEEF 0x00000100 MOV R1, #0xFA05 MOV R5, #256 MOVW R3, #0xBEEF MOVT R3, #0xDEAD MVN R2, #0xF MOV 3.5.6 MOV and MVN
ARM LDR/STR 只有 ldr 跟 str 可以存取記憶體 其他 opcode 的運算子都不能存取記憶體
3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xFFFFFFF0 0xDEADBEEF 0x00000100 0x100 0x104 0xfaceb00c 0xdeadbeef LDR R1, [R5] 3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xfaceb00c 0xFFFFFFF0 0xDEADBEEF 0x00000100 LDR R1, [R5] 0x100 0x104 0xfaceb00c 0xdeadbeef 3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xfaceb00c 0xFFFFFFF0 0xDEADBEEF 0x00000100 LDR R1, [R5] STR R2, [R5,#4] 0x100 0x104 0xfaceb00c 0xdeadbeef 3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xfaceb00c 0xFFFFFFF0 0xDEADBEEF 0x00000100 0x100 0x104 0xfaceb00c 0xFFFFFFF0 LDR R1, [R5] STR R2, [R5,#4] 3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xfaceb00c 0xFFFFFFF0 0xDEADBEEF 0x00000100 0x100 0x104 0xfaceb00c 0xFFFFFFF0 LDR R1, [R5] STR R2, [R5,#4] LDR R2, [R5],#4 3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xfaceb00c 0xfaceb00c 0xDEADBEEF 0x00000104 0x100 0x104 0x108 0xfaceb00c 0xFFFFFFF0 LDR R1, [R5] STR R2, [R5,#4] LDR R2, [R5],#4 3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xfaceb00c 0xfaceb00c 0xDEADBEEF 0x00000104 0x100 0x104 0x108 0xfaceb00c 0xFFFFFFF0 LDR R1, [R5] STR R2, [R5,#4] LDR R2, [R5],#4 STR R2, [R5,#4]! 3.4 Memory access instructions
ARM LDR/STR R0 R1 R2 R3 R4 R5 R6 R7
R8 R9 R10 R11 R12 SP(R13) LR(R14) PC(R15) 0xfaceb00c 0xfaceb00c 0xDEADBEEF 0x00000108 0x100 0x104 0x108 0xfaceb00c 0xFFFFFFF0 0xfaceb00c LDR R1, [R5] STR R2, [R5,#4] LDR R2, [R5],#4 STR R2, [R5,#4]! 3.4 Memory access instructions
ARM 單位 10101010 10101010 10101010 10101010 10101010 10101010 10101010 1
BYTE 1 Half Word 1 Word LDR LDRH, LDRSH LDRB, LDRBH
ARM condition execution N -> negative Z -> zero C
-> carry V -> overflow CMP R1, #3 LDREQ R1, [R5] 3.3.7 Condition execution
ARM condition execution N -> negative Z -> zero C
-> carry V -> overflow if( r1 == 3 ) r1 = *r5 3.3.7 Condition execution
ARM condition execution CMP R1, #3 IT EQ LDREQ R1,
[R5] N -> negative Z -> zero C -> carry V -> overflow 3.3.7 Condition execution
ARM condition execution N -> negative Z -> zero C
-> carry V -> overflow if( r1 == 3 ) r1 = *r5 3.3.7 Condition execution
ARM condition execution CMP R1, #3 ITT EQ LDREQ R1,
[R5] LDREQ R2, [R5] N -> negative Z -> zero C -> carry V -> overflow 3.3.7 Condition execution
ARM condition execution N -> negative Z -> zero C
-> carry V -> overflow if( r1 == 3 ){ r1 = *r5 r2 = *r5 } 3.3.7 Condition execution
ARM condition execution CMP R1, #3 ITTE EQ LDREQ R1,
[R5] LDREQ R2, [R5] ADDNE R1, #1 N -> negative Z -> zero C -> carry V -> overflow 3.3.7 Condition execution
ARM condition execution N -> negative Z -> zero C
-> carry V -> overflow if( r1 == 3 ){ r1 = *r5 r2 = *r5 }else{ r1 += 1 } 3.3.7 Condition execution
ARM B{cond} lable 跳轉 BL{cond} lable 跳轉,把 return address 放進
LR BX{cond} Rm 跳轉 BXL{cond} Rm 跳轉,把 return address 放進 LR 3.10 Branch and control instructions
Find the main Literal Pool
Find the main
BONUS TIME
Secure Boot
Secure Boot 所以在 Bootloader 執行時 我們要確保即將掛載的 firmware 不是修改過的
Secure Boot Reset ROM Bootloader Bootloader input Signed? yes no
Bootloader firmware input Signed? yes no Stop or Recover
Secure Boot Bootloader hash ##### encrypt flash memory key
Secure Boot Bootloader hash ##### encrypt flash memory key burn
eFuse
Secure Boot Firmware digital signature hash ##### private key (on
your PC) signature algorithm
Secure Boot Firmware digital signature hash ##### public key (in
bootloader) signature algorithm Same?
Secure Boot But this is not the end……
Secure Boot Tegra X1
Secure Boot Tegra X1 USB Recovery Mode https://http.download.nvidia.com/tegra-public-appnotes/tegra-boot-flow.html#_error_handling_and_recovery_mode
Secure Boot Fusée Gelée:https://github.com/Qyriad/fusee-launcher ShofEL2:https://fail0verflow.com/blog/2018/shofel2/