SlideShare a Scribd company logo
Reverse Engineering and Applications to
Anti-Malware
Nguyen Minh Hai
Ho Chi Minh City University of Technology (HCMUT)
November 2015
Agenda
1. Introduction
2. Anti-Research Techniques
1. Indirect Jump
2. Overlapping Instruction
3. Self-modifying Code
4. Encryption
5. Structured Exception Handler
6. Anti-Debugging
7. Anti-Emulation
3. Conclusions
1
Introduction
2
Reverse Engineering
• Reverse engineering (RE) is the process of
inferring the insight knowledge from anything man
made.
• The Goal of RE is to obtain missing knowledge,
ideas and design philosophy when such information
is unavailable.
Demo
5a4d903040ffff0b8
00040000000000000
00000a801f0eebab4
00cd09b8214c0121c
d6854736970206f72
72676d6163206e616
f6e2074656272206e
756920206e4f44205
36f6d6564d2ea0d24
000175ddb1d761...
0x1000: addl $0x2a, %eax
0x1003: cmpl $0x0, %eax
0x1006: jae 0x100f
0x1008: movl $0x5, %ebx
0x100d: jmp 0x1017
0x100f: subl $0x7, %eax
0x1012: movl $0x3, %ebx
0x1017: addl %ebx, %eax
0x1019: ret
Magic word (ZM)
Entry point address
Instructions
Disassembly
Problems
• Indirect Jump
• Overlapping Block/Function/Instruction
• SEH
• Encryption/Decryption
• Anti-Research Techniques
Applications
• Software Maintenance
• Source Code and Documentation Engineering
• Virus Analysis: to extract the Virus Signature
Virus Signature
Signature of Stoned Virus:
0400 B801 020E 07BB 0002 33C9 8BD1 419C
Anti-Research Techniques
4
Motivation
• Multi-layer Malware
Motivation (cont.)
• Obfuscation techniques are used in software for
protecting against cracking, reverse engineering.
• Obfuscation techniques are used in malware for
protecting against automatic detection and analysis
of malicious code.
• Our goal: build a tool for handling most of
obfuscation techniques: Indirect Jump, Self-
modifying code, SEH, Encryption, Anti-Debugging,
Anti-Emulation.
5
Indirect Jump
• Idea: store the target address of JUMP instruction in
register or memory location
• Require simulation of executing x86 instructions
and Windows API
JMP EAX ?????
6
Indirect Jump (cont.)
• Virus.Win32.Aztec
00401057 . B8 00100000 MOV EAX,1000
0040105C . 05 00004000 ADD EAX, 00400000
00401061 . FFE0 JMP EAX
BE-PUM
IDA Pro
7
Indirect Jump (cont.)
• Virus.Win32.Aztec: look for base address of
kernel32 and store address of API in memory
location.
8
Indirect Jump
• Demo
Overlapping Instruction
HLLW.Rolog.f
•Junk code modifies the return address.
00437002 E8 03000000 CALL 0043700A
00437007 E9 EB045D45 JMP 45A074F7
00437002 CALL 0043700A
0043700D RETN
0043700A POP EBP
0043700B INC EBP
0043700C PUSH EBP
Code
11
Demo
BE-PUM
IDA Pro
12
Self-Modifying Code
• Virus.Win32.Seppuku.1606 : Self-Modifying Code
00401646 E8 B5F9FFFF CALL 00401000
EDI = 401067
004010E5 MOV EAX,DWORD PTR SS:[EBP+401489]
004010EB STOS DWORD PTR ES:[EDI]
00401646 E8 00000000 CALL 0040164B
13
Decryption
• Email-Worm.Win32.Kickin.d : Self-decryption
00609223 pop ebp
00609224 push 3d
00609226 mov byte ptr ds:[esi+9cccd0e5],dh
0060922C retn 8d9e
0060922F pxor mm5,mm3
00609232 dec ecx
00609233 fiadd word ptr ds:[ecx+80a6b31]
Decryption loop
ecx was set to 0CAh0060933A mov ecx,0ca
00609345 lods byte ptr ds:[esi]
00609346 xor al,ah
00609348 inc ah
0060934A rol ah,2
0060934D add ah,90
00609350 stos byte ptr es:[edi]
00609351 loopd 00609345
00609223 call 00609228
00609228 mov ebx, [ebp+402705]
0060922E add ebx,28
00609231 pop eax
00609232 sub eax,ebx
00609234 mov [ebp+40270d],eax
14
Demo
BE-PUM
IDA Pro
15
SEH
• SEH - Structured Exception Handler
• Used to handle error in running code
• Malware uses this method to intentionally cause a
change in the execution flow
push offset SEH_Handler
push dword ptr fs:[0]
mov fs:[0],esp
16
SEH (cont.)
004011FE xor edx, edx
00401200 push dword ptr [edx]
00401203 mov dword ptr [edx], esp
00401206 inc dword ptr [edx]
00401209 lea esi,dword ptr [ebp+401943]
edx = 0
Set up SEH
Exception occurs!
17
SEH (cont.)
• Demo
BE-PUM
IDA Pro
18
• Dead code insertion
push %ebx
pop %ebx
• Instruction substitution
mov $0, %eax -> xor %eax, %eax
• Variable renaming & register reassignment
mov $0, %eax -> mov $0, %ebx
• Code reordering
Change syntactic order of the code
Semantic execution path remains unchange
Anti-debugging
• Use NtGlobalFlag field which exists at offset 0x68 in the PEB
(Process Environemnt Block)
• PEB is a structure created in process initialization
• PEB contains data necessary to the execution of a process.
• Used by ExeCryptor
1: mov eax, fs:[30h] ;PEB
;check NtGlobalFlag
2: cmp byte [eax+68h], 70h
3: jne being_debugged
4: jmp real_code
being_debugged:
5: call ExitProcess
19
Anti-debugging (cont.)
• Use the process default heap to find presence of
debugging artifacts
1: mov eax, fs:[30h] ;PEB
;get process heap base
2: mov eax, [eax+18h]
3: mov eax, [eax+0ch] ;Flags
4: dec eax
5: dec eax
6: jne being_debugged
7: jmp real_code
being_debugged:
8: call ExitProcess
20
Special APIs
• The kernel32 IsDebuggerPresent() function was
introduced in Windows 95.
• It returns TRUE if a debugger is present
1: call IsDebuggerPresent
2: test al, al
3: jne being_debugged
4: jmp real_code
being_debugged:
5: call ExitProcess
21
Special APIs (cont.)
• Use kernel32 CheckRemoteDebuggerPresent() function
1: push eax
2: push esp
3: push -1 ;GetCurrentProcess()
4: call CheckRemoteDebuggerPresent
5: pop eax
6: test eax, eax
7: jne being_debugged
8: jmp real_code
being_debugged:
9: call ExitProcess
22
Time Attack
• Malware target on specific date.
E.g. CodeRed malware use Windows API
GetSystemTime
• Solution: On-Demand Symbolic Execution for
Windows API
The return value is symbol value (instead of real
execution with JNA)
Demo
• Win32.Voltage
1: lea eax,[ebp + SYSTEMTIME]
2: push eax
3: call [ebp + GetLocalTime]
4: cmp word ptr [ebp+wMonth],12
5: jne NoPayLoad
6: cmp word ptr [ebp +wDay],29
7: jne NoPayLoad
8: push eax
9: push eax
10: push 0h
11: call [ebp + MessageBox]
NoPayLoad:
12: Call ExitProcess
Execution Timing
• Based on an idea: there is a significant delay between the
executions of the individual instructions in debugger mode
compared to normal execution.
1: call GetTickCount
2: xchg ebx, eax
3: call GetTickCount
4: sub eax, ebx
5: cmp eax, 1
6: jnb being_debugged
7: jmp real_code
being_debugged:
8: call ExitProcess
24
Exception
• Using exceptions to alter the value of eip
• An effective anti-debugging technique
• Used by packer PECompact
1: xor eax, eax
2: push offset l3
3: push dw fs:[eax]
4: mov fs:[eax], esp
l1:
5: call l1
l2:
6: jmp l3
l3:
7: pop eax
25
Exception (cont.)
• Used in packer Telock
00407A1B PUSHAD
00407A1C CALL 00407A27
00407A27 PUSH DWORD PTR FS:[0]
00407A2D MOV DWORD PTR FS:[0],ESP
00407A33 PUSHFD
00407A34 OR DWORD PTR SS:[ESP],100
00407A3B POPFD
00407A3C CLC
00407A3D JNB SHORT 00407A1B
26
Stalling Code
• The main idea is to delay the execution of malicious
activity in very long time.
• Stalling code make automated analysis systems to
give up on a sample.
27
Stalling Code (cont.)
0x00406016: movl %ecx, $0x1951<UINT32>
0x0040601b: movl %eax, %ecx
0x0040601d: clc
0x0040601e: jae 0x00406022
0x00406022: addl %esi, $0x33<UINT8>
0x00406025: leal %eax, 0x67(%ecx,
%eax,4)
0x00406029: call 0x00406030
0x00406030: xorb (%esi), %al
0x00406032: incl %esi
0x00406033: popl %edx
0x00406034: jmp 0x00406037
0x00406037: aam $0x9<UINT8>
0x00406039: decl %ecx
0x0040603a: jg 0x00406025
28
Anti-Emulation
• Invalid API parameters: Attacker will intentionally
pass known invalid parameters to the function, and
expecting an error code to be returned
push 1
push 1
call Beep
call GetLastError
;ERROR_INVALID_PARAMET
ER (0x57)
push 5 ;sizeof(l2)
pop ecx
xchg edx, eax
mov esi, offset l2
mov edi, esi
l1: lodsb
xor al, dl
stosb
loop l1
...
l2: db 3fh, 32h,
3bh, 3bh, 38h
;secret message
29
GetProcAddress
• Attacker will intentionally pass known invalid
parameters to the function, and expecting no
function address to be returned.
• Any emulator that returns an address in such a
situation will be revealed
push offset l1
push 12345678h ;illegal value
call GetProcAddress
test eax, eax
jne being_debugged
...
l1: db "myfunction", 0
30
Undocumented instructions
• An anti-malware emulator might fail to support
undocumented instructions or undocumented
encodings of documented instructions
• Solution: Capstone disassembly
(http://www.capstone-engine.org/)
0040F0D0 > $ 0F6FE0 MOVQ MM4,MM0
0040F0D3 . E8 06000000 CALL 0040F0DE
31
Other Techniques
• Check Parent process for explore.exe
• Checksumming for detecting tampering
• Stolen bytes technique using
VirtualAlloc API.
Other Techniques (cont.)
• Prevent reverser from controlling the debugger with
user32!BlockInput()
• Debugger blocker by spawning a process which
becomes a debugger for the packed code
• API redirection with LoadLibrary and GetProcAddress
Packer
Self-modifying Code + SEH +
Encryption + Anti-Debugging +
Anti-Emulation + ...
•Bullet-proof jacket for software (and malware also):
Against Cracks
Against KeyGens
Against Stolen serial number
Against Unauthorized use
Packer
32
Antivirus Is Dead
Antivirus Isn't Dead, It Just Can't Keep Up
Advanced Persistent Threat
• W32.Stuxnet is discovered in 2009.
A compute worm targets to industrial control
systems for equipment made by Siement.
These systems are used in Iran for uranium
enrichment.
“the Most Menacing Malware in History”
• Flame is discovered in 2010
“most complex malware ever found” – main
component is ~6MB
Kaspersky researchers found chunks of code
from a 2009 Stuxnet variant inside Flame
My Current Research
2
BE-PUM
• BE-PUM - Binary Emulation for Pushdown Model
• Apply pushdown model generation of binary code
Apply concolic testing (dynamic symbolic execution) to
handle indirect jump
Apply on-the-fly model generation for handling self-
modifying code
Focus on obfuscation techniques which are used in
malware and packer tools.
3
Architecture
Frontiers
Single-step
Symbolic Execution
Instr(Env,m)
Jakstab 0.8.3
Feasibility check
SMT: Z3 4.3
Control
instructions
Data
instructions
Yes
No
Binary Emulation
Controlled
Sandbox
Stack
Memory
Register
Flag
(k, asmk,ψk)
(k, asmk,ψk) : New region?
〈 (k, asmk),ε 〉 ↪ 〈 (m, asm), (m’, asm’) 〉 : New rule?
Pushdown Model
〈 (k, asmk),ε 〉 ↪ 〈 (m, asm), (m’, asm’) 〉
Symbolic states
(k, asmk,ψk )
Stub of API
System call
(pre-condition)
Java API
(Output)
CFG Storage
〈 (k, asmk) 〉
Conclusion
• RE is very important in the fight for malware.
• It needs to evolve to keep up with the new types of
APT malwares.
• How ???
36
References
• “The Art of Unpacking”. Mark Vincent Yason.
• “Reversing: Secrets of Reverse Engineering”. Eldad
Eilam.
• “An Anti-Reverse Engineering Guide”. Josh_Jackson.
• “Anti-unpacker Tricks”. Peter Ferrie.
36
Q&A

More Related Content

What's hot

Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 
Source Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers ViewpointSource Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers Viewpoint
Tyler Shields
 
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacketCsw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
CanSecWest
 
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
mmisono
 
A exception ekon16
A exception ekon16A exception ekon16
A exception ekon16
Max Kleiner
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
 
Scale17x buffer overflows
Scale17x buffer overflowsScale17x buffer overflows
Scale17x buffer overflows
johseg
 
Secure coding for developers
Secure coding for developersSecure coding for developers
Secure coding for developers
sluge
 
Taint scope
Taint scopeTaint scope
Taint scope
geeksec80
 
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Ivan Piskunov
 
Exploring the x64
Exploring the x64Exploring the x64
Exploring the x64
FFRI, Inc.
 
Protecting C++
Protecting C++Protecting C++
Protecting C++
Pavel Filonov
 
Moony li pacsec-1.8
Moony li pacsec-1.8Moony li pacsec-1.8
Moony li pacsec-1.8
PacSecJP
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23
DefconRussia
 
Static analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsStatic analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systems
Andrey Karpov
 
Qt Rest Server
Qt Rest ServerQt Rest Server
Qt Rest Server
Vasiliy Sorokin
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
Ji Hun Kim
 
2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits 2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits
Raleigh ISSA
 
Maximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestMaximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digest
Pythian
 

What's hot (19)

Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
Source Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers ViewpointSource Boston 2009 - Anti-Debugging A Developers Viewpoint
Source Boston 2009 - Anti-Debugging A Developers Viewpoint
 
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacketCsw2016 wheeler barksdale-gruskovnjak-execute_mypacket
Csw2016 wheeler barksdale-gruskovnjak-execute_mypacket
 
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
論文紹介 Hyperkernel: Push-Button Verification of an OS Kernel (SOSP’17)
 
A exception ekon16
A exception ekon16A exception ekon16
A exception ekon16
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
 
Scale17x buffer overflows
Scale17x buffer overflowsScale17x buffer overflows
Scale17x buffer overflows
 
Secure coding for developers
Secure coding for developersSecure coding for developers
Secure coding for developers
 
Taint scope
Taint scopeTaint scope
Taint scope
 
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
 
Exploring the x64
Exploring the x64Exploring the x64
Exploring the x64
 
Protecting C++
Protecting C++Protecting C++
Protecting C++
 
Moony li pacsec-1.8
Moony li pacsec-1.8Moony li pacsec-1.8
Moony li pacsec-1.8
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23
 
Static analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systemsStatic analysis and writing C/C++ of high quality code for embedded systems
Static analysis and writing C/C++ of high quality code for embedded systems
 
Qt Rest Server
Qt Rest ServerQt Rest Server
Qt Rest Server
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 
2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits 2011-03 Developing Windows Exploits
2011-03 Developing Windows Exploits
 
Maximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digestMaximizing SQL Reviews and Tuning with pt-query-digest
Maximizing SQL Reviews and Tuning with pt-query-digest
 

Viewers also liked

Reverse Engineering Web Applications
Reverse Engineering Web ApplicationsReverse Engineering Web Applications
Reverse Engineering Web Applications
Porfirio Tramontana
 
Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...
Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...
Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...
Association of Scientists, Developers and Faculties
 
Reverse Engineering .NET and Java
Reverse Engineering .NET and JavaReverse Engineering .NET and Java
Reverse Engineering .NET and Java
Joe Kuemerle
 
ravi reverseengineeringitsapplication01 121101044845-phpapp02
ravi reverseengineeringitsapplication01 121101044845-phpapp02ravi reverseengineeringitsapplication01 121101044845-phpapp02
ravi reverseengineeringitsapplication01 121101044845-phpapp02
Akash Maurya
 
Introduction to Reverse Engineering
Introduction to Reverse EngineeringIntroduction to Reverse Engineering
Introduction to Reverse Engineering
Gopinath Chintala
 
Reverse engineering
Reverse engineeringReverse engineering
Reverse engineering
Syed Zillay Ali
 
Reverse engineering
Reverse engineeringReverse engineering
Reverse engineering
Saswat Padhi
 
Reverse engineering & its application
Reverse engineering & its applicationReverse engineering & its application
Reverse engineering & its application
mapqrs
 
IEEE Day 2013 - Reverse Engineering an Android Application
IEEE Day 2013 - Reverse Engineering an Android ApplicationIEEE Day 2013 - Reverse Engineering an Android Application
IEEE Day 2013 - Reverse Engineering an Android Application
Rufatet Babakishiyev
 

Viewers also liked (9)

Reverse Engineering Web Applications
Reverse Engineering Web ApplicationsReverse Engineering Web Applications
Reverse Engineering Web Applications
 
Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...
Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...
Application of Reverse Engineering and CAD/CAM in Field of Prosthetics-A Make...
 
Reverse Engineering .NET and Java
Reverse Engineering .NET and JavaReverse Engineering .NET and Java
Reverse Engineering .NET and Java
 
ravi reverseengineeringitsapplication01 121101044845-phpapp02
ravi reverseengineeringitsapplication01 121101044845-phpapp02ravi reverseengineeringitsapplication01 121101044845-phpapp02
ravi reverseengineeringitsapplication01 121101044845-phpapp02
 
Introduction to Reverse Engineering
Introduction to Reverse EngineeringIntroduction to Reverse Engineering
Introduction to Reverse Engineering
 
Reverse engineering
Reverse engineeringReverse engineering
Reverse engineering
 
Reverse engineering
Reverse engineeringReverse engineering
Reverse engineering
 
Reverse engineering & its application
Reverse engineering & its applicationReverse engineering & its application
Reverse engineering & its application
 
IEEE Day 2013 - Reverse Engineering an Android Application
IEEE Day 2013 - Reverse Engineering an Android ApplicationIEEE Day 2013 - Reverse Engineering an Android Application
IEEE Day 2013 - Reverse Engineering an Android Application
 

Similar to Reverse engineering20151112

Windows debugging sisimon
Windows debugging   sisimonWindows debugging   sisimon
Windows debugging sisimon
Sisimon Soman
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
Satpal Parmar
 
Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"
Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"
Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"
Yulia Tsisyk
 
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
David Beazley (Dabeaz LLC)
 
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Jagadisha Maiya
 
Tetcon2016 160104
Tetcon2016 160104Tetcon2016 160104
Tetcon2016 160104
Bordeaux I
 
Reverse eningeering
Reverse eningeeringReverse eningeering
Reverse eningeering
Kent Huang
 
How Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protectionsHow Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protections
Jonathan Salwan
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
Weber Tsai
 
Reverse engineering of binary programs for custom virtual machines
Reverse engineering of binary programs for custom virtual machinesReverse engineering of binary programs for custom virtual machines
Reverse engineering of binary programs for custom virtual machines
SmartDec
 
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbg
Arno Huetter
 
NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016
Mikhail Sosonkin
 
C++ in kernel mode
C++ in kernel modeC++ in kernel mode
C++ in kernel mode
corehard_by
 
HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1
Linaro
 
Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019
Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019 Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019
Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019
corehard_by
 
SEH overwrite and its exploitability
SEH overwrite and its exploitabilitySEH overwrite and its exploitability
SEH overwrite and its exploitability
FFRI, Inc.
 
The forgotten art of assembly
The forgotten art of assemblyThe forgotten art of assembly
The forgotten art of assembly
Marian Marinov
 
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypassObject Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Sam Thomas
 
Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...
Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...
Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...
Positive Hack Days
 
WCTF 2018 binja Editorial
WCTF 2018 binja EditorialWCTF 2018 binja Editorial
WCTF 2018 binja Editorial
Charo_IT
 

Similar to Reverse engineering20151112 (20)

Windows debugging sisimon
Windows debugging   sisimonWindows debugging   sisimon
Windows debugging sisimon
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
 
Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"
Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"
Рахманов Александр "Что полезного в разборе дампов для .NET-разработчиков?"
 
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
 
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
 
Tetcon2016 160104
Tetcon2016 160104Tetcon2016 160104
Tetcon2016 160104
 
Reverse eningeering
Reverse eningeeringReverse eningeering
Reverse eningeering
 
How Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protectionsHow Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protections
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
Reverse engineering of binary programs for custom virtual machines
Reverse engineering of binary programs for custom virtual machinesReverse engineering of binary programs for custom virtual machines
Reverse engineering of binary programs for custom virtual machines
 
Windows Debugging with WinDbg
Windows Debugging with WinDbgWindows Debugging with WinDbg
Windows Debugging with WinDbg
 
NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016
 
C++ in kernel mode
C++ in kernel modeC++ in kernel mode
C++ in kernel mode
 
HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1HHVM on AArch64 - BUD17-400K1
HHVM on AArch64 - BUD17-400K1
 
Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019
Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019 Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019
Защищая С++. Павел Филонов ➠ CoreHard Autumn 2019
 
SEH overwrite and its exploitability
SEH overwrite and its exploitabilitySEH overwrite and its exploitability
SEH overwrite and its exploitability
 
The forgotten art of assembly
The forgotten art of assemblyThe forgotten art of assembly
The forgotten art of assembly
 
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypassObject Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypass
 
Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...
Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...
Positive Hack Days. Oleksyuk. Automatic Search for Vulnerabilities in Program...
 
WCTF 2018 binja Editorial
WCTF 2018 binja EditorialWCTF 2018 binja Editorial
WCTF 2018 binja Editorial
 

Recently uploaded

Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
michniczscribd
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
Paul Brebner
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
Maitrey Patel
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
campbellclarkson
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio, Inc.
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
confluent
 
The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
mohitd6
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
narinav14
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
Alina Yurenko
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 

Recently uploaded (20)

Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
 
ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.ACE - Team 24 Wrapup event at ahmedabad.
ACE - Team 24 Wrapup event at ahmedabad.
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
 
Building API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructureBuilding API data products on top of your real-time data infrastructure
Building API data products on top of your real-time data infrastructure
 
The Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdfThe Role of DevOps in Digital Transformation.pdf
The Role of DevOps in Digital Transformation.pdf
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and MoreManyata Tech Park Bangalore_ Infrastructure, Facilities and More
Manyata Tech Park Bangalore_ Infrastructure, Facilities and More
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 

Reverse engineering20151112

  • 1. Reverse Engineering and Applications to Anti-Malware Nguyen Minh Hai Ho Chi Minh City University of Technology (HCMUT) November 2015
  • 2. Agenda 1. Introduction 2. Anti-Research Techniques 1. Indirect Jump 2. Overlapping Instruction 3. Self-modifying Code 4. Encryption 5. Structured Exception Handler 6. Anti-Debugging 7. Anti-Emulation 3. Conclusions 1
  • 4. Reverse Engineering • Reverse engineering (RE) is the process of inferring the insight knowledge from anything man made. • The Goal of RE is to obtain missing knowledge, ideas and design philosophy when such information is unavailable.
  • 5. Demo 5a4d903040ffff0b8 00040000000000000 00000a801f0eebab4 00cd09b8214c0121c d6854736970206f72 72676d6163206e616 f6e2074656272206e 756920206e4f44205 36f6d6564d2ea0d24 000175ddb1d761... 0x1000: addl $0x2a, %eax 0x1003: cmpl $0x0, %eax 0x1006: jae 0x100f 0x1008: movl $0x5, %ebx 0x100d: jmp 0x1017 0x100f: subl $0x7, %eax 0x1012: movl $0x3, %ebx 0x1017: addl %ebx, %eax 0x1019: ret Magic word (ZM) Entry point address Instructions Disassembly
  • 6.
  • 7. Problems • Indirect Jump • Overlapping Block/Function/Instruction • SEH • Encryption/Decryption • Anti-Research Techniques
  • 8. Applications • Software Maintenance • Source Code and Documentation Engineering • Virus Analysis: to extract the Virus Signature
  • 9. Virus Signature Signature of Stoned Virus: 0400 B801 020E 07BB 0002 33C9 8BD1 419C
  • 12. Motivation (cont.) • Obfuscation techniques are used in software for protecting against cracking, reverse engineering. • Obfuscation techniques are used in malware for protecting against automatic detection and analysis of malicious code. • Our goal: build a tool for handling most of obfuscation techniques: Indirect Jump, Self- modifying code, SEH, Encryption, Anti-Debugging, Anti-Emulation. 5
  • 13. Indirect Jump • Idea: store the target address of JUMP instruction in register or memory location • Require simulation of executing x86 instructions and Windows API JMP EAX ????? 6
  • 14. Indirect Jump (cont.) • Virus.Win32.Aztec 00401057 . B8 00100000 MOV EAX,1000 0040105C . 05 00004000 ADD EAX, 00400000 00401061 . FFE0 JMP EAX BE-PUM IDA Pro 7
  • 15. Indirect Jump (cont.) • Virus.Win32.Aztec: look for base address of kernel32 and store address of API in memory location. 8
  • 17. Overlapping Instruction HLLW.Rolog.f •Junk code modifies the return address. 00437002 E8 03000000 CALL 0043700A 00437007 E9 EB045D45 JMP 45A074F7 00437002 CALL 0043700A 0043700D RETN 0043700A POP EBP 0043700B INC EBP 0043700C PUSH EBP Code 11
  • 19. Self-Modifying Code • Virus.Win32.Seppuku.1606 : Self-Modifying Code 00401646 E8 B5F9FFFF CALL 00401000 EDI = 401067 004010E5 MOV EAX,DWORD PTR SS:[EBP+401489] 004010EB STOS DWORD PTR ES:[EDI] 00401646 E8 00000000 CALL 0040164B 13
  • 20. Decryption • Email-Worm.Win32.Kickin.d : Self-decryption 00609223 pop ebp 00609224 push 3d 00609226 mov byte ptr ds:[esi+9cccd0e5],dh 0060922C retn 8d9e 0060922F pxor mm5,mm3 00609232 dec ecx 00609233 fiadd word ptr ds:[ecx+80a6b31] Decryption loop ecx was set to 0CAh0060933A mov ecx,0ca 00609345 lods byte ptr ds:[esi] 00609346 xor al,ah 00609348 inc ah 0060934A rol ah,2 0060934D add ah,90 00609350 stos byte ptr es:[edi] 00609351 loopd 00609345 00609223 call 00609228 00609228 mov ebx, [ebp+402705] 0060922E add ebx,28 00609231 pop eax 00609232 sub eax,ebx 00609234 mov [ebp+40270d],eax 14
  • 22. SEH • SEH - Structured Exception Handler • Used to handle error in running code • Malware uses this method to intentionally cause a change in the execution flow push offset SEH_Handler push dword ptr fs:[0] mov fs:[0],esp 16
  • 23. SEH (cont.) 004011FE xor edx, edx 00401200 push dword ptr [edx] 00401203 mov dword ptr [edx], esp 00401206 inc dword ptr [edx] 00401209 lea esi,dword ptr [ebp+401943] edx = 0 Set up SEH Exception occurs! 17
  • 25. • Dead code insertion push %ebx pop %ebx • Instruction substitution mov $0, %eax -> xor %eax, %eax • Variable renaming & register reassignment mov $0, %eax -> mov $0, %ebx • Code reordering Change syntactic order of the code Semantic execution path remains unchange
  • 26. Anti-debugging • Use NtGlobalFlag field which exists at offset 0x68 in the PEB (Process Environemnt Block) • PEB is a structure created in process initialization • PEB contains data necessary to the execution of a process. • Used by ExeCryptor 1: mov eax, fs:[30h] ;PEB ;check NtGlobalFlag 2: cmp byte [eax+68h], 70h 3: jne being_debugged 4: jmp real_code being_debugged: 5: call ExitProcess 19
  • 27. Anti-debugging (cont.) • Use the process default heap to find presence of debugging artifacts 1: mov eax, fs:[30h] ;PEB ;get process heap base 2: mov eax, [eax+18h] 3: mov eax, [eax+0ch] ;Flags 4: dec eax 5: dec eax 6: jne being_debugged 7: jmp real_code being_debugged: 8: call ExitProcess 20
  • 28. Special APIs • The kernel32 IsDebuggerPresent() function was introduced in Windows 95. • It returns TRUE if a debugger is present 1: call IsDebuggerPresent 2: test al, al 3: jne being_debugged 4: jmp real_code being_debugged: 5: call ExitProcess 21
  • 29. Special APIs (cont.) • Use kernel32 CheckRemoteDebuggerPresent() function 1: push eax 2: push esp 3: push -1 ;GetCurrentProcess() 4: call CheckRemoteDebuggerPresent 5: pop eax 6: test eax, eax 7: jne being_debugged 8: jmp real_code being_debugged: 9: call ExitProcess 22
  • 30. Time Attack • Malware target on specific date. E.g. CodeRed malware use Windows API GetSystemTime • Solution: On-Demand Symbolic Execution for Windows API The return value is symbol value (instead of real execution with JNA)
  • 31. Demo • Win32.Voltage 1: lea eax,[ebp + SYSTEMTIME] 2: push eax 3: call [ebp + GetLocalTime] 4: cmp word ptr [ebp+wMonth],12 5: jne NoPayLoad 6: cmp word ptr [ebp +wDay],29 7: jne NoPayLoad 8: push eax 9: push eax 10: push 0h 11: call [ebp + MessageBox] NoPayLoad: 12: Call ExitProcess
  • 32. Execution Timing • Based on an idea: there is a significant delay between the executions of the individual instructions in debugger mode compared to normal execution. 1: call GetTickCount 2: xchg ebx, eax 3: call GetTickCount 4: sub eax, ebx 5: cmp eax, 1 6: jnb being_debugged 7: jmp real_code being_debugged: 8: call ExitProcess 24
  • 33. Exception • Using exceptions to alter the value of eip • An effective anti-debugging technique • Used by packer PECompact 1: xor eax, eax 2: push offset l3 3: push dw fs:[eax] 4: mov fs:[eax], esp l1: 5: call l1 l2: 6: jmp l3 l3: 7: pop eax 25
  • 34. Exception (cont.) • Used in packer Telock 00407A1B PUSHAD 00407A1C CALL 00407A27 00407A27 PUSH DWORD PTR FS:[0] 00407A2D MOV DWORD PTR FS:[0],ESP 00407A33 PUSHFD 00407A34 OR DWORD PTR SS:[ESP],100 00407A3B POPFD 00407A3C CLC 00407A3D JNB SHORT 00407A1B 26
  • 35. Stalling Code • The main idea is to delay the execution of malicious activity in very long time. • Stalling code make automated analysis systems to give up on a sample. 27
  • 36. Stalling Code (cont.) 0x00406016: movl %ecx, $0x1951<UINT32> 0x0040601b: movl %eax, %ecx 0x0040601d: clc 0x0040601e: jae 0x00406022 0x00406022: addl %esi, $0x33<UINT8> 0x00406025: leal %eax, 0x67(%ecx, %eax,4) 0x00406029: call 0x00406030 0x00406030: xorb (%esi), %al 0x00406032: incl %esi 0x00406033: popl %edx 0x00406034: jmp 0x00406037 0x00406037: aam $0x9<UINT8> 0x00406039: decl %ecx 0x0040603a: jg 0x00406025 28
  • 37. Anti-Emulation • Invalid API parameters: Attacker will intentionally pass known invalid parameters to the function, and expecting an error code to be returned push 1 push 1 call Beep call GetLastError ;ERROR_INVALID_PARAMET ER (0x57) push 5 ;sizeof(l2) pop ecx xchg edx, eax mov esi, offset l2 mov edi, esi l1: lodsb xor al, dl stosb loop l1 ... l2: db 3fh, 32h, 3bh, 3bh, 38h ;secret message 29
  • 38. GetProcAddress • Attacker will intentionally pass known invalid parameters to the function, and expecting no function address to be returned. • Any emulator that returns an address in such a situation will be revealed push offset l1 push 12345678h ;illegal value call GetProcAddress test eax, eax jne being_debugged ... l1: db "myfunction", 0 30
  • 39. Undocumented instructions • An anti-malware emulator might fail to support undocumented instructions or undocumented encodings of documented instructions • Solution: Capstone disassembly (http://www.capstone-engine.org/) 0040F0D0 > $ 0F6FE0 MOVQ MM4,MM0 0040F0D3 . E8 06000000 CALL 0040F0DE 31
  • 40. Other Techniques • Check Parent process for explore.exe • Checksumming for detecting tampering • Stolen bytes technique using VirtualAlloc API.
  • 41. Other Techniques (cont.) • Prevent reverser from controlling the debugger with user32!BlockInput() • Debugger blocker by spawning a process which becomes a debugger for the packed code • API redirection with LoadLibrary and GetProcAddress
  • 42. Packer Self-modifying Code + SEH + Encryption + Anti-Debugging + Anti-Emulation + ... •Bullet-proof jacket for software (and malware also): Against Cracks Against KeyGens Against Stolen serial number Against Unauthorized use Packer 32
  • 43.
  • 45. Antivirus Isn't Dead, It Just Can't Keep Up
  • 46. Advanced Persistent Threat • W32.Stuxnet is discovered in 2009. A compute worm targets to industrial control systems for equipment made by Siement. These systems are used in Iran for uranium enrichment. “the Most Menacing Malware in History” • Flame is discovered in 2010 “most complex malware ever found” – main component is ~6MB Kaspersky researchers found chunks of code from a 2009 Stuxnet variant inside Flame
  • 48. BE-PUM • BE-PUM - Binary Emulation for Pushdown Model • Apply pushdown model generation of binary code Apply concolic testing (dynamic symbolic execution) to handle indirect jump Apply on-the-fly model generation for handling self- modifying code Focus on obfuscation techniques which are used in malware and packer tools. 3
  • 49. Architecture Frontiers Single-step Symbolic Execution Instr(Env,m) Jakstab 0.8.3 Feasibility check SMT: Z3 4.3 Control instructions Data instructions Yes No Binary Emulation Controlled Sandbox Stack Memory Register Flag (k, asmk,ψk) (k, asmk,ψk) : New region? 〈 (k, asmk),ε 〉 ↪ 〈 (m, asm), (m’, asm’) 〉 : New rule? Pushdown Model 〈 (k, asmk),ε 〉 ↪ 〈 (m, asm), (m’, asm’) 〉 Symbolic states (k, asmk,ψk ) Stub of API System call (pre-condition) Java API (Output) CFG Storage 〈 (k, asmk) 〉
  • 50. Conclusion • RE is very important in the fight for malware. • It needs to evolve to keep up with the new types of APT malwares. • How ??? 36
  • 51. References • “The Art of Unpacking”. Mark Vincent Yason. • “Reversing: Secrets of Reverse Engineering”. Eldad Eilam. • “An Anti-Reverse Engineering Guide”. Josh_Jackson. • “Anti-unpacker Tricks”. Peter Ferrie. 36
  • 52. Q&A

Editor's Notes

  1. Anti-research
  2. https://en.wikipedia.org/wiki/Stoned_(computer_virus) Stoned is the name of a boot sector computer virus created in 1987. One of the very first viruses, it is thought to have been written by a university student in Wellington, New Zealand.[1][2] By 1989 it had spread widely in New Zealand and Australia,[3] and variants became very common worldwide in the early 1990s.[4] A computer infected with the original version had a one in eight probability[5][6] that the screen would declare: &amp;quot;Your PC is now Stoned!&amp;quot;, a phrase found in infected boot sectors of infected floppy disks and master boot records of infected hard disks, along with the phrase &amp;quot;Legalise Marijuana&amp;quot;. Later variants produced a range of other messages.
  3. In software development, obfuscation is the deliberate act of creating obfuscated code, i.e. source or machine code that is difficult for humans to understand. Programmers may deliberately obfuscate code to conceal its purpose (security through obscurity) or its logic, in order to prevent tampering, deter reverse engineering, or as a puzzle or recreational challenge for someone reading the source code. Programs known as obfuscators transform readable code into obfuscated code using various techniques.
  4. Eva.a : exception occurrence is obfuscated. As Windows standard, fs:[0] initially points to the system exception handler. New frame pushed at 00401012 and modified at 00401015. At 00401018, access violation (inc at 00000000). Win32 PE executables can set up a so-called SEH (Structured Exception Handler). Most runtime code, and several viruses use this method to trap errors, but it can also be used to intentionally cause a change in the execution flow. Viruses insert their SEH and create a fault condition, causing the exception handler to be run instead. The first virus really in ‘in-the-wild’ installing multiple exception handlers was W32/Magistr.A to confuse AV emulators.
  5. What is PEB: Process Environment Block Simulate PEB structure using symbolic execution value
  6. Solution: Simulate PEB structure using symbolic execution value
  7. Solution: On-demand Symbolic Execution for APIs
  8. Other APIs: NtQueryInformationProcess, NtQuerySystemInformation, NtQueryObject, SetInformationThread... Determines whether the specified process is being debugged. Solution: On-demand Symbolic Execution for APIs
  9. Solution: On-demand Symbolic Execution for APIs
  10. Stack overflow
  11. This leads to a vulnerability, whereby an attacker will intentionally pass known invalid parameters to the function, and expecting an error code to be returned. In some cases, this error code is used as a key for decryption. Any emulator that fails to return the error code will not be able to decrypt the data. Solution: On-demand Symbolic Execution for APIs
  12. Solution: Simulate Windows APIs