SlideShare a Scribd company logo
1 of 21
組合語言
REDHUNG @ TDOH-資安功德院
WHO AM I
WHO AM I
▸ 陳靖汯 a.k.a Redhung
▸ 國立中正大學資工/資管系
▸ jasphi168@gmail.com
▸ 興趣:CTF、逆向
▸ 配偶:橋本環奈
指令集
RISC、CISC
指令集
RISC
▸精簡指令集(Reduced Instruction Set Computing)
▸指令系統簡單、精簡
▸指令數目小於100條
▸ARM架構使用RISC指令集
指令集
CISC
▸複雜指令集(Complex Instruction Set Computing)
▸指令系統複雜、龐大
▸指令數目大於200條
▸X86架構使用CISC指令集
ARM &
X86
CPU架構
CPU架構
ARM
▸最早為Acorn公司所開始發展
▸功能相對X86較為簡單
▸耗電量明顯更低
▸因此設計路線與X86為不同方向
▸ARM專注於低成本、低耗能的研發方向
CPU架構
X86
▸最早為Intel公司發展出的「Intel8086」CPU
▸其後系列CPU結尾皆為86,因此其架構被稱為X86
▸功能相較ARM較為強大
▸X86專注於效能、速度的開發
▸普遍PC都是使用Intel的CPU
▸因此CTF與實戰上通常遇到的都是X86架構
組合語言
X86架構
X86架構-組合語言
組合語言
▸Assembly language(Assembly code)為低階語言
▸Human readable,易讀
▸Machine code <——> Assembly code
▸Assembler:ASM —> 01
▸Disassembler:01 —> ASM
▸00000111110000001000001101001000 —> mov rax, 7
▸CPU指令:mov, add, sub, push, pop, etc.
▸X64 assembly、X86 assembly
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
X86架構-組合語言
暫存器 REGISTER
▸索引暫存器:
▸RSI, RDI —> 64bits
▸ESI, EDI —> 32bits
▸SI, DI —> 16bits
▸RSI:來源索引暫存器
▸RDI:目的索引暫存器
RSI ESI SI
X86架構-組合語言
暫存器 REGISTER
▸ RSP, ESP
▸ 指向堆疊(Stack)的最頂端
▸ RBP, EBP
▸ 指向堆疊(Stack)的最尾端
▸ RSP, ESP
▸ 指向程式當前執行的位址
FUNCTION()
ARGUMENT
RETURN ADDRESS
SAVED RBP
RS
P
RB
P
High address
Low address
X86架構-組合語言
X64 ASSEMBLY
▸mov
▸add, sub
▸and, or, xor
▸push, pop
▸call, jmp
▸leave, ret
打字來輸入說明。
X86架構-組合語言
MOV
▸mov 目的, 來源
▸將來源資料複製到目的
▸mov rax, 5 —> rax = 5
▸mov rax, rbx —> rax = rbx 的值
▸mov [rax], 0x123 —> 將0x123儲存至rax指向的內容地址
X86架構-組合語言
ADD, SUB
▸add 目的, 來源
▸add rax, rbx —> rax = rax + rbx
▸sub 目的, 來源
▸sub rax, rbx —> rax = rax - rbx
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
X86架構-組合語言
CALL, JMP
▸jmp 地址
▸跳至程式某一地址執行
▸call 地址
▸先儲存執行完function後要回來的下一行程式碼的地址
▸呼叫指定地址的function
X86架構-組合語言
LEAVE, RET
▸leave
▸還原上一層Stack frame
▸mov rsp, rbp
▸pop rbp
▸ret
▸funtion結束後返回
▸ret = pop rip
X86架構-組合語言
堆疊 STACK, PUSH, POP
▸Data structure
▸Memory section
▸LIFO(Last In First Out)
▸push 來源
▸將來源資料放入堆疊記憶體
▸push rax = sub rsp, 8; mov [rsp], rax
▸pop 目的
▸從堆疊記憶體取出資料放入目的
▸pop rax = mov rax, [rsp]; add rsp, 8
打字來輸入說明。
Low address
High address
flag{Th_4_nks}

More Related Content

More from 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 EmulatorWindows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator
Windows Offender_ Reverse Engineering Windows Defender's Antivirus Emulator
 
AEG_ Automatic Exploit Generation
AEG_ Automatic Exploit GenerationAEG_ Automatic Exploit Generation
AEG_ Automatic Exploit Generation
 
Unleashing MAYHEM On Binary Code
Unleashing MAYHEM On Binary CodeUnleashing MAYHEM On Binary Code
Unleashing MAYHEM On Binary Code
 
Firmadyne
FirmadyneFirmadyne
Firmadyne
 
Fintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJSFintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJS
 
TA-java-method-109
TA-java-method-109TA-java-method-109
TA-java-method-109
 
TA Lesson Web-109
TA Lesson Web-109TA Lesson Web-109
TA Lesson Web-109
 
TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)
 
Java - TA課 - Array
Java - TA課 - ArrayJava - TA課 - Array
Java - TA課 - Array
 
Reverse Engineering - Assembly & Introduction
Reverse Engineering - Assembly & IntroductionReverse Engineering - Assembly & Introduction
Reverse Engineering - Assembly & Introduction
 
TA Lesson3 - Method
TA Lesson3 - MethodTA Lesson3 - Method
TA Lesson3 - Method
 
Web Introduction
Web IntroductionWeb Introduction
Web Introduction
 
Java - TA課 - Let's Begin
Java - TA課 - Let's BeginJava - TA課 - Let's Begin
Java - TA課 - Let's Begin
 
Java - TA課 - 開發環境
Java - TA課 - 開發環境Java - TA課 - 開發環境
Java - TA課 - 開發環境
 
IoT Penetration Talk
IoT Penetration TalkIoT Penetration Talk
IoT Penetration Talk
 
Introduction to computer network
Introduction to computer networkIntroduction to computer network
Introduction to computer network
 
TP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attackTP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attack
 
滲透測試入門 Penetration test - white hat hacking introduction
 滲透測試入門 Penetration test - white hat hacking introduction 滲透測試入門 Penetration test - white hat hacking introduction
滲透測試入門 Penetration test - white hat hacking introduction
 

Assembly Language Redhung ( x86 ) @ TDOH