SlideShare a Scribd company logo
1 of 54
Download to read offline
BINARY TRAIN
- PART I
CMJ / 2017.03.18
OUTLINE
NEXT 45 MIN
▸ In the next 45 min
▸ Learn the Mach-O binary format
▸ X86-64 Assembly Language / Machine Code
▸ Trivial Binary Bugs
▸ Order by DESC
ㄌㄡˋ洞 就在那邊
民明書房
不可不知的⼗⼤名句
BUG TO VULNERABILITY
SIGNAL
▸ There are so~ many SIGNAL in *nix-like system
▸ Some is helpful
▸ Some is bug prevention
▸ Understand the bug will find the vulnerabilities
▸ SIGFPE - devision-by-zero
▸ SIGILL - illegal instruction
▸ SIGSEGV - invalid virtual memory reference
BUG TO VULNERABILITY
SIGNAL
▸ There are so~ many SIGNAL in *nix-like system
▸ Some is helpful
▸ Some is bug prevention
▸ Understand the bug will find the vulnerabilities
▸ SIGFPE - devision-by-zero
▸ SIGILL - illegal instruction
▸ SIGSEGV - invalid virtual memory reference
BUG TO VULNERABILITY
ILLEGAL & INVALID
▸ Caused by compiler, library, logical
▸ Compiler - replace a newer compiler
▸ Run-time library - replace a newer library
▸ Run-time logical - replace a correct input
▸ 都是 They 的錯
BUG TO VULNERABILITY
ILLEGAL & INVALID
▸ Caused by compiler, library, logical
▸ Compiler - replace a newer compiler
▸ Run-time library - replace a newer library
▸ Run-time logical - replace a correct input
▸ 都是 They 的錯
VULNERABILITY
INPUT
▸ User Input
▸ User-Name, Age, email-address, Gender
▸ Store the user input into memory space
▸ ISSUE
A. How
B. What
C. Where
WORLD IN
X64-64
CPU
X86-64
▸ Register - extend to 64-bits
▸ 8 / 16 / 32 / 64 bits
▸ 128 bits (SSE)
▸ NX (No-Execute) bit
▸ Register is limited
▸ limited to 16 general registers
▸ 16 SSE registers
CPU
X86-64
▸ Von Neumann model
▸ Code / Data are put together (memory)
▸ When data need to be stored / loaded
▸ from register to memory
▸ from memory to register
STORAGE
SOMETHING IN MEMORY
▸ Code vs Data vs BSS vs Stack vs Heap
▸ Code is used to read-execute
▸ Data is used to read-write
▸ BSS is used to store Non-Initial data
▸ Stack is used to store template (local) data
▸ Heap is used to store dynamic data
▸ All of these are stored in the memory
HOPE YOU HAVE …
DATA IN PROGRAM
▸ Data
▸ Gender - one letter or full description
▸ Age - possible integer or impossible integer
▸ Name - alphabet or unicode
▸ All data in register / memory are integer-like
▸ 8-bit (0~255) to SSE (0 ~ 3.4e38)
▸ sign or unsigned is a question
HOPE YOU HAVE …
DATA IN PROGRAM
▸ Can simply put age into register
▸ Gender could be
▸ one letter - to ASCII and put in register
▸ Fix-length - store in memory
▸ Name should be
▸ store in memory
MEMORY
WHERE TO STORE
▸ Memory
▸ Sequently store user input
▸ decode by program / programmer
▸ ISSUE
▸ size
▸ permission
MEMORY
WHERE TO STORE
▸ Data vs BSS vs Stack vs Heap stack
▸ Fit the scenario (assumption)
▸ data is
1. temporary
2. global view
3. variable size
綠⾖糕、稿紙
どっち
你或許看過的 - 雅量
DECODE
⽂字
MOV
▸ In x86-64 opcodes
▸ lots of opcodes are MOV
▸ move from/to memory are frequently used actions
▸ mov ch, dl
▸ mov rax, [rax-0x10]
▸ mov [r8], rsp
▸ lea cx, [rbx]
▸ But there are difference opcode!
AGE
SAVE DATA
▸ Save 18 as age into program
▸ mov rax, 18 ; save as register
▸ mov [rax], 18 ; save into memory
▸ push 18 ; save into stack
GENDER
SAVE DATA
▸ Save ‘F’ (0x46) as gender into program
▸ mov rax, 0x46 ; save as register
▸ mov [rax], 0x46 ; save into memory
▸ push 0x46 ; save into stack
GENDER
SAVE DATA
▸ Save ‘Female’ as gender into program
▸ mov [rax], 0x46656D61
▸ mov [rax+0x04], 0x6C650000
▸ push 0x46
▸ push 0x65
▸ push …
MEMORY
SIZE IS MATTER
▸ Step to store data in memory
1. decide the size of memory
2. how to encode/decode data
3. decide the location of memory
4. put into / get from memory
MEMORY
OVERESTIMATE VS UNDERESTIMATE
▸ Over
▸ memory leak - OOM
▸ waste resource
▸ Under
▸ data corrupt
▸ overflow
MEMORY
▸ move to memory space
▸ Where is the space? BSS or Data or Heap
▸ Compile-time or Run-time
▸ fix-length or variable-length
▸ Save into Stack
▸ Push stack is not unlimited
IN C LANGUAGE
ASSUMPTION
▸ Struct in C
struct foo {
int age;
char gender[8];
char email[128];
};
‣ What happen if overflow in gender
‣ email is corrupt / age is corrupt
age
gender
email
0x1230
0x12B9
IN ASM
ASSUMPTION
[0x400000] call 0x400043
…
[0x400043] mov rax 18
[0x400048] ret
IN ASM
ASSUMPTION
[0x400000] call 0x400043
…
[0x400043] push 18
[0x400048] ret
IN ASM
ASSUMPTION
[0x400000] call 0x400043
…
[0x400043] mov [rbp-0x10] 0x46
[0x40004E] ret
IN ASM
ASSUMPTION
[0x400000] call 0x400043
…
[0x400043] mov r8 [rip+0x08]
[0x40004A] mov [r8] 18
[0x400051] ret
LEGACY
CODE/DATA BOTH IN MEMORY
▸ First: call is combined from push and jump
▸ call 0x400035
1. push rip
2. jump 0x400035
‣ ret
1. pop rip
2. jump rip
‣ And more
▸ call rax
▸ call [rax]
LEGACY
PROGRAM ALWAYS HAS BUG
EVEN COMPILER
QUESTION
▸ If vulnerability could be
▸ source code to assembly code
QUESTION
▸ If vulnerability could be
▸ source code to assembly code
▸ NO BUG from assembly code to machine code?
⽂字
ASSEMBLE
▸ From assembly code to machine code
▸ 1-1 mapping
▸ platform-dependent
▸ Example
▸ pop rax - 58
▸ syscall - 0F 05
▸ xor r8 0x10 - 48 83 F0 10
▸ mov eax 0xDEADBEEF - B8 EF BE AD DE
X86-64
OPCODE
INSTRUCTION
X86-64 MACHINE CODE
▸ X86-64 machine code layout
▸ [prefix] [opcode] [MOD] [SIB] [Displacement] [Immediate]
▸ Max to 15-bytes peer each instruction
▸ Displacement + Immediate max to 8-bytes (64-bit address)
▸ R(educed)ISC vs C(omplex)ISC
STFW
OPCODE
▸ X86-64 opcode
▸ Intel Manual[0]
▸ Web Resource[1]
▸ OPCODE possible 00 ~ FF
▸ Each one has possible usage or invalid
[0]: https://software.intel.com/sites/default/files/managed/ad/01/253666-sdm-vol-2a.pdf
[1]: http://ref.x86asm.net/coder64.html
SIMPLE LIFE
OPCODE
▸ Simple (frequently-used) opcode
▸ No-OPeration
▸ NOP 90 (maybe xchg eax, eax)
▸ NOP 0F 0D
▸ FNOP D9 D0 (FPU nop)
[0]: http://stackoverflow.com/questions/25008772/whats-the-difference-between-the-x86-nop-and-fnop-
instructions
X86-64
SLIGHTLY COMPLICATED
▸ Extension OPCODE
▸ add (01) support 16 / 32 / 64 operand
▸ add r/m16/32/64 r16/32/64
▸ One opcode do multiple thing?
▸ prefix 48 ~ 4F extend the size to 64-bit
7 3 2 1 0
+—————————+———+———+———+———+
| 0 1 0 0 | W | R | X | B |
+—————————+———+———+———+———+
X86-64
REGISTER EXTENSION
▸ Extension
▸ Size (32-bits to 64-bits)
▸ register (general to extension)
▸ mov eax, 0xdeadbeef B8 EF BE AD DE
▸ mov rax, 0xdeadbeef 48 B8 EF BE AD DE
▸ mov r8, 0xdeadbeef 49 B8 EF BE AD DE
X86-64
TRICKY
▸ OPCODE
▸ push implies r64
▸ push rax 50
▸ push rax 48 50
X86-64
PRIMARY OPCODE
▸ Some opcode is mixed
▸ OPCODE + second opcode
▸ push r16/64 would be merge with 1-byte
▸ push ax 66 50
▸ push rax 50
▸ push r9w 66 41 51
▸ push r9 41 51
X86-64
TWO-BYTE OPCODE
▸ Some opcode are two-type
▸ ADD 05
▸ syscall 0F 05
▸ Prefix (two-byte) 0F
X86-64
SOME PROBLEM
▸ Trivial case - condition check
▸ jz LABEL 48 0F 84 06 00 00 00
▸ Can be modified as
▸ nop 90 90 90 90 90 90 90
X86-64
SOME PROBLEM
▸ If we have
▸ add ax, 0x5150 66 05 50 51
▸ Can be modified as
▸ syscall 0F 05
▸ push rax 50
▸ push rcx 51
REAL-CASE
- MAC OS X
POSSIBILITY
MACHO
▸ Mach-O is a binary format
▸ Header
▸ Commands
▸ Sections
▸ Segment
▸ Binary payload
▸ Multi-architecture binaries
MACH-O 64
HEADER
▸ Magic Number 0xFEEDFACF
▸ 64-bit
▸ CPU info
▸ X86_64 / ARM / ARM64 / POWERPC64 / …
▸ File Type
▸ Execute / Preload / DYLIB / …
▸ Number of commands (section/segment)
▸ Flags
▸ PIE / NOUNDEFS / DYLDLINK / LAZY_INIT / …
MACH-O 64
COMMANDS
▸ Lots of commands
▸ LC_SEGMENT_64
▸ LC_SYMTAB
▸ LC_LOAD_DYLIB
▸ LC_UNIXTHREAD
▸ LC_MAIN
▸ LC_RPATH
MACH-O 64
SEGMENT
▸ Segment
▸ command name
▸ memory address
▸ memory size
▸ file offset
▸ file size
▸ max VM protection
▸ max initial protection
▸ number of sections
MACH-O 64
SECTION
▸ Section Name
▸ Segment Name
▸ memory address
▸ size
▸ offset
▸ align
▸ flags
MACH-O 64
MINIMAL
▸ Minimal Mach-O 64 binary
▸ Low consumption - 4K
▸ Header
▸ 7 commands - 664 bytes
▸ Machine Code - 12 bytes
▸ Dummy x00
ZASM
ASSEMBLER
▸ Assembler
▸ From assembly language to machine code
▸ Target format (ELF / Mach-O / …)
▸ Target platform (x86-64 / ARMv8 / …)
▸ Generator
[0]: https://github.com/cmj0121/Zerg/tree/master/src/zasm
Q&A
THANKS FOR YOUR ATTENTION

More Related Content

Viewers also liked

Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerMarina Kolpakova
 
Pragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler OptimizationsPragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler OptimizationsMarina Kolpakova
 
Hydrogen production by a thermally integrated ATR based fuel processor
Hydrogen production by a thermally integrated ATR based fuel processorHydrogen production by a thermally integrated ATR based fuel processor
Hydrogen production by a thermally integrated ATR based fuel processorAntonio Ricca
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesMarina Kolpakova
 
Advanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPAdvanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPA B Shinde
 
Pragmatic optimization in modern programming - modern computer architecture c...
Pragmatic optimization in modern programming - modern computer architecture c...Pragmatic optimization in modern programming - modern computer architecture c...
Pragmatic optimization in modern programming - modern computer architecture c...Marina Kolpakova
 
SOC Chip Basics
SOC Chip BasicsSOC Chip Basics
SOC Chip BasicsA B Shinde
 
SOC Interconnects: AMBA & CoreConnect
SOC Interconnects: AMBA  & CoreConnectSOC Interconnects: AMBA  & CoreConnect
SOC Interconnects: AMBA & CoreConnectA B Shinde
 
SOC Processors Used in SOC
SOC Processors Used in SOCSOC Processors Used in SOC
SOC Processors Used in SOCA B Shinde
 
BigchainDB: A Scalable Blockchain Database, In Python
BigchainDB: A Scalable Blockchain Database, In PythonBigchainDB: A Scalable Blockchain Database, In Python
BigchainDB: A Scalable Blockchain Database, In PythonTrent McConaghy
 
SOC System Design Approach
SOC System Design ApproachSOC System Design Approach
SOC System Design ApproachA B Shinde
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetesTed Jung
 
2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficiently2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficientlyBruno Capuano
 
The History and Future of Core Dumps in FreeBSD
The History and Future of Core Dumps in FreeBSDThe History and Future of Core Dumps in FreeBSD
The History and Future of Core Dumps in FreeBSDSam Gwydir
 
ARM based System for Monitoring Grain Condition
ARM based System for Monitoring Grain ConditionARM based System for Monitoring Grain Condition
ARM based System for Monitoring Grain ConditionAM Publications
 
M.E.L.I.G. Unikernel and Serverless
M.E.L.I.G. Unikernel and ServerlessM.E.L.I.G. Unikernel and Serverless
M.E.L.I.G. Unikernel and ServerlessQNIB Solutions
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Patrick Chanezon
 

Viewers also liked (20)

Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
 
Pragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler OptimizationsPragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
 
Hydrogen production by a thermally integrated ATR based fuel processor
Hydrogen production by a thermally integrated ATR based fuel processorHydrogen production by a thermally integrated ATR based fuel processor
Hydrogen production by a thermally integrated ATR based fuel processor
 
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization ApproachesPragmatic Optimization in Modern Programming - Ordering Optimization Approaches
Pragmatic Optimization in Modern Programming - Ordering Optimization Approaches
 
Advanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPAdvanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILP
 
Pragmatic optimization in modern programming - modern computer architecture c...
Pragmatic optimization in modern programming - modern computer architecture c...Pragmatic optimization in modern programming - modern computer architecture c...
Pragmatic optimization in modern programming - modern computer architecture c...
 
SOC Chip Basics
SOC Chip BasicsSOC Chip Basics
SOC Chip Basics
 
Dual-core processor
Dual-core processorDual-core processor
Dual-core processor
 
SOC Interconnects: AMBA & CoreConnect
SOC Interconnects: AMBA  & CoreConnectSOC Interconnects: AMBA  & CoreConnect
SOC Interconnects: AMBA & CoreConnect
 
SOC Processors Used in SOC
SOC Processors Used in SOCSOC Processors Used in SOC
SOC Processors Used in SOC
 
BigchainDB: A Scalable Blockchain Database, In Python
BigchainDB: A Scalable Blockchain Database, In PythonBigchainDB: A Scalable Blockchain Database, In Python
BigchainDB: A Scalable Blockchain Database, In Python
 
Pynq祭り資料
Pynq祭り資料Pynq祭り資料
Pynq祭り資料
 
SOC System Design Approach
SOC System Design ApproachSOC System Design Approach
SOC System Design Approach
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
 
2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficiently2017 03 25 Microsoft Hacks, How to code efficiently
2017 03 25 Microsoft Hacks, How to code efficiently
 
The History and Future of Core Dumps in FreeBSD
The History and Future of Core Dumps in FreeBSDThe History and Future of Core Dumps in FreeBSD
The History and Future of Core Dumps in FreeBSD
 
ARM based System for Monitoring Grain Condition
ARM based System for Monitoring Grain ConditionARM based System for Monitoring Grain Condition
ARM based System for Monitoring Grain Condition
 
M.E.L.I.G. Unikernel and Serverless
M.E.L.I.G. Unikernel and ServerlessM.E.L.I.G. Unikernel and Serverless
M.E.L.I.G. Unikernel and Serverless
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-pi
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
 

Similar to [2017.03.18] hst binary training part 1

21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query execution
21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query execution21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query execution
21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query executionAthens Big Data
 
Configuration and lifecycle in Mixed environments
Configuration and lifecycle in Mixed environmentsConfiguration and lifecycle in Mixed environments
Configuration and lifecycle in Mixed environmentsDmitry Kireev
 
Install power linux through cdrom and network redhat and suse
Install power linux through cdrom and network   redhat and suseInstall power linux through cdrom and network   redhat and suse
Install power linux through cdrom and network redhat and susezhangjunli
 
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them allDEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them allFelipe Prado
 
Webinar: Strength in Numbers: Introduction to ClickHouse Cluster Performance
Webinar: Strength in Numbers: Introduction to ClickHouse Cluster PerformanceWebinar: Strength in Numbers: Introduction to ClickHouse Cluster Performance
Webinar: Strength in Numbers: Introduction to ClickHouse Cluster PerformanceAltinity Ltd
 
Node, can you even in CPU intensive operations?
Node, can you even in CPU intensive operations?Node, can you even in CPU intensive operations?
Node, can you even in CPU intensive operations?The Software House
 
Lecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfLecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfssuser02936f
 
Basic stuff You Need to Know about Cassandra
Basic stuff You Need to Know about CassandraBasic stuff You Need to Know about Cassandra
Basic stuff You Need to Know about CassandraYu-Chang Ho
 
High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018Zahari Dichev
 
Linux memory-management-kamal
Linux memory-management-kamalLinux memory-management-kamal
Linux memory-management-kamalKamal Maiti
 
Gdc03 ericson memory_optimization
Gdc03 ericson memory_optimizationGdc03 ericson memory_optimization
Gdc03 ericson memory_optimizationbrettlevin
 
How the antiviruses work
How the antiviruses workHow the antiviruses work
How the antiviruses workDawid Golak
 
Php memory-redux
Php memory-reduxPhp memory-redux
Php memory-reduxnanderoo
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialWim Godden
 
Cryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 WorkshopCryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 WorkshopMark Niebergall
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12Tim Bunce
 
資工也該懂些資安吧
資工也該懂些資安吧資工也該懂些資安吧
資工也該懂些資安吧明旋 簡
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawnGábor Nyers
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Community
 

Similar to [2017.03.18] hst binary training part 1 (20)

21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query execution
21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query execution21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query execution
21st Athens Big Data Meetup - 3rd Talk - Dive into ClickHouse query execution
 
Configuration and lifecycle in Mixed environments
Configuration and lifecycle in Mixed environmentsConfiguration and lifecycle in Mixed environments
Configuration and lifecycle in Mixed environments
 
Install power linux through cdrom and network redhat and suse
Install power linux through cdrom and network   redhat and suseInstall power linux through cdrom and network   redhat and suse
Install power linux through cdrom and network redhat and suse
 
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them allDEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
DEF CON 27- ITZIK KOTLER and AMIT KLEIN - gotta catch them all
 
Webinar: Strength in Numbers: Introduction to ClickHouse Cluster Performance
Webinar: Strength in Numbers: Introduction to ClickHouse Cluster PerformanceWebinar: Strength in Numbers: Introduction to ClickHouse Cluster Performance
Webinar: Strength in Numbers: Introduction to ClickHouse Cluster Performance
 
Node, can you even in CPU intensive operations?
Node, can you even in CPU intensive operations?Node, can you even in CPU intensive operations?
Node, can you even in CPU intensive operations?
 
Lecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfLecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdf
 
Basic stuff You Need to Know about Cassandra
Basic stuff You Need to Know about CassandraBasic stuff You Need to Know about Cassandra
Basic stuff You Need to Know about Cassandra
 
High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018
 
Linux memory-management-kamal
Linux memory-management-kamalLinux memory-management-kamal
Linux memory-management-kamal
 
Gdc03 ericson memory_optimization
Gdc03 ericson memory_optimizationGdc03 ericson memory_optimization
Gdc03 ericson memory_optimization
 
How the antiviruses work
How the antiviruses workHow the antiviruses work
How the antiviruses work
 
To AWS with Ansible
To AWS with AnsibleTo AWS with Ansible
To AWS with Ansible
 
Php memory-redux
Php memory-reduxPhp memory-redux
Php memory-redux
 
phptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorialphptek13 - Caching and tuning fun tutorial
phptek13 - Caching and tuning fun tutorial
 
Cryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 WorkshopCryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 Workshop
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12
 
資工也該懂些資安吧
資工也該懂些資安吧資工也該懂些資安吧
資工也該懂些資安吧
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawn
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph
 

More from Chia-Hao Tsai

[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001Chia-Hao Tsai
 
[2019.02.16] hst - orm
[2019.02.16] hst  - orm[2019.02.16] hst  - orm
[2019.02.16] hst - ormChia-Hao Tsai
 
[2019.01.12] hst iptables 101 to 301
[2019.01.12] hst   iptables 101 to 301[2019.01.12] hst   iptables 101 to 301
[2019.01.12] hst iptables 101 to 301Chia-Hao Tsai
 
[2018.12.15] hst python object 102
[2018.12.15] hst   python object 102[2018.12.15] hst   python object 102
[2018.12.15] hst python object 102Chia-Hao Tsai
 
[2018.11.16] Python Object 101
[2018.11.16]  Python Object 101[2018.11.16]  Python Object 101
[2018.11.16] Python Object 101Chia-Hao Tsai
 
Rootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitRootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitChia-Hao Tsai
 
Rootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionRootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionChia-Hao Tsai
 
Learn Python in 30 min - 4
Learn Python in 30 min - 4Learn Python in 30 min - 4
Learn Python in 30 min - 4Chia-Hao Tsai
 
Learn python in 30 min - 3
Learn python in 30 min - 3Learn python in 30 min - 3
Learn python in 30 min - 3Chia-Hao Tsai
 
Learn python 2 - Real World Case
Learn python 2 - Real World CaseLearn python 2 - Real World Case
Learn python 2 - Real World CaseChia-Hao Tsai
 
Passwd crack introduction
Passwd crack   introductionPasswd crack   introduction
Passwd crack introductionChia-Hao Tsai
 
Security coding c and c++ ch8(2)
Security coding c and c++   ch8(2)Security coding c and c++   ch8(2)
Security coding c and c++ ch8(2)Chia-Hao Tsai
 
Security coding c and c++ ch8 (1)
Security coding c and c++   ch8 (1)Security coding c and c++   ch8 (1)
Security coding c and c++ ch8 (1)Chia-Hao Tsai
 

More from Chia-Hao Tsai (19)

[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001
 
[2019.02.16] hst - orm
[2019.02.16] hst  - orm[2019.02.16] hst  - orm
[2019.02.16] hst - orm
 
[2019.01.12] hst iptables 101 to 301
[2019.01.12] hst   iptables 101 to 301[2019.01.12] hst   iptables 101 to 301
[2019.01.12] hst iptables 101 to 301
 
[2018.12.15] hst python object 102
[2018.12.15] hst   python object 102[2018.12.15] hst   python object 102
[2018.12.15] hst python object 102
 
[2018.11.16] Python Object 101
[2018.11.16]  Python Object 101[2018.11.16]  Python Object 101
[2018.11.16] Python Object 101
 
Rootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitRootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based Rootkit
 
Rootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionRootkit 101 - 2nd Edition
Rootkit 101 - 2nd Edition
 
ELF 101
ELF 101ELF 101
ELF 101
 
Maker - WiFi AP
Maker - WiFi APMaker - WiFi AP
Maker - WiFi AP
 
Learn Python in 30 min - 4
Learn Python in 30 min - 4Learn Python in 30 min - 4
Learn Python in 30 min - 4
 
Learn python in 30 min - 3
Learn python in 30 min - 3Learn python in 30 min - 3
Learn python in 30 min - 3
 
Learn python 2 - Real World Case
Learn python 2 - Real World CaseLearn python 2 - Real World Case
Learn python 2 - Real World Case
 
Learn python 1
Learn python 1Learn python 1
Learn python 1
 
HoneyCon 2014
HoneyCon 2014HoneyCon 2014
HoneyCon 2014
 
Passwd crack introduction
Passwd crack   introductionPasswd crack   introduction
Passwd crack introduction
 
Security coding c and c++ ch8(2)
Security coding c and c++   ch8(2)Security coding c and c++   ch8(2)
Security coding c and c++ ch8(2)
 
Security coding c and c++ ch8 (1)
Security coding c and c++   ch8 (1)Security coding c and c++   ch8 (1)
Security coding c and c++ ch8 (1)
 
Build web server
Build web serverBuild web server
Build web server
 
Rootkit tw(0224)
Rootkit tw(0224)Rootkit tw(0224)
Rootkit tw(0224)
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 

Recently uploaded (20)

The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 

[2017.03.18] hst binary training part 1

  • 1. BINARY TRAIN - PART I CMJ / 2017.03.18
  • 2. OUTLINE NEXT 45 MIN ▸ In the next 45 min ▸ Learn the Mach-O binary format ▸ X86-64 Assembly Language / Machine Code ▸ Trivial Binary Bugs ▸ Order by DESC
  • 4. BUG TO VULNERABILITY SIGNAL ▸ There are so~ many SIGNAL in *nix-like system ▸ Some is helpful ▸ Some is bug prevention ▸ Understand the bug will find the vulnerabilities ▸ SIGFPE - devision-by-zero ▸ SIGILL - illegal instruction ▸ SIGSEGV - invalid virtual memory reference
  • 5. BUG TO VULNERABILITY SIGNAL ▸ There are so~ many SIGNAL in *nix-like system ▸ Some is helpful ▸ Some is bug prevention ▸ Understand the bug will find the vulnerabilities ▸ SIGFPE - devision-by-zero ▸ SIGILL - illegal instruction ▸ SIGSEGV - invalid virtual memory reference
  • 6. BUG TO VULNERABILITY ILLEGAL & INVALID ▸ Caused by compiler, library, logical ▸ Compiler - replace a newer compiler ▸ Run-time library - replace a newer library ▸ Run-time logical - replace a correct input ▸ 都是 They 的錯
  • 7. BUG TO VULNERABILITY ILLEGAL & INVALID ▸ Caused by compiler, library, logical ▸ Compiler - replace a newer compiler ▸ Run-time library - replace a newer library ▸ Run-time logical - replace a correct input ▸ 都是 They 的錯
  • 8. VULNERABILITY INPUT ▸ User Input ▸ User-Name, Age, email-address, Gender ▸ Store the user input into memory space ▸ ISSUE A. How B. What C. Where
  • 10. CPU X86-64 ▸ Register - extend to 64-bits ▸ 8 / 16 / 32 / 64 bits ▸ 128 bits (SSE) ▸ NX (No-Execute) bit ▸ Register is limited ▸ limited to 16 general registers ▸ 16 SSE registers
  • 11. CPU X86-64 ▸ Von Neumann model ▸ Code / Data are put together (memory) ▸ When data need to be stored / loaded ▸ from register to memory ▸ from memory to register
  • 12. STORAGE SOMETHING IN MEMORY ▸ Code vs Data vs BSS vs Stack vs Heap ▸ Code is used to read-execute ▸ Data is used to read-write ▸ BSS is used to store Non-Initial data ▸ Stack is used to store template (local) data ▸ Heap is used to store dynamic data ▸ All of these are stored in the memory
  • 13. HOPE YOU HAVE … DATA IN PROGRAM ▸ Data ▸ Gender - one letter or full description ▸ Age - possible integer or impossible integer ▸ Name - alphabet or unicode ▸ All data in register / memory are integer-like ▸ 8-bit (0~255) to SSE (0 ~ 3.4e38) ▸ sign or unsigned is a question
  • 14. HOPE YOU HAVE … DATA IN PROGRAM ▸ Can simply put age into register ▸ Gender could be ▸ one letter - to ASCII and put in register ▸ Fix-length - store in memory ▸ Name should be ▸ store in memory
  • 15. MEMORY WHERE TO STORE ▸ Memory ▸ Sequently store user input ▸ decode by program / programmer ▸ ISSUE ▸ size ▸ permission
  • 16. MEMORY WHERE TO STORE ▸ Data vs BSS vs Stack vs Heap stack ▸ Fit the scenario (assumption) ▸ data is 1. temporary 2. global view 3. variable size
  • 18. ⽂字 MOV ▸ In x86-64 opcodes ▸ lots of opcodes are MOV ▸ move from/to memory are frequently used actions ▸ mov ch, dl ▸ mov rax, [rax-0x10] ▸ mov [r8], rsp ▸ lea cx, [rbx] ▸ But there are difference opcode!
  • 19. AGE SAVE DATA ▸ Save 18 as age into program ▸ mov rax, 18 ; save as register ▸ mov [rax], 18 ; save into memory ▸ push 18 ; save into stack
  • 20. GENDER SAVE DATA ▸ Save ‘F’ (0x46) as gender into program ▸ mov rax, 0x46 ; save as register ▸ mov [rax], 0x46 ; save into memory ▸ push 0x46 ; save into stack
  • 21. GENDER SAVE DATA ▸ Save ‘Female’ as gender into program ▸ mov [rax], 0x46656D61 ▸ mov [rax+0x04], 0x6C650000 ▸ push 0x46 ▸ push 0x65 ▸ push …
  • 22. MEMORY SIZE IS MATTER ▸ Step to store data in memory 1. decide the size of memory 2. how to encode/decode data 3. decide the location of memory 4. put into / get from memory
  • 23. MEMORY OVERESTIMATE VS UNDERESTIMATE ▸ Over ▸ memory leak - OOM ▸ waste resource ▸ Under ▸ data corrupt ▸ overflow
  • 24. MEMORY ▸ move to memory space ▸ Where is the space? BSS or Data or Heap ▸ Compile-time or Run-time ▸ fix-length or variable-length ▸ Save into Stack ▸ Push stack is not unlimited
  • 25. IN C LANGUAGE ASSUMPTION ▸ Struct in C struct foo { int age; char gender[8]; char email[128]; }; ‣ What happen if overflow in gender ‣ email is corrupt / age is corrupt age gender email 0x1230 0x12B9
  • 26. IN ASM ASSUMPTION [0x400000] call 0x400043 … [0x400043] mov rax 18 [0x400048] ret
  • 27. IN ASM ASSUMPTION [0x400000] call 0x400043 … [0x400043] push 18 [0x400048] ret
  • 28. IN ASM ASSUMPTION [0x400000] call 0x400043 … [0x400043] mov [rbp-0x10] 0x46 [0x40004E] ret
  • 29. IN ASM ASSUMPTION [0x400000] call 0x400043 … [0x400043] mov r8 [rip+0x08] [0x40004A] mov [r8] 18 [0x400051] ret
  • 30. LEGACY CODE/DATA BOTH IN MEMORY ▸ First: call is combined from push and jump ▸ call 0x400035 1. push rip 2. jump 0x400035 ‣ ret 1. pop rip 2. jump rip ‣ And more ▸ call rax ▸ call [rax]
  • 31. LEGACY PROGRAM ALWAYS HAS BUG EVEN COMPILER
  • 32. QUESTION ▸ If vulnerability could be ▸ source code to assembly code
  • 33. QUESTION ▸ If vulnerability could be ▸ source code to assembly code ▸ NO BUG from assembly code to machine code?
  • 34. ⽂字 ASSEMBLE ▸ From assembly code to machine code ▸ 1-1 mapping ▸ platform-dependent ▸ Example ▸ pop rax - 58 ▸ syscall - 0F 05 ▸ xor r8 0x10 - 48 83 F0 10 ▸ mov eax 0xDEADBEEF - B8 EF BE AD DE
  • 36. INSTRUCTION X86-64 MACHINE CODE ▸ X86-64 machine code layout ▸ [prefix] [opcode] [MOD] [SIB] [Displacement] [Immediate] ▸ Max to 15-bytes peer each instruction ▸ Displacement + Immediate max to 8-bytes (64-bit address) ▸ R(educed)ISC vs C(omplex)ISC
  • 37. STFW OPCODE ▸ X86-64 opcode ▸ Intel Manual[0] ▸ Web Resource[1] ▸ OPCODE possible 00 ~ FF ▸ Each one has possible usage or invalid [0]: https://software.intel.com/sites/default/files/managed/ad/01/253666-sdm-vol-2a.pdf [1]: http://ref.x86asm.net/coder64.html
  • 38. SIMPLE LIFE OPCODE ▸ Simple (frequently-used) opcode ▸ No-OPeration ▸ NOP 90 (maybe xchg eax, eax) ▸ NOP 0F 0D ▸ FNOP D9 D0 (FPU nop) [0]: http://stackoverflow.com/questions/25008772/whats-the-difference-between-the-x86-nop-and-fnop- instructions
  • 39. X86-64 SLIGHTLY COMPLICATED ▸ Extension OPCODE ▸ add (01) support 16 / 32 / 64 operand ▸ add r/m16/32/64 r16/32/64 ▸ One opcode do multiple thing? ▸ prefix 48 ~ 4F extend the size to 64-bit 7 3 2 1 0 +—————————+———+———+———+———+ | 0 1 0 0 | W | R | X | B | +—————————+———+———+———+———+
  • 40. X86-64 REGISTER EXTENSION ▸ Extension ▸ Size (32-bits to 64-bits) ▸ register (general to extension) ▸ mov eax, 0xdeadbeef B8 EF BE AD DE ▸ mov rax, 0xdeadbeef 48 B8 EF BE AD DE ▸ mov r8, 0xdeadbeef 49 B8 EF BE AD DE
  • 41. X86-64 TRICKY ▸ OPCODE ▸ push implies r64 ▸ push rax 50 ▸ push rax 48 50
  • 42. X86-64 PRIMARY OPCODE ▸ Some opcode is mixed ▸ OPCODE + second opcode ▸ push r16/64 would be merge with 1-byte ▸ push ax 66 50 ▸ push rax 50 ▸ push r9w 66 41 51 ▸ push r9 41 51
  • 43. X86-64 TWO-BYTE OPCODE ▸ Some opcode are two-type ▸ ADD 05 ▸ syscall 0F 05 ▸ Prefix (two-byte) 0F
  • 44. X86-64 SOME PROBLEM ▸ Trivial case - condition check ▸ jz LABEL 48 0F 84 06 00 00 00 ▸ Can be modified as ▸ nop 90 90 90 90 90 90 90
  • 45. X86-64 SOME PROBLEM ▸ If we have ▸ add ax, 0x5150 66 05 50 51 ▸ Can be modified as ▸ syscall 0F 05 ▸ push rax 50 ▸ push rcx 51
  • 47. POSSIBILITY MACHO ▸ Mach-O is a binary format ▸ Header ▸ Commands ▸ Sections ▸ Segment ▸ Binary payload ▸ Multi-architecture binaries
  • 48. MACH-O 64 HEADER ▸ Magic Number 0xFEEDFACF ▸ 64-bit ▸ CPU info ▸ X86_64 / ARM / ARM64 / POWERPC64 / … ▸ File Type ▸ Execute / Preload / DYLIB / … ▸ Number of commands (section/segment) ▸ Flags ▸ PIE / NOUNDEFS / DYLDLINK / LAZY_INIT / …
  • 49. MACH-O 64 COMMANDS ▸ Lots of commands ▸ LC_SEGMENT_64 ▸ LC_SYMTAB ▸ LC_LOAD_DYLIB ▸ LC_UNIXTHREAD ▸ LC_MAIN ▸ LC_RPATH
  • 50. MACH-O 64 SEGMENT ▸ Segment ▸ command name ▸ memory address ▸ memory size ▸ file offset ▸ file size ▸ max VM protection ▸ max initial protection ▸ number of sections
  • 51. MACH-O 64 SECTION ▸ Section Name ▸ Segment Name ▸ memory address ▸ size ▸ offset ▸ align ▸ flags
  • 52. MACH-O 64 MINIMAL ▸ Minimal Mach-O 64 binary ▸ Low consumption - 4K ▸ Header ▸ 7 commands - 664 bytes ▸ Machine Code - 12 bytes ▸ Dummy x00
  • 53. ZASM ASSEMBLER ▸ Assembler ▸ From assembly language to machine code ▸ Target format (ELF / Mach-O / …) ▸ Target platform (x86-64 / ARMv8 / …) ▸ Generator [0]: https://github.com/cmj0121/Zerg/tree/master/src/zasm
  • 54. Q&A THANKS FOR YOUR ATTENTION