Adam Meyers - Obfuscation And Communications
-
Upload
source-conference -
Category
Technology
-
view
1.875 -
download
4
description
Transcript of Adam Meyers - Obfuscation And Communications
Significant Work. Extraordinary People. SRA.
RCE: Obfuscation and Communications
Adam Meyers - SRA International
Significant Work. Extraordinary People. SRA.
Agenda
• Introduction• Disclaimer• Obfuscation• Analysis Techniques• Reversing Obfuscation• Conclusion• Q & A
2
Significant Work. Extraordinary People. SRA.
Who are you, and what are you doing here?
• SRA– Leading provider of technology and strategic consulting services and solutions - including
systems design, development and integration; and outsourcing and managed services.– Comprehensive cyber security practice integrating security architecture, risk assessments, and
certification & accreditation. SRA’s IA practice currently rated at NSA-CMM Level 3.• Adam
– Security Consultant– Penetration Test Team– Forensic Technician– Security Architect– Reverse Code Analysis
3
Significant Work. Extraordinary People. SRA.
Hacker Fail
• Fall 2008 a promise is made • Meet JK Benites • This ‘genius’ left his name (unobfuscated) in the malware he wrote to steal banking
credentials and ended up at a certain US Government Agency
4
i'm JK Benites.I like the music, i love the rock N metal, i'm a person that like stranges things, like adredaline, be good with friends, make new things... i play the guitar, my guitar is my life, with she i can show that i feel.i like the Pcs, too....Visit my profil in Hi5: http://jkprotection.hi5.comCity: PiuraHometown: Piura
Significant Work. Extraordinary People. SRA.
Compliance
5
Angry Birds
lulz
APTCyberwar
Significant Work. Extraordinary People. SRA.
Agenda
• Introduction• Disclaimer• Obfuscation• Analysis Techniques• Reversing Obfuscation• Conclusion• Q & A
6
Significant Work. Extraordinary People. SRA.
Disclaimer• Standard legal-mumbo jumbo.• You have the right to remain silent. Anything you say or do can and will be used against you in a court of law. You have the
right to an attorney. If you cannot afford an attorney, one will be appointed to you. • Prohibition on Reverse Engineering, Decompilation, and Disassembly. You may not reverse engineer, decompile, or
disassemble the SOFTWARE PRODUCT, except and only to the extent that such activity is expressly permitted by applicable law notwithstanding this limitation.
• The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no Warrants shall issue, but upon probable cause, supported by Oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.
• (2) Intentionally accesses a computer without authorization or exceeds authorized access, and thereby obtains— • (A) information contained in a financial record of a financial institution, or of a card issuer as defined in section 1602 (n) of
title 15, or contained in a file of a consumer reporting agency on a consumer, as such terms are defined in the Fair Credit Reporting Act (15 U.S.C. 1681 et seq.);
• (B) information from any department or agency of the United States; or • (C) information from any protected computer;• I pledge allegiance to the flag of the United States of America, and to the republic for which it stands, one nation under God,
indivisible, with liberty and justice for all• Energy can be transformed (changed from one form to another), but cannot be created or destroyed.
7
Significant Work. Extraordinary People. SRA.
Agenda
• Introduction• Disclaimer• Obfuscation• Dynamic Techniques• Static Techniques• Reversing Obfuscation• Conclusion• Q & A
8
Significant Work. Extraordinary People. SRA.
Packing
• This is not a presentation on unpacking• Packers are complex programs aimed at obscuring many of the indicators in
malware• Obfuscated strings, code, and communications can still be packed and may
require manual unpacking
9
Significant Work. Extraordinary People. SRA.
Why obfuscation
• Malware Authors know that once malware is deployed to target environment the race is on
• Obfuscation can provide extra time for the software to operate between detection and mitigation
• In the case of targeted attacks this can allow additional malware/backdoors to be planted and may be critical in operational success
• Obfuscation can circumvent some controls/sensors– E.G: IDS rule looking for ws2_32.dll will miss uq0]10,fnn
• (ws2_32.dll ⊕ 0x2)
10
Significant Work. Extraordinary People. SRA.
Obfuscation Math• Mono-Alphabetic Substitution
– “Caesar Cipher” || “Shift Cipher”
• eXlusive OR ⊕/^– Logic operation “one or the other, never both”– Provides quick obfuscation
• 1 ⊕ 0 = 1
• ‘a’ ⊕ 1 = ‘`’
– Used as an operator in cryptography• Poly-alphabetic substitution
– numerous substitution alphabets– Vigenère Square
11
http://en.wikipedia.org/wiki/Caesar_cipher
Key
Cle
ar T
ext
Significant Work. Extraordinary People. SRA.
Cryptography
• Advanced malware may use advanced cryptographic concepts to conceal data• Strings are largely obfuscated and cryptography is generally reserved for
command and control• Common Malware Crypto
– RC4– OpenSSL (uses algorithms like AES/DES/Blowfish/etc)– PKI - Advanced crypto
• Stream Cipher versus Block Cipher
12
Significant Work. Extraordinary People. SRA.
String Obfuscation• Malware contains strings for a variety of reasons
– Command and Control– Imported/Exported functions– Logging– Crypto
• String Obfuscation is trivial to include– “SOURCE Boston 2011” (Clear)– FBHEPR Obfgba 2011 (ROT13)– 'A]G@QW2P}af}|2 "##' (XOR 0x12)– 0x7 0x27 0x3c 0x21 0x63 0x2c 0x53 0x62 0x2 0xa 0x54 0x4 0xb 0x59 0x66 0x58 0x58
0x42 (key password = “This is my key”)
Significant Work. Extraordinary People. SRA.
Code Obfuscation
• Code obfuscation is more advanced than string obfuscation, malware is coded in such a way that it makes decompilation/disassembly very difficult
• MessageBoxA(0,”test”,”Hello World”,0) - (Clear)•
• Create condition where a function is called via a variable (e.g.: jmp <eax>)• Create loops to build large time delays, or break analysis tools
14
Call Obfuscation{
FARPROC obfunc;obfunc = GetProcAddress(“MessageBoxA”, LoadlibraryA(“user32.dll”));obfunc(0,”test”,”Obfuscate World”,0);
}
Significant Work. Extraordinary People. SRA.
Command and Control
• Malware command and control provides communication to external entities• Typical command and control mechanisms are en claire but obfuscated
– Some are encapsulated in crypto (e.g.: ssl)• Various components of C2 may be obfuscated
– strings used in C2 – HTTP Post, User Agent, Host Name/IP– Content
• Generally provides information back to C2 server on infected systems host name, etc...
15
Significant Work. Extraordinary People. SRA.
Obfuscation Shortfalls
• That which is obfuscated at some point will be deobfuscated• Memory analysis is a great place to identify both unpacked and unobfuscated
malware• Complex obfuscation can be analyzed using readily available tools
16
Significant Work. Extraordinary People. SRA.
Unveiling Obfuscation
• We need to figure out where the obfuscation is– function calls– crypto libraries
• Understand the implementation– Key material 1 byte XOR– Complex password with Crypto Algorithm– Public Key Cryptography
• Reveal obfuscated/crypto material into clear text• Ideally make this repeatable with some code• Lets explore analysis ‘tools’ to begin revealing that which we cannot see
17
Significant Work. Extraordinary People. SRA.
Agenda
• Introduction• Disclaimer• Obfuscation• Analysis Techniques• Reversing Obfuscation• Conclusion• Q & A
18
Significant Work. Extraordinary People. SRA.
Dynamic Analysis• Several different possibilities for ‘Dynamic Analysis’• In process
– Attach a debugger, set break points, step through– Some optimizations
• In memory– Capture system memory during/after malware execution – Utilize a helper tool to lock memory– Execute malware inside a VM, suspend, analyze memory contents
Significant Work. Extraordinary People. SRA.
Debugger Strategies
• Import Break Pointing– Enumerate imports in debugger– Breakpoint functions likely to preceded obfuscation
• Search referenced obfuscated strings and break point on access• Script obfuscation detection
– Immunitydbg
20
Significant Work. Extraordinary People. SRA.
Static Analysis• Static analysis is conducted without executing code• Primary of techniques available
– Strings– Disassembly
• Static analysis with strings is fairly difficult to accomplish in the case of obfuscation
Significant Work. Extraordinary People. SRA.
Disassembly
• Defacto tool IDA Pro– Released free version 5.0 (newer) December 2010– Professional version 6.1
• IDA uses multiple algorithms– Recursive Decent– Linear Sweep
• Write your own– ( Painful + not realistic ) / IDA already exists == no reason
22
Significant Work. Extraordinary People. SRA.
Obfuscated Code
23
Significant Work. Extraordinary People. SRA.
Hybrid Approach
• Use both Dynamic and Static• Various methodologies
– Find obfuscated strings in static analysis– Identify functions referencing string location using disassembler– Breakpoint function in debugger and reverse obfuscation
24
Significant Work. Extraordinary People. SRA.
Concept
25
Obfuscation/Crypto(string)
Persistence/Registry Changes
Command and Control
KeyLog Data/Exfil
Obfuscated
Obfuscated
Obfuscated
Retuned Clear Text
JINO^QMDVUCPG^OKAPMQMDV^UKLFMUQ^AWPPGLVTGPQKML^PWL^PWLMLAG
HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN\RUNONCE
Significant Work. Extraordinary People. SRA.
Concept
26
Obfuscation/Crypto(string)
Persistence/Registry Changes
Command and Control
KeyLog Data/Exfil
Obfuscated
Obfuscated
Obfuscated
Retuned Clear Text
JINO^QMDVUCPG^OKAPMQMDV^UKLFMUQ^AWPPGLVTGPQKML^PWL^PWLMLAG
Break Point
While(string) { clean = string[count] ^ 0x02 .... } return clean
HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN\RUNONCE
Significant Work. Extraordinary People. SRA.
Practical Example - Step 1
27
Obfuscated call breaks IDA XRef
Significant Work. Extraordinary People. SRA.
Practical Example - Step 1
28
Multiple XRef functions to suspected obfuscation
Significant Work. Extraordinary People. SRA.
Practical Example - Step 2
29
Program jumps to Entry PointJump to Crypto Function
Significant Work. Extraordinary People. SRA.
Practical Example - Step 2
30
Set Break Point at function preamble
Significant Work. Extraordinary People. SRA.
Practical Example - Step 2
31
Set Break Point at function return
Significant Work. Extraordinary People. SRA.
Practical Example - Step 2
32
When BP is reached - obfuscated string in ECX
Significant Work. Extraordinary People. SRA.
Practical Example - Step 2
33
When second BP is reached - deobfuscated string pushed to stack
Significant Work. Extraordinary People. SRA.
Other Useful Methods
• Win32 Imports are very useful– Looking for Command and Control? GetHostByName() will receive unobfuscated name– Persistance - RegOpenKey()/RegCreateKey()/RegQueryKey()– Log - CreateFile()/WriteFile()/OpenFile()– Exfiltration - Send()/InternetWriteFile()– Stage2 - URLDownloadToFile()/Recv()– etc
• Same routine– Find code reference to imported function– trace backwards statically to obfuscation– set break points and evaluate dynamically
34
Significant Work. Extraordinary People. SRA.
Agenda
• Introduction• Disclaimer• Obfuscation• Analysis Techniques• Reversing Obfuscation• Conclusion• Q & A
35
Significant Work. Extraordinary People. SRA.
Reversing Obfuscation• Deeper than ‘breakpoint decryption’• Need to analyze algorithm
– Tedious process• Write a tool to decrypt on the fly (help your friends)
Significant Work. Extraordinary People. SRA.
Algorithm Identification
• Hunt the obfuscation function• Dynamic
– Step through the function noting how transforms occur– Complicated algorithms may emerge
• XOR 0x55 << 0x06 + ‘Z’ % 123
• Static– Use Decompiler to review algorithm– Look for static library references
• OpenSSL/PGP/Other• Manual implementation (e.g.: RC4 block cipher)
– API calls (Also available via dynamic)• Crypt()
37
Significant Work. Extraordinary People. SRA.
Components of Interest• Non-encoded strings
– probable key• Loops
– required to loop over multi-character encoded strings to perform transforms• Counters
– Some obfuscation changes the key during iterationsCrypt(string) { key = 0x12 while(string) { string[count] ^ key key++ count++}
• Malware will sometimes add each byte of the key manually– Looks weird in IDA – Protip - use ‘a’ to render hex to ascii
38
Significant Work. Extraordinary People. SRA.
Cheating at Code Deobfuscation
39
Significant Work. Extraordinary People. SRA.
Cheating at Code Deobfuscation
40
Significant Work. Extraordinary People. SRA.
Cheating at Code Deobfuscation
41
Significant Work. Extraordinary People. SRA.
Cheating at Code Deobfuscation
42
Significant Work. Extraordinary People. SRA.
Cheating at Code Deobfuscation
43
Significant Work. Extraordinary People. SRA.
Hexrays DeCompiler
• One word - awesome• Makes reversing algorithms a snap
44
Significant Work. Extraordinary People. SRA.
Hexrays DeCompiler
45
Significant Work. Extraordinary People. SRA.
Script to DeObfuscate
46
Significant Work. Extraordinary People. SRA.
BRUXOR/VARXOR
• Brute XOR Python script for IDA Pro• Simple Algorithm
– XOR string against every possible value– Calculate how much of the string is in ASCII readable space– look for < 6 letters to be non-ascii – Possible Key
• Not very 1337 but shows how simple scripts can help deobfuscate
47
Significant Work. Extraordinary People. SRA.
Bruxor
48
Significant Work. Extraordinary People. SRA.
Bruxor
49
Significant Work. Extraordinary People. SRA.
Bruxor
50
Significant Work. Extraordinary People. SRA.
Bruxor
51
Significant Work. Extraordinary People. SRA.
Bruxor
52
Significant Work. Extraordinary People. SRA.
DeXor
• Command script written for Immunity Debugger• Pointless?• Learning IMM API - more to come
53
Significant Work. Extraordinary People. SRA. 54
Significant Work. Extraordinary People. SRA.
Agenda
• Introduction• Disclaimer• Obfuscation• Analysis Techniques• Reversing Obfuscation• Conclusion• Q & A
55
Significant Work. Extraordinary People. SRA.
Conclusion• Obfuscated strings whether C2 or part of malware will be deobfuscated at some point• Creative use of debugger breakpoints, IDA script, and in some cases memory dumping
can rapidly help deobfuscate• Obfuscated code is complicated to read
– Check out Optimice (by Branko Spasojevic)• Hex Rays Disassembler rocks• Deobfuscating malware is valuable to the Incident Responder/Reverse Engineer• Hybrid approach of debugger and disassembler can make things easier
Significant Work. Extraordinary People. SRA.
Agenda
• Introduction• Disclaimer• Obfuscation• Analysis Techniques• Reversing Obfuscation• Conclusion• Q & A
57