Professional Documents
Culture Documents
Recon22 Next Gen LyqHkvB
Recon22 Next Gen LyqHkvB
• Tim Blazytko
• co-founder of emproof
• trainer
• Moritz Schloegel
1
Setting the Scene
ARROW-RIGHT Next-Gen
2
Motivation
• intellectual property
• malicious payloads
• Digital Rights Management
3
Virtualization-based Obfuscation
Virtual Machines
__secret_ip:
mov edx, eax
add edx, ebx
mov eax, ebx
mov ebx, edx
loop __secret_ip
4
Virtual Machines
__secret_ip:
mov edx, eax
add edx, ebx
mov eax, ebx
mov ebx, edx
loop __secret_ip
4
Virtual Machines
__secret_ip:
mov edx, eax
add edx, ebx
mov eax, ebx
mov ebx, edx
loop __secret_ip
4
Virtual Machines
➟
vpop r1 vldi #1
add edx, ebx vld r2 vld r3
mov eax, ebx vld r1 vsub r3
vadd r1 vld #0
mov ebx, edx vld r2 veq r3
loop __secret_ip vpop r0 vbr0 #-0E
4
Virtual Machines
__secret_ip: __bytecode:
push __bytecode db 54 68 69 73 20 64 6f
➟
db 65 73 6e 27 74 20 6c
call vm_entry db 6f 6f 6b 20 6c 69 6b
db 65 20 61 6e 79 74 68
db 69 6e 67 20 74 6f 20
db 6d 65 2e de ad be ef
4
Virtual Machines
__secret_ip: __bytecode:
push __bytecode db 54 68 69 73 20 64 6f
➟
db 65 73 6e 27 74 20 6c
call vm_entry db 6f 6f 6b 20 6c 69 6b
db 65 20 61 6e 79 74 68
db 69 6e 67 20 74 6f 20
ret
4
Virtual Machines
Core Components
VM Entry/Exit Context Switch: native context ⇔ virtual context
VM Dispatcher Fetch–Decode–Execute loop
Handler Table Individual VM ISA instruction semantics
5
Virtual Machines
Core Components
VM Entry/Exit Context Switch: native context ⇔ virtual context
VM Dispatcher Fetch–Decode–Execute loop
Handler Table Individual VM ISA instruction semantics
5
Virtual Machines
Core Components
VM Entry/Exit Context Switch: native context ⇔ virtual context
VM Dispatcher Fetch–Decode–Execute loop
Handler Table Individual VM ISA instruction semantics
5
Virtual Machines
6
Virtual Machines
handle_vpush
handle_vpush
}
handle_vadd
handle_vadd
handle_vxor
handle_vxor
handle_vexit
handle_vexit
handle_vpop
handle_vpop
…
VM Entry
}
look up
6
Virtual Machines
__vm_dispatcher:
mov bl, [rsi]
inc rsi
movzx rax, bl
jmp __handler_table[rax * 8]
VM Dispatcher
7
Virtual Machines
__handle_vnor:
__vm_dispatcher: mov rcx, [rbp]
mov bl, [rsi] mov rbx, [rbp + 4]
inc rsi not rcx
movzx rax, bl not rbx
jmp __handler_table[rax * 8] and rcx, rbx
mov [rbp + 4], rcx
pushf
VM Dispatcher pop [rbp]
jmp __vm_dispatcher
7
Breaking Virtual Machine Obfuscation I
8
Breaking Virtual Machine Obfuscation I
1. understand VM architecture/context
8
Writing a VM Disassembler
9
Writing a VM Disassembler
0a 01 02 0b 01 05
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add r1
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add r1, r2
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add r1, r2
mul
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add r1, r2
mul r1
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add r1, r2
mul r1, r5
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add r1, r2
mul r1, r5
9
Writing a VM Disassembler
0a 01 02 0b 01 05
add r1, r2
mul r1, r5
9
Virtual Machine Hardening
Virtual Machines
11
Virtual Machines
11
Virtual Machines
12
Virtual Machines
12
handle_vpush
handle_vadd
handle_vnor
handle_vpop
handle_vpush
handle_vadd
handle_vpush
handle_vnor''
➟
handle_vadd
handle_vpop
handle_vnor
handle_vadd'
handle_vpop
handle_vnor
handle_vnor'
handle_vadd''
Virtual Machines
14
FDE
handle_vnor handle_…
handle_vnor handle_…
FDE FDE
Virtual Machines
17
Virtual Machines
Goal: Hide location of handlers that have not been executed yet.
17
Virtual Machines
Goal: Hide location of handlers that have not been executed yet.
17
Virtual Machines
Goal: Hide location of handlers that have not been executed yet.
17
Virtual Machines
19
Virtual Machines
19
operand ← [vIP + 0]
vIP ← vIP + 8
jmp next_handler
20
operand ← [vIP + 0]
vIP ← vIP + 8
jmp next_handler
20
Breaking Virtual Machine Obfuscation II
1 https://synthesis.to/2021/10/21/vm_based_obfuscation.html
21
Automated Attacks on VMs
Instruction Removal
Compiler Optimizations
23
Compiler Optimizations
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
mov eax, 0x5678
×
add eax, 0x1111
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
mov eax, 0x5678
Dead Code
×
0x1111Elimination
add eax,
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
mov eax, 0x5678
×
add eax, 0x1111
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
mov eax, 0x5678
×
add eax, 0x1111
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
×
mov eax, 0x6789
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
Constant Folding
×
mov eax, 0x6789
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
×
mov eax, 0x6789
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
×
mov eax, 0x6789
×
mov edx, eax
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
×
×
×
mov edx, 0x6789
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
Constant Propagation
×
×
×
mov edx, 0x6789
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
×
×
×
mov edx, 0x6789
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
push eax
×
×
×
×
mov edx, 0x6789
pop eax
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
×
×
×
×
×
mov edx, 0x6789
×
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
not eax
×
×
×
×
×
mov edx, 0x6789
×
not eax
ret
23
Compiler Optimizations
×
mov eax, 0x1234
×
×
×
×
×
×
mov edx, 0x6789
×
×
ret
23
Compiler Optimizations
×
mov eax, 0x1234
×
×
×
Peephole Optimization
×
×
×
mov edx, 0x6789
×
×
ret
23
Compiler Optimizations
×
mov eax, 0x1234
×
×
×
×
×
×
mov edx, 0x6789
×
×
ret
23
Decoding
Blinding
Semantics
Dispatcher
Symbolic Execution
Symbolic Execution: A Syntactic Approach
__handle_vnor:
mov rcx, [rbp]
mov rbx, [rbp + 4]
not rcx
not rbx
and rcx, rbx
mov [rbp + 4], rcx
pushf
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
• mov rcx, [rbp]
mov rbx, [rbp + 4]
not rcx
not rbx
and rcx, rbx
mov [rbp + 4], rcx
pushf
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
• mov rbx, [rbp + 4]
not rcx
not rbx
and rcx, rbx
mov [rbp + 4], rcx
pushf
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
• not rcx
not rbx
and rcx, rbx
mov [rbp + 4], rcx
pushf
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
• not rbx
and rcx, rbx
mov [rbp + 4], rcx
pushf
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
not rbx rcx ← rcx ∧ rbx
• and rcx, rbx = (¬ [rbp]) ∧ (¬ [rbp + 4])
mov [rbp + 4], rcx
pushf
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
not rbx rcx ← rcx ∧ rbx
• and rcx, rbx = (¬ [rbp]) ∧ (¬ [rbp + 4])
mov [rbp + 4], rcx = [rbp] ↓ [rbp + 4]
pushf
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
not rbx rcx ← rcx ∧ rbx
and rcx, rbx = (¬ [rbp]) ∧ (¬ [rbp + 4])
• mov [rbp + 4], rcx = [rbp] ↓ [rbp + 4]
pushf [rbp + 4] ← rcx = [rbp] ↓ [rbp + 4]
pop [rbp]
jmp __vm_dispatcher
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
not rbx rcx ← rcx ∧ rbx
and rcx, rbx = (¬ [rbp]) ∧ (¬ [rbp + 4])
mov [rbp + 4], rcx = [rbp] ↓ [rbp + 4]
• pushf [rbp + 4] ← rcx = [rbp] ↓ [rbp + 4]
pop [rbp]
jmp __vm_dispatcher
rsp ← rsp − 4
[rsp] ← flags
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
not rbx rcx ← rcx ∧ rbx
and rcx, rbx = (¬ [rbp]) ∧ (¬ [rbp + 4])
mov [rbp + 4], rcx = [rbp] ↓ [rbp + 4]
pushf [rbp + 4] ← rcx = [rbp] ↓ [rbp + 4]
• pop [rbp]
jmp __vm_dispatcher
rsp ← rsp − 4
[rsp] ← flags
[rbp] ← [rsp] = flags
Handler performing nor
rsp ← rsp + 4
(with flag side-effects)
27
Symbolic Execution: A Syntactic Approach
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
not rbx rcx ← rcx ∧ rbx
and rcx, rbx = (¬ [rbp]) ∧ (¬ [rbp + 4])
mov [rbp + 4], rcx = [rbp] ↓ [rbp + 4]
pushf [rbp + 4] ← rcx = [rbp] ↓ [rbp + 4]
pop [rbp]
• jmp __vm_dispatcher
rsp ← rsp − 4
[rsp] ← flags
[rbp] ← [rsp] = flags
Handler performing nor
rsp ← rsp + 4
(with flag side-effects)
27
Symbolic Execution: A Syntactic Approach
rcx ← [rbp]
__handle_vnor:
rbx ← [rbp + 4]
mov rcx, [rbp]
rcx ← ¬ rcx = ¬ [rbp]
mov rbx, [rbp + 4]
not rcx rbx ← ¬ rbx = ¬ [rbp + 4]
not rbx rcx ← rcx ∧ rbx
We use f as a black-box:
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
(1,1,1)
? 3
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
(1, 1, 1) → 3
(1,1,1)
? 3
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
(1, 1, 1) → 3
(2,3,1)
? 6
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
(1, 1, 1) → 3
(2,3,1)
? 6 (2, 3, 1) → 6
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
(1, 1, 1) → 3
(0,7,2)
? 9 (2, 3, 1) → 6
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
(1, 1, 1) → 3
(0,7,2)
? 9 (2, 3, 1) → 6
(0, 7, 2) → 9
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
(1, 1, 1) → 3
(2, 3, 1) → 6
(0, 7, 2) → 9
29
Program Synthesis: A Semantic Approach
We use f as a black-box:
29
Synthesis Light: Code Book Attacks
30
Synthesis Light: Code Book Attacks
VM ISA
• x+y
• x−y
• x∧y
• x∨y
• x⊕y
30
Synthesis Light: Code Book Attacks
VM ISA
Lookup Table
• x+y
(5, 3) → 8: x+y
• x−y (5, 3) → 2: x−y
• x∧y (5, 3) → 1: x∧y
• x∨y (5, 3) → 7: x∨y
(5, 3) → 6: x⊕y
• x⊕y
30
Synthesis Light: Code Book Attacks
VM ISA
Lookup Table
• x+y
(5, 3) → 8: x+y
• x−y (5, 3) → 2: x−y
• x∧y (5, 3) → 1: x∧y
• x∨y (5, 3) → 7: x∨y
(5, 3) → 6: x⊕y
• x⊕y
30
Attack Surface
Shortcomings of VMs
32
Shortcomings of VMs
32
VM Attack Landscape
Attack Vectors
7 7 7 7 7 7
33
VM Attack Landscape
Attack Vectors
7 7 7 7 7 7
33
VM Attack Landscape
Attack Vectors
7 7 7 7 7 7
33
Next-Gen VM-based Obfuscators
Design Goals
Attack Vectors
36
Design Principles
• handler semantics are based on instruction sequences from the target program
36
Design Principles
• handler semantics are based on instruction sequences from the target program
• introduce diversity
36
Design Principles
• handler semantics are based on instruction sequences from the target program
• introduce diversity
36
Design Principles
• handler semantics are based on instruction sequences from the target program
No meaningful
• complex instruction mnemonics for VM disassemblers
handler semantics
• introduce diversity
36
Design Principles
37
Design Principles
37
Design Principles
37
Design Principles
37
Loki
Loki
39
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Current VM Handlers
opcode
opcode
register
register
register
register
constant
41
Can we do better?
Merging Instruction Semantics
x + y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
43
Merging Instruction Semantics
x + y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
43
Merging Instruction Semantics
x + y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
43
Merging Instruction Semantics
43
Polynomial Encodings and Branch-free Code
( a
x+y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
b c
equal
f (x, y, c, k) := (k == 0) · x + y
a’
+ (k == 1) · x − y << c
44
Polynomial Encodings and Branch-free Code
( a
x+y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
b c
equal
f (x, y, c, k) := (k == 0) · x + y
a’
+ (k == 1) · x − y << c
44
Polynomial Encodings and Branch-free Code
( a
x+y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
b c
equal
f (x, y, c, k) := (k == 0) · x + y
a’
+ (k == 1) · x − y << c
44
Polynomial Encodings and Branch-free Code
( a
x+y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
b c
equal
f (x, y, c, k) := (k == 0) · x + y
a’
+ (k == 1) · x − y << c
44
Polynomial Encodings and Branch-free Code
( a
x+y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
b c
equal
f (x, y, c, k) := (k == 0) · x + y
a’
+ (k == 1) · x − y << c
44
Polynomial Encodings and Branch-free Code
( a
x+y if k == 0
f (x, y, c, k) :=
x − y << c if k == 1
b c
Interlockingequal
of instruction semantics
f (x, y, c, k) := (k == 0) · x + y
a’
+ (k == 1) · x − y << c
44
Polynomial Encodings
Attack Vectors
Factorization
f (x, y, c, k) := (k == 0) · x + y
+ (k == 1) · x − y << c
Quadratic Residues
46
Hardening Key Selection
Factorization
f (x, y, c, k) := (n mod k == 0) · x + y
+ (k2 == q mod m) · x − y << c
Quadratic Residues
46
Hardening Key Selection
Factorization
f (x, y, c, k) := (n mod k == 0) · x + y
+ (k2 == q mod m) · x − y << c
Quadratic Residues
46
Hardening Key Selection
Factorization
f (x, y, c, k) := (n mod k == 0) · x + y
+ (k2 == q mod m) · x − y << c
Quadratic Residues
46
Hardening Key Selection
Factorization
SMT-hard
f (x, y,encodings
c, k) := forkinstruction
(n mod == 0) · x + y selection
+ (k2 == q mod m) · x − y << c
Quadratic Residues
46
Point Functions
47
Point Functions
47
Point Functions
47
Point Functions
pf (0x1336) = 1
47
Point Functions
pf (0x1336) = 1
3
47
Point Functions
pf (0x1336) = 1 pf (0xabcd) = 0
3
47
Point Functions
pf (0x1336) = 1 pf (0xabcd) = 0
3 7
47
Point Functions
pf (0x1000) = 0x20ab58bbaa53a22ad7
pf (0x1336) = 1 pf (0xabcd) = 0
3 7 ?
47
Point Functions
pf (0x1000) = 0x20ab58bbaa53a22ad7
pf (0x1336) = 1 pf (0xabcd) = 0
pf (0xdead) = 0xf4c7e7859c0c3d320
3 7 ??
47
Point Functions
3 7 ??
47
SMT-hard Key Encodings and Point Functions
Attack Vectors
49
Thwarting Program Synthesis
49
Thwarting Program Synthesis
49
Thwarting Program Synthesis
49
How to Build Semantically Complex Operations
50
How to Build Semantically Complex Operations
50
How to Build Semantically Complex Operations
50
How to Build Semantically Complex Operations
50
How to Build Semantically Complex Operations
50
How to Build Semantically Complex Operations
50
How to Build Semantically Complex Operations
50
How to Build Semantically Complex Operations
f (x, y, c) := (x edx.3
imul edx, 0x10 + y):=∗edx.2
c * 0x10
50
Semantically Complex Operations
Attack Vectors
52
Thwarting Symbolic Execution
52
Thwarting Symbolic Execution
52
Thwarting Symbolic Execution
f (x, y, c, k) :=
(n mod k == 0) · ((x ⊕ y) + 2 · (x ∧ y)) + (x 1)
Syntactically
+ pf (k)complex
1
expressions
· (x + ¬y + 1) · ((x ⊕ y) + 2 · (x ∧ y))
52
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
47) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
47) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
47) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
47) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
47) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
47) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Traditional Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
47) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
Lookup equal
table w/ *all* identities ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Recursive Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Recursive Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Recursive Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Recursive Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Recursive Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Recursive Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
Recursive Approach
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
equal ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Mixed Boolean Arithmetic Expressions
x − y x· (((x
−y∨ xy)−⊕
· ((x −y y) ++y))
· (x∧
(x 2 y)
· (x
+∧ 2 ·y))
(x ∧ y))
Rewriting rules:
1) x + y → (x ⊕ y) + 2 · (x ∧ y)
2) x ⊕ y → (x ∨ y) − (x ∧ y)
Recursive
equal
Rewriting ...
847,000) x ∧ y → (¬x ∨ y) − ¬x
x − yx ·−(((x
y x· ∨
−y)y∨
(((x y)
·−((x − y)
⊕
((¬x ∨∧
(x y)y))
+ 2−· ¬x))
+∧
(x 2 ·y))
+(x2∧· (x
y))∧ y))
final expression
53
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
equal
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
equal
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
equal
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Polynomial MBAs
x − y · (x + y)
Rewrite as:
expr ≡ h−1 (h(expr))
x − y · (h−1 (h(x + y)))
Invertible function on 1 byte:
equal
h : a 7→ 39a + 23
x − y · (h−1 (39 · (x + y) + 23)) h : a 7→ 151a + 111
−1
54
Syntactically Complex Operations
Attack Vectors
58
Loki: Academic Next-Gen VM Prototype
58
Loki: Academic Next-Gen VM Prototype
58
Loki: Academic Next-Gen VM Prototype
58
Loki: Academic Next-Gen VM Prototype
58
Loki: Academic Next-Gen VM Prototype
58
Impact on Deobfuscation
Verging on the Limits
Challenges in Code Deobfuscation
60
Challenges in Code Deobfuscation
• analysis effort rises enormously: limitations of binary analysis techniques & tools
61
What needs to be done?
Better Analysis Tools
• improve tooling for large instruction sequences (performance and memory footprint)
63
Selection of Analysis Windows
64
Advances in MBA Deobfuscation
65
Conclusion
Takeaways
67
Takeaways
Next-gen VMs will shape the landscape of modern obfuscation in the next years.
67
Summary
• virtualization-based obfuscation
• attacks on VMs (instruction removal, symbolic execution, program synthesis)
• next-gen VMs and their impact on deobfuscation
68