Submit Search
Upload
Reverse Engineering - Assembly & Introduction
•
1 like
•
337 views
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Follow
TA Lesson in Information Security Basic of Reverse Engineering
Read less
Read more
Software
Report
Share
Report
Share
1 of 53
Download now
Download to read offline
Recommended
Heap exploitation
Heap exploitation
Angel Boy
Shell脚本
Shell脚本
bj
Binary exploitation - AIS3
Binary exploitation - AIS3
Angel Boy
Linux常用命令与工具简介
Linux常用命令与工具简介
weihe
Return to dlresolve
Return to dlresolve
Angel Boy
程式設計師的自我修養 Chapter 10 記憶體
程式設計師的自我修養 Chapter 10 記憶體
Shu-Yu Fu
系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入
鍾誠 陳鍾誠
如何学习Bash Shell
如何学习Bash Shell
LI Daobing
Recommended
Heap exploitation
Heap exploitation
Angel Boy
Shell脚本
Shell脚本
bj
Binary exploitation - AIS3
Binary exploitation - AIS3
Angel Boy
Linux常用命令与工具简介
Linux常用命令与工具简介
weihe
Return to dlresolve
Return to dlresolve
Angel Boy
程式設計師的自我修養 Chapter 10 記憶體
程式設計師的自我修養 Chapter 10 記憶體
Shu-Yu Fu
系統程式 -- 第 5 章 連結與載入
系統程式 -- 第 5 章 連結與載入
鍾誠 陳鍾誠
如何学习Bash Shell
如何学习Bash Shell
LI Daobing
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器
鍾誠 陳鍾誠
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
鍾誠 陳鍾誠
Execution
Execution
Angel Boy
[Crypto Course] Block Cipher Mode
[Crypto Course] Block Cipher Mode
WEI CHIEH CHAO
第9章文件
第9章文件
summerfeng
系統程式 -- 附錄
系統程式 -- 附錄
鍾誠 陳鍾誠
Sigreturn Oriented Programming
Sigreturn Oriented Programming
Angel Boy
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
Angel Boy
Linux command tutorial
Linux command tutorial
朋 陈
自然语言处理 中文分词程序实验报告%28含源代码%29
自然语言处理 中文分词程序实验报告%28含源代码%29
aemoe
ch13-pv1-system-calls
ch13-pv1-system-calls
yushiang fu
Android C Library: Bionic 成長計畫
Android C Library: Bionic 成長計畫
Kito Cheng
系統程式 - 第二章
系統程式 - 第二章
鍾誠 陳鍾誠
系統程式 -- 第 2 章
系統程式 -- 第 2 章
鍾誠 陳鍾誠
系統程式 -- 第 12 章
系統程式 -- 第 12 章
鍾誠 陳鍾誠
系統程式 -- 第 3 章 組合語言
系統程式 -- 第 3 章 組合語言
鍾誠 陳鍾誠
ch7-pv1-modules
ch7-pv1-modules
yushiang fu
系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器
鍾誠 陳鍾誠
系統程式 - 附錄
系統程式 - 附錄
鍾誠 陳鍾誠
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Kito Cheng
Linux 教育訓練
Linux 教育訓練
Bo-Yi Wu
Java 開發者的函數式程式設計
Java 開發者的函數式程式設計
Justin Lin
More Related Content
What's hot
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器
鍾誠 陳鍾誠
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
鍾誠 陳鍾誠
Execution
Execution
Angel Boy
[Crypto Course] Block Cipher Mode
[Crypto Course] Block Cipher Mode
WEI CHIEH CHAO
第9章文件
第9章文件
summerfeng
系統程式 -- 附錄
系統程式 -- 附錄
鍾誠 陳鍾誠
Sigreturn Oriented Programming
Sigreturn Oriented Programming
Angel Boy
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
Angel Boy
Linux command tutorial
Linux command tutorial
朋 陈
自然语言处理 中文分词程序实验报告%28含源代码%29
自然语言处理 中文分词程序实验报告%28含源代码%29
aemoe
ch13-pv1-system-calls
ch13-pv1-system-calls
yushiang fu
Android C Library: Bionic 成長計畫
Android C Library: Bionic 成長計畫
Kito Cheng
系統程式 - 第二章
系統程式 - 第二章
鍾誠 陳鍾誠
系統程式 -- 第 2 章
系統程式 -- 第 2 章
鍾誠 陳鍾誠
系統程式 -- 第 12 章
系統程式 -- 第 12 章
鍾誠 陳鍾誠
系統程式 -- 第 3 章 組合語言
系統程式 -- 第 3 章 組合語言
鍾誠 陳鍾誠
ch7-pv1-modules
ch7-pv1-modules
yushiang fu
系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器
鍾誠 陳鍾誠
系統程式 - 附錄
系統程式 - 附錄
鍾誠 陳鍾誠
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Kito Cheng
What's hot
(20)
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 4 章 組譯器
系統程式 -- 第 11 章 嵌入式系統
系統程式 -- 第 11 章 嵌入式系統
Execution
Execution
[Crypto Course] Block Cipher Mode
[Crypto Course] Block Cipher Mode
第9章文件
第9章文件
系統程式 -- 附錄
系統程式 -- 附錄
Sigreturn Oriented Programming
Sigreturn Oriented Programming
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
Linux command tutorial
Linux command tutorial
自然语言处理 中文分词程序实验报告%28含源代码%29
自然语言处理 中文分词程序实验报告%28含源代码%29
ch13-pv1-system-calls
ch13-pv1-system-calls
Android C Library: Bionic 成長計畫
Android C Library: Bionic 成長計畫
系統程式 - 第二章
系統程式 - 第二章
系統程式 -- 第 2 章
系統程式 -- 第 2 章
系統程式 -- 第 12 章
系統程式 -- 第 12 章
系統程式 -- 第 3 章 組合語言
系統程式 -- 第 3 章 組合語言
ch7-pv1-modules
ch7-pv1-modules
系統程式 -- 第 9 章 虛擬機器
系統程式 -- 第 9 章 虛擬機器
系統程式 - 附錄
系統程式 - 附錄
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Similar to Reverse Engineering - Assembly & Introduction
Linux 教育訓練
Linux 教育訓練
Bo-Yi Wu
Java 開發者的函數式程式設計
Java 開發者的函數式程式設計
Justin Lin
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
Kris Mok
Linux基础
Linux基础
zhuqling
Linux Binary Exploitation - Stack buffer overflow
Linux Binary Exploitation - Stack buffer overflow
Angel Boy
Linux Tracing System 浅析 & eBPF框架开发经验分享
Linux Tracing System 浅析 & eBPF框架开发经验分享
happyagan
linux 從無到有
linux 從無到有
alex867
Rootkit 101
Rootkit 101
WEI CHIEH CHAO
Python入門:5大概念初心者必備 2021/11/18
Python入門:5大概念初心者必備 2021/11/18
Derek Lee
Effective linux.1.(commandline)
Effective linux.1.(commandline)
wang hongjiang
新北市教師工作坊 -- Bash script programming 介紹
新北市教師工作坊 -- Bash script programming 介紹
fweng322
Php More
Php More
henbo
Oda安装 恢复步骤
Oda安装 恢复步骤
n-lauren
Similar to Reverse Engineering - Assembly & Introduction
(13)
Linux 教育訓練
Linux 教育訓練
Java 開發者的函數式程式設計
Java 開發者的函數式程式設計
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
Linux基础
Linux基础
Linux Binary Exploitation - Stack buffer overflow
Linux Binary Exploitation - Stack buffer overflow
Linux Tracing System 浅析 & eBPF框架开发经验分享
Linux Tracing System 浅析 & eBPF框架开发经验分享
linux 從無到有
linux 從無到有
Rootkit 101
Rootkit 101
Python入門:5大概念初心者必備 2021/11/18
Python入門:5大概念初心者必備 2021/11/18
Effective linux.1.(commandline)
Effective linux.1.(commandline)
新北市教師工作坊 -- Bash script programming 介紹
新北市教師工作坊 -- Bash script programming 介紹
Php More
Php More
Oda安装 恢复步骤
Oda安装 恢复步骤
More from Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator
Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
AEG_ Automatic Exploit Generation
AEG_ Automatic Exploit Generation
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Unleashing MAYHEM On Binary Code
Unleashing MAYHEM On Binary Code
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Firmadyne
Firmadyne
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Fintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJS
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
TA-java-method-109
TA-java-method-109
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
TA Lesson Web-109
TA Lesson Web-109
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Java - TA課 - Array
Java - TA課 - Array
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
TA Lesson3 - Method
TA Lesson3 - Method
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Web Introduction
Web Introduction
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Java - TA課 - Let's Begin
Java - TA課 - Let's Begin
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Java - TA課 - 開發環境
Java - TA課 - 開發環境
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
IoT Penetration Talk
IoT Penetration Talk
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Introduction to computer network
Introduction to computer network
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
Assembly Language Redhung ( x86 ) @ TDOH
Assembly Language Redhung ( x86 ) @ TDOH
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
TP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attack
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
滲透測試入門 Penetration test - white hat hacking introduction
滲透測試入門 Penetration test - white hat hacking introduction
Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
More from Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.
(18)
Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator
Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator
AEG_ Automatic Exploit Generation
AEG_ Automatic Exploit Generation
Unleashing MAYHEM On Binary Code
Unleashing MAYHEM On Binary Code
Firmadyne
Firmadyne
Fintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJS
TA-java-method-109
TA-java-method-109
TA Lesson Web-109
TA Lesson Web-109
TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)
Java - TA課 - Array
Java - TA課 - Array
TA Lesson3 - Method
TA Lesson3 - Method
Web Introduction
Web Introduction
Java - TA課 - Let's Begin
Java - TA課 - Let's Begin
Java - TA課 - 開發環境
Java - TA課 - 開發環境
IoT Penetration Talk
IoT Penetration Talk
Introduction to computer network
Introduction to computer network
Assembly Language Redhung ( x86 ) @ TDOH
Assembly Language Redhung ( x86 ) @ TDOH
TP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attack
滲透測試入門 Penetration test - white hat hacking introduction
滲透測試入門 Penetration test - white hat hacking introduction
Reverse Engineering - Assembly & Introduction
1.
REVERSE- ASSEMBLY & INTRODUCTION TA LESSON
@ 108-1 INFORMATION SECURITY
2.
WHO AM I WHO
AM I ▸ 陳靖汯 a.k.a Redhung ▸ 國立中正⼤大學資管系 ▸ redhung@hung.red ▸ 興趣:CTF、逆向 ▸ 配偶:橋本環奈
3.
序⾔ 序⾔ ▸ 在開始前 ...
說說為何我們需要學習組合語⾔言? ▸ 組合語⾔言是最接近底層的語⾔言 ▸ 藉由學習組合語⾔言可以更更了了解電腦核⼼心運作的⽅方式 ▸ 學習組合語⾔言也是希望⾃自⼰己能看懂反組譯出來來的程式碼, 對於逆向⼯工程有興趣的同學是不可或缺的技能
4.
指令集 CPU架構 組合語⾔言
STACK FRAME 逆向⼯工程
5.
指令集 RISC、CISC
6.
指令集 RISC ▸ 精簡指令集(Reduced Instruction
Set Computing) ▸ 指令系統簡單、精簡 ▸ 指令數⽬目⼩小於100條 ▸ ARM架構使⽤用RISC指令集
7.
指令集 CISC ▸ 複雜指令集(Complex Instruction
Set Computing) ▸ 指令系統複雜、龐⼤大 ▸ 指令數⽬目⼤大於200條 ▸ X86架構使⽤用CISC指令集
8.
CPU架構 ARM &X86
9.
CPU架構 ARM ▸ 最早為Acorn公司所開始發展 ▸ 功能相對X86較為簡單 ▸
耗電量量明顯更更低 ▸ 因此設計路路線與X86為不同⽅方向 ▸ ARM專注於低成本、低耗能的研發⽅方向
10.
CPU架構 X86 ▸ 最早為Intel公司發展出的「Intel8086」CPU ▸ 其後系列列CPU結尾皆為86,因此其架構被稱為X86 ▸
功能相較ARM較為強⼤大 ▸ X86專注於效能、速度的開發 ▸ 普遍PC都是使⽤用Intel的CPU ▸ 因此CTF與實戰上通常遇到的都是X86架構
11.
組合語⾔ X86架構
12.
X86架構-組合語⾔ 組合語⾔ ▸ Assembly language(Assembly
code)為低階語⾔言 ▸ Human readable,易易讀 ▸ Machine code <——> Assembly code ▸ Assembler:ASM —> 01 ▸ Disassembler:01 —> ASM ▸ CPU指令:mov, add, sub, push, pop, etc. ▸ X64 assembly、X86 assembly
13.
X86架構-組合語⾔ 記憶體 ▸ 記憶體是可供 CPU
存取操作具有保存訊息功能的設備,CPU 要 和記憶體溝通必須透過三類的訊息交換 ▸ 1. 地址訊息: 欲讀取或寫入的地址 ▸ 2. 控制訊息: 對記憶體的操作(讀取或寫入) ▸ 3. 數據訊息: 讀取或寫入的資料 ▸ CPU 想要將資料寫入記憶體,必需先知道記憶體的地址,接著告 訴記憶體要進⾏行行寫入的操作,最後把資料送過去,以上為 CPU 對記憶體操作的⼤大致流程
14.
X86架構-組合語⾔ 暫存器 REGISTER ▸ ⼀一般暫存器: ▸
RAX, RBX, RCX, RDX —> 64bits ▸ EAX, EBX, ECX, EDX —> 32bits ▸ AX, BX, CX, DX —> 16bits ▸ AX, BX, CX, DX 底下還有 H, L ▸ AX —> AH, AL —> 8bits RAX EAX AX AH AL
15.
X86架構-組合語⾔ 暫存器 REGISTER ▸ 索引暫存器: ▸
RSI, RDI —> 64bits ▸ ESI, EDI —> 32bits ▸ SI, DI —> 16bits ▸ RSI:來來源索引暫存器 ▸ RDI:⽬目的索引暫存器 RSI ESI SI
16.
X86架構-組合語⾔ 暫存器 REGISTER ▸ RSP,
ESP ▸ 指向堆疊(Stack)的最頂端 ▸ RBP, EBP ▸ 指向堆疊(Stack)的最尾端 ▸ RSP, ESP ▸ 指向程式當前執⾏行行的位址 FUNCTION() ARGUMENT RETURN ADDRESS SAVED RBP RSP RBP High address Low address
17.
X86架構-組合語⾔ X64 ASSEMBLY ▸ mov ▸
add, sub ▸ and, or, xor ▸ push, pop ▸ call, jmp ▸ leave, ret
18.
X86架構-組合語⾔ MOV ▸ mov ⽬目的,
來來源 ▸ 將來來源資料複製到⽬目的 ▸ mov rax, 5 —> rax = 5 ▸ mov rax, rbx —> rax = rbx 的值 ▸ mov [rax], 0x123 —> 將0x123儲存⾄至rax指向的內容地址
19.
X86架構-組合語⾔ ADD, SUB ▸ add
⽬目的, 來來源 ▸ add rax, rbx —> rax = rax + rbx ▸ sub ⽬目的, 來來源 ▸ sub rax, rbx —> rax = rax - rbx
20.
X86架構-組合語⾔ AND, OR, XOR ▸
and ⽬目的, 來來源 ▸ and rax, rbx —> rax = rax & rbx ▸ or ⽬目的, 來來源 ▸ or rax, rbx —> rax = rax | rbx ▸ xor ⽬目的, 來來源 ▸ xor rax, rbx —> rax = rax ^ rbx
21.
X86架構-組合語⾔ CALL, JMP ▸ jmp
地址 ▸ 跳⾄至程式某⼀一地址執⾏行行 ▸ call 地址 ▸ 先儲存執⾏行行完function後要回來來的下⼀一⾏行行程式碼的地址 ▸ 呼叫指定地址的function
22.
X86架構-組合語⾔ LEAVE, RET ▸ leave ▸
還原上⼀一層Stack frame ▸ mov rsp, rbp ▸ pop rbp ▸ ret ▸ funtion結束後返回 ▸ ret = pop rip
23.
X86架構-組合語⾔ 堆疊 STACK ▸ Data
structure ▸ Memory section ▸ LIFO(Last In First Out) ▸ Stack由⾼高地址往低地址⽣生長
24.
X86架構-組合語⾔ PUSH, POP ▸ push
來來源 ▸ 將來來源資料放入堆疊記憶體 ▸ push rax = sub rsp, 8; mov [rsp], rax ▸ pop ⽬目的 ▸ 從堆疊記憶體取出資料放入⽬目的 ▸ pop rax = mov rax, [rsp]; add rsp, 8 High address Low address
25.
STACK FRAME 實際運作
26.
STACK FRAME STACK FRAME ▸
stack 是由⼀一些邏輯的 stack frame 所組成,當呼叫⼀一個 function 就會 push stack frame,當執⾏行行結果回傳後就 pop ▸ ⼀一個 stack frame 包含了了: ▸ 1. ⼀一個 function 的參參數 ▸ 2. 他的 local 的變數 ▸ 3. 復原前⼀一個 stack frame 所需要的資料 ▸ 4. 當 function call 的時候那些 instruction pointers 的值
27.
STACK FRAME STACK FRAME
運作⽅式 - PART 1 ▸ Function parameters ▸ 假設今天呼叫了了⼀一個 foo( a, b, c ),會呈現為: ▸ Push a ▸ Push b ▸ Push c ▸ Call foo
28.
STACK FRAME STACK FRAME
運作⽅式 - PART 2 ▸ Stackframe back pointer ▸ 現在我們已經要開始執⾏行行foo了了,如果想存取變數的話: ▸ [esp + 0] - return address ▸ [esp + 4] - parameter 'a' ▸ [esp + 8] - parameter 'b' ▸ [esp + 12] - parameter 'c' ▸ 但我們現在的RBP, RSP還沒指向foo的stack frame,因此我們必須先儲存當前stack frame的 RBP,再將RBP指過去 ▸ push rbp ; 儲存舊的RBP ▸ mov rbp, rsp ; rbp = rsp
29.
STACK FRAME STACK FRAME
運作⽅式 - PART 3 ▸ Carving space for local variables ▸ Local variable也存放在stack,由於stack是從⾼高地址往低地 址⽣生長,因此我們sub rsp來來決定需要多少空間 ▸ sub rsp, n_bytes ; n_bytes = local variables需要的空間
30.
STACK FRAME STACK FRAME
運作⽅式 - PART 4 ▸ Stackframe cleanup ▸ 當我們執⾏行行完foo時,foo的stack frame必須正確清除 ▸ mov rsp, rbp ; 將Local variables的空間還原 ▸ pop rbp ; 將當前的stack frame pop掉 ▸ ret ; 返回 ▸ // 有時也會看到leave ▸ // leave = mov rsp, rbp ; pop rbp
31.
實際運作情況
32.
int foo(int a,
int b, int c) { int i, j; … return 1; } int main() { foo(1, 2, 3); return 0; } Compiler foo: push rbp mov rbp, rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 leave ret
33.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP
34.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP RIP
35.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP call foo = push next_rip jmp foo
36.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP call foo = push next_rip jmp foo RETURN ADDRESS
37.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP call foo = push next_rip jmp foo 0X5321AA
38.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP 0X5321AA RIP
39.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP 0X5321AA RIP SAVED RBP
40.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSPRBP 0X5321AA RIP SAVED RBP
41.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP 0X5321AA RIP SAVED RBP LOCAL VARIABLES OF FOO Stackframe of foo
42.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP 0X5321AA RIP SAVED RBP LOCAL VARIABLES OF FOO Stackframe of foo
43.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP 0X5321AA RIP SAVED RBP LOCAL VARIABLES OF FOO
44.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP 0X5321AA RIP SAVED RBP LOCAL VARIABLES OF FOO
45.
foo: push rbp mov rbp,
rsp sub rsp, 0xF … mov rsp, rbp pop rbp ret main: push rbp mov rbp, rsp mov rdi, 0x1 mov rsi, 0x2 mov rdx, 0x3 call foo mov rax, 0 // address = 0x5321aa leave ret STACK FRAME OF MAIN High address Low address RSP RBP 0X5321AA RIP SAVED RBP LOCAL VARIABLES OF FOO
46.
逆向⼯程 觀念、⼯具
47.
逆向⼯程 逆向⼯程 ▸ Reverse Engineering ▸
逆向分析程式、軟體、韌體 ▸ 找出能夠利利⽤用的漏洞洞(Pwn) ▸ 程式碼加密保護 ▸ 程式碼混淆
48.
逆向⼯程 分析程式 ▸ 靜態分析 ▸ strings ▸
strace、ltrace ▸ objdump ▸ 動態分析 ▸ 使⽤用debugger追蹤除錯 ▸ e.g. gdb
49.
逆向⼯程 靜態分析 ▸ $ strings
<file> ▸ 印出檔案中的可視字元 ▸ $ objdump -d <file> ▸ 反組譯檔案,查看組合語⾔言 ▸ $ grep <pattern> ▸ 尋找含有pattern的內容 ▸ 通常可以和strings⼀一起使⽤用 ▸ $ strings <file> | grep “flag”
50.
逆向⼯程 靜態分析 ▸ $ strace
<file> ▸ 查看檔案的system call ▸ $ ltrace <file> ▸ 查看檔案呼叫的library
51.
逆向⼯程 動態分析 ▸ 使⽤用gdb動態追蹤程式脈絡 ▸ b
main ▸ 將中斷點設在main ▸ run ▸ 開始執⾏行行程式 ▸ x/30wx $rsp ▸ 從rsp開始以hex形式往下dump出30個stack內存
52.
逆向⼯程 練習時間 ▸ ⾃自⾏行行撰寫出reverse.c,程式可讓使⽤用者輸入字串串內容 ▸ 使⽤用靜態分析⼯工具來來分析程式 ▸
使⽤用gdb追蹤程式流程,學會觀察內存改變
53.
Q&A
Download now