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
620
2020 交大程式安全:逆向工程上課講義-第二週(第二段)
terrynini
0
310
2020 交大程式安全:逆向工程上課講義-第一週(第一段)
terrynini
1
1.3k
2020 交大程式安全:逆向工程上課講義-第一週(第二段)
terrynini
1
670
2020 交大程式安全:逆向工程上課講義-第一週(第三段)
terrynini
3
2.2k
NTUST.pdf
terrynini
0
410
別pwn那裡.pdf
terrynini
0
530
逆逆_忍術_F5_消失之術_.pdf
terrynini
1
1.1k
成功高中講義.pdf
terrynini
0
820
Other Decks in Technology
See All in Technology
ABEMA の Datadog × OTel 基盤、 中から見るか? 外から見るか?
tetsuya28
0
110
Rancherの紹介&Update情報(RancherJP Online Meetup #09)
yoshiyuki_kono
0
130
非定型業務をAI slackbotで自動化する ~ 社内要望を自動壁打ちするbotを作った ~/automating-ad-hoc-work-with-ai-slackbot
shibayu36
0
210
protovalidate-es を導入してみた
bengo4com
0
150
Dario Amodi『Policy on the AI Exponential』を理解する
nagatsu
0
200
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/3 - 2026/5
oracle4engineer
PRO
1
220
価格.comをAI駆動で全面刷新する ー 30年分の技術的負債を返し、次の30年の土台をつくる ー / AI Engineering Summit Tokyo 2026
tkyowa
50
56k
AI Testing Talks: Challenges of Applying AI in Software Testing: From Hype to Practical Use
exactpro
PRO
1
140
AgentGatewayを試してみたかった
tkikuchi
0
120
AIプラットフォームを運用し続けるための可観測性
tanimuyk
4
1.2k
MIERUNE JCT 発表資料「宇宙から伊能忠敬ごっこ」
syuchimu
0
190
運用を見据えたAIエージェント設計実践
amacbee
1
3.2k
Featured
See All Featured
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
330
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
280
HDC tutorial
michielstock
2
690
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
Leo the Paperboy
mayatellez
7
1.8k
Everyday Curiosity
cassininazir
0
220
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
350
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
Testing 201, or: Great Expectations
jmmastey
46
8.2k
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/