SlideShare ist ein Scribd-Unternehmen logo
1 von 58
Downloaden Sie, um offline zu lesen
RCE: Obfuscation and
 Communications
Adam Meyers - SRA International




                                  Significant Work. Extraordinary People. SRA.
Agenda

                            •     Introduction
                            •     Disclaimer
                            •     Obfuscation
                            •     Analysis Techniques
                            •     Reversing Obfuscation
                            •     Conclusion
                            •     Q&A




Significant Work. Extraordinary People. SRA.                   2
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




Significant Work. Extraordinary People. SRA.                                                              3
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




 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.com
City: Piura
Hometown: Piura


  Significant Work. Extraordinary People. SRA.                                        4
Compliance

                                                Angry Birds



                          lulz


                                                        Cyberwar

                                               APT



Significant Work. Extraordinary People. SRA.                                5
Agenda

                            •     Introduction
                            •     Disclaimer
                            •     Obfuscation
                            •     Analysis Techniques
                            •     Reversing Obfuscation
                            •     Conclusion
                            •     Q&A




Significant Work. Extraordinary People. SRA.                   6
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.




Significant Work. Extraordinary People. SRA.                                                                                         7
Agenda

                            •     Introduction
                            •     Disclaimer
                            •     Obfuscation
                            •     Dynamic Techniques
                            •     Static Techniques
                            •     Reversing Obfuscation
                            •     Conclusion
                            •     Q&A



Significant Work. Extraordinary People. SRA.                   8
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




Significant Work. Extraordinary People. SRA.                                  9
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)




Significant Work. Extraordinary People. SRA.                                          10
Obfuscation Math
• Mono-Alphabetic Substitution
       – “Caesar Cipher” || “Shift Cipher”



                                                                                        Key




                              http://en.wikipedia.org/wiki/Caesar_cipher
• eXlusive OR ⊕/^
       – Logic operation “one or the other, never both”
       – Provides quick obfuscation




                                                                           Clear Text
              • 1⊕0=1
              • ‘a’ ⊕ 1 = ‘`’
       – Used as an operator in cryptography
• Poly-alphabetic substitution
       – numerous substitution alphabets
       – Vigenère Square



Significant Work. Extraordinary People. SRA.                                                  11
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




Significant Work. Extraordinary People. SRA.                                  12
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)
• Call Obfuscation
   {
     FARPROC obfunc;
     obfunc = GetProcAddress(“MessageBoxA”, LoadlibraryA
     (“user32.dll”));
     obfunc(0,”test”,”Obfuscate World”,0);
   }
• 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




Significant Work. Extraordinary People. SRA.                                       14
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...




Significant Work. Extraordinary People. SRA.                                                             15
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




Significant Work. Extraordinary People. SRA.                                    16
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




Significant Work. Extraordinary People. SRA.                                  17
Agenda

                            •     Introduction
                            •     Disclaimer
                            •     Obfuscation
                            •     Analysis Techniques
                            •     Reversing Obfuscation
                            •     Conclusion
                            •     Q&A




Significant Work. Extraordinary People. SRA.                   18
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




Significant Work. Extraordinary People. SRA.                            20
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




Significant Work. Extraordinary People. SRA.                                       22
Obfuscated Code




Significant Work. Extraordinary People. SRA.                 23
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




Significant Work. Extraordinary People. SRA.                                  24
Concept

                                                                       Persistence/Registry Changes

                                                          a     ted
                                          u            sc
JINO^QMDVUCPG^OKAPMQMDV^UKLFMUQ^AWPPGLV bf
                                       O
TGPQKML^PWL^PWLMLAG


                                                 Obfuscated
                                                                       Command and Control
              Obfuscation/Crypto(string)


                                                   Ob
                                                      fu   sc
                                                             ate
                                                                   d
                     HKLMSOFTWAREMICROSOFTWINDOWS
                                                                       KeyLog Data/Exfil
                     CURRENTVERSIONRUNRUNONCE


                        Retuned Clear Text




 Significant Work. Extraordinary People. SRA.                                                         25
Concept

JINO^QMDVUCPG^OKAPMQMDV^UKLFMUQ^AWPPGLV                                 Persistence/Registry Changes
TGPQKML^PWL^PWLMLAG
                                                             a   ted
                                                          sc
                                                   Obfu
                                   Break Point

                   While(string) {                Obfuscated
                                                                        Command and Control
              Obfuscation/Crypto(string) ^ 0x02
                    clean = string[count]
                    ....
                     }
                    return clean                    Ob
                                                       fu   sc
                                                              ate
                                                                    d
HKLMSOFTWAREMICROSOFTWINDOWS
                                                                        KeyLog Data/Exfil
CURRENTVERSIONRUNRUNONCE


                        Retuned Clear Text




 Significant Work. Extraordinary People. SRA.                                                          26
Practical Example - Step 1




                                                  Obfuscated call breaks IDA XRef




Significant Work. Extraordinary People. SRA.                                        27
Practical Example - Step 1




                                                  Multiple XRef functions to suspected obfuscation




Significant Work. Extraordinary People. SRA.                                                         28
Practical Example - Step 2




                                          Jump to Crypto Function
                                                     Program jumps to Entry Point




Significant Work. Extraordinary People. SRA.                                        29
Practical Example - Step 2

                                               Set Break Point at function preamble




Significant Work. Extraordinary People. SRA.                                          30
Practical Example - Step 2


                                                 Set Break Point at function return




Significant Work. Extraordinary People. SRA.                                          31
Practical Example - Step 2

                                                          When BP is reached - obfuscated string
                                                          in ECX




Significant Work. Extraordinary People. SRA.                                                       32
Practical Example - Step 2




                                                        When second BP is reached -
                                                        deobfuscated string pushed to stack   33
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




Significant Work. Extraordinary People. SRA.                                               34
Agenda

                            •     Introduction
                            •     Disclaimer
                            •     Obfuscation
                            •     Analysis Techniques
                            •     Reversing Obfuscation
                            •     Conclusion
                            •     Q&A




Significant Work. Extraordinary People. SRA.                   35
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()




Significant Work. Extraordinary People. SRA.                                   37
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 iterations
                         Crypt(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




Significant Work. Extraordinary People. SRA.                                           38
Cheating at Code Deobfuscation




Significant Work. Extraordinary People. SRA.                             39
Cheating at Code Deobfuscation




Significant Work. Extraordinary People. SRA.                              40
Cheating at Code Deobfuscation




Significant Work. Extraordinary People. SRA.                              41
Cheating at Code Deobfuscation




Significant Work. Extraordinary People. SRA.                              42
Cheating at Code Deobfuscation




Significant Work. Extraordinary People. SRA.                              43
Hexrays DeCompiler

• One word - awesome
• Makes reversing algorithms a snap




Significant Work. Extraordinary People. SRA.                    44
Hexrays DeCompiler




Significant Work. Extraordinary People. SRA.                    45
Script to DeObfuscate




Significant Work. Extraordinary People. SRA.                       46
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




Significant Work. Extraordinary People. SRA.                           47
Bruxor




Significant Work. Extraordinary People. SRA.        48
Bruxor




Significant Work. Extraordinary People. SRA.        49
Bruxor




Significant Work. Extraordinary People. SRA.        50
Bruxor




Significant Work. Extraordinary People. SRA.        51
Bruxor




Significant Work. Extraordinary People. SRA.        52
DeXor
• Command script written for Immunity Debugger
• Pointless?
• Learning IMM API - more to come




Significant Work. Extraordinary People. SRA.         53
Significant Work. Extraordinary People. SRA.   54
Agenda

                            •     Introduction
                            •     Disclaimer
                            •     Obfuscation
                            •     Analysis Techniques
                            •     Reversing Obfuscation
                            •     Conclusion
                            •     Q&A




Significant Work. Extraordinary People. SRA.                   55
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




Significant Work. Extraordinary People. SRA.                   57
Questions?




                                                   Adam	
  Meyers
                                                Adam_meyers@sra.com
                                               Twi3er:	
  Cyber_Adam_SRA




Significant Work. Extraordinary People. SRA.                                        58

Weitere ähnliche Inhalte

Ähnlich wie Adam Meyers - RCE: Obfuscation and Communications

Fun with Application Security
Fun with Application SecurityFun with Application Security
Fun with Application SecurityBruce Abernethy
 
Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...
Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...
Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...Alex Pinto
 
Dama - Protecting Sensitive Data on a Database
Dama - Protecting Sensitive Data on a DatabaseDama - Protecting Sensitive Data on a Database
Dama - Protecting Sensitive Data on a Databasejohanswart1234
 
PENETRATION TESTING FROM A HOT TUB TIME MACHINE
PENETRATION TESTING FROM A HOT TUB TIME MACHINEPENETRATION TESTING FROM A HOT TUB TIME MACHINE
PENETRATION TESTING FROM A HOT TUB TIME MACHINEChris Gates
 
WTF is Penetration Testing v.2
WTF is Penetration Testing v.2WTF is Penetration Testing v.2
WTF is Penetration Testing v.2Scott Sutherland
 
WTF is Penetration Testing
WTF is Penetration TestingWTF is Penetration Testing
WTF is Penetration TestingScott Sutherland
 
The Rugged Way in the Cloud--Building Reliability and Security into Software
The Rugged Way in the Cloud--Building Reliability and Security into SoftwareThe Rugged Way in the Cloud--Building Reliability and Security into Software
The Rugged Way in the Cloud--Building Reliability and Security into SoftwareJames Wickett
 
Rugged Dev: Building Reliability and Security Into Software
Rugged Dev: Building Reliability and Security Into SoftwareRugged Dev: Building Reliability and Security Into Software
Rugged Dev: Building Reliability and Security Into SoftwareInnoTech
 
Hunt for the red DA
Hunt for the red DAHunt for the red DA
Hunt for the red DANeil Lines
 
Genetic Malware
Genetic MalwareGenetic Malware
Genetic MalwareOkta
 
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin FalckLuncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin FalckNorth Texas Chapter of the ISSA
 
Inception: Tips and tricks I’ve learned reversing vulnerabilities!
Inception: Tips and tricks I’ve learned reversing vulnerabilities!Inception: Tips and tricks I’ve learned reversing vulnerabilities!
Inception: Tips and tricks I’ve learned reversing vulnerabilities!Nelson Brito
 
How to Build Your Own Physical Pentesting Go-bag
How to Build Your Own Physical Pentesting Go-bagHow to Build Your Own Physical Pentesting Go-bag
How to Build Your Own Physical Pentesting Go-bagBeau Bullock
 
Sql injection to enterprise Owned - K.K. Mookhey
Sql injection to enterprise Owned  - K.K. Mookhey Sql injection to enterprise Owned  - K.K. Mookhey
Sql injection to enterprise Owned - K.K. Mookhey OWASP-Qatar Chapter
 
Finding Needles in Haystacks (The Size of Countries)
Finding Needles in Haystacks (The Size of Countries)Finding Needles in Haystacks (The Size of Countries)
Finding Needles in Haystacks (The Size of Countries)packetloop
 
RightScale Webinar: Security Monitoring in the Cloud: How RightScale Does It
RightScale Webinar: Security Monitoring in the Cloud: How RightScale Does ItRightScale Webinar: Security Monitoring in the Cloud: How RightScale Does It
RightScale Webinar: Security Monitoring in the Cloud: How RightScale Does ItRightScale
 
SECURITY OPERATION CENTER CONTENT.pptx
SECURITY OPERATION CENTER CONTENT.pptxSECURITY OPERATION CENTER CONTENT.pptx
SECURITY OPERATION CENTER CONTENT.pptxFarzanMansoor1
 
Risk management and auditing
Risk management and auditingRisk management and auditing
Risk management and auditingDorothea Salo
 

Ähnlich wie Adam Meyers - RCE: Obfuscation and Communications (20)

Fun with Application Security
Fun with Application SecurityFun with Application Security
Fun with Application Security
 
Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...
Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...
Secure Because Math: A Deep-Dive on Machine Learning-Based Monitoring (#Secur...
 
Dama - Protecting Sensitive Data on a Database
Dama - Protecting Sensitive Data on a DatabaseDama - Protecting Sensitive Data on a Database
Dama - Protecting Sensitive Data on a Database
 
PENETRATION TESTING FROM A HOT TUB TIME MACHINE
PENETRATION TESTING FROM A HOT TUB TIME MACHINEPENETRATION TESTING FROM A HOT TUB TIME MACHINE
PENETRATION TESTING FROM A HOT TUB TIME MACHINE
 
WTF is Penetration Testing v.2
WTF is Penetration Testing v.2WTF is Penetration Testing v.2
WTF is Penetration Testing v.2
 
WTF is Penetration Testing
WTF is Penetration TestingWTF is Penetration Testing
WTF is Penetration Testing
 
The Rugged Way in the Cloud--Building Reliability and Security into Software
The Rugged Way in the Cloud--Building Reliability and Security into SoftwareThe Rugged Way in the Cloud--Building Reliability and Security into Software
The Rugged Way in the Cloud--Building Reliability and Security into Software
 
Rugged Dev: Building Reliability and Security Into Software
Rugged Dev: Building Reliability and Security Into SoftwareRugged Dev: Building Reliability and Security Into Software
Rugged Dev: Building Reliability and Security Into Software
 
Hunt for the red DA
Hunt for the red DAHunt for the red DA
Hunt for the red DA
 
Genetic Malware
Genetic MalwareGenetic Malware
Genetic Malware
 
Genetic Malware
Genetic MalwareGenetic Malware
Genetic Malware
 
sourabh_sipPPT.pptx
sourabh_sipPPT.pptxsourabh_sipPPT.pptx
sourabh_sipPPT.pptx
 
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin FalckLuncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin Falck
 
Inception: Tips and tricks I’ve learned reversing vulnerabilities!
Inception: Tips and tricks I’ve learned reversing vulnerabilities!Inception: Tips and tricks I’ve learned reversing vulnerabilities!
Inception: Tips and tricks I’ve learned reversing vulnerabilities!
 
How to Build Your Own Physical Pentesting Go-bag
How to Build Your Own Physical Pentesting Go-bagHow to Build Your Own Physical Pentesting Go-bag
How to Build Your Own Physical Pentesting Go-bag
 
Sql injection to enterprise Owned - K.K. Mookhey
Sql injection to enterprise Owned  - K.K. Mookhey Sql injection to enterprise Owned  - K.K. Mookhey
Sql injection to enterprise Owned - K.K. Mookhey
 
Finding Needles in Haystacks (The Size of Countries)
Finding Needles in Haystacks (The Size of Countries)Finding Needles in Haystacks (The Size of Countries)
Finding Needles in Haystacks (The Size of Countries)
 
RightScale Webinar: Security Monitoring in the Cloud: How RightScale Does It
RightScale Webinar: Security Monitoring in the Cloud: How RightScale Does ItRightScale Webinar: Security Monitoring in the Cloud: How RightScale Does It
RightScale Webinar: Security Monitoring in the Cloud: How RightScale Does It
 
SECURITY OPERATION CENTER CONTENT.pptx
SECURITY OPERATION CENTER CONTENT.pptxSECURITY OPERATION CENTER CONTENT.pptx
SECURITY OPERATION CENTER CONTENT.pptx
 
Risk management and auditing
Risk management and auditingRisk management and auditing
Risk management and auditing
 

Mehr von Source Conference

Extracting Forensic Information From Zeus Derivatives
Extracting Forensic Information From Zeus DerivativesExtracting Forensic Information From Zeus Derivatives
Extracting Forensic Information From Zeus DerivativesSource Conference
 
How to Like Social Media Network Security
How to Like Social Media Network SecurityHow to Like Social Media Network Security
How to Like Social Media Network SecuritySource Conference
 
Wfuzz para Penetration Testers
Wfuzz para Penetration TestersWfuzz para Penetration Testers
Wfuzz para Penetration TestersSource Conference
 
Security Goodness with Ruby on Rails
Security Goodness with Ruby on RailsSecurity Goodness with Ruby on Rails
Security Goodness with Ruby on RailsSource Conference
 
Securty Testing For RESTful Applications
Securty Testing For RESTful ApplicationsSecurty Testing For RESTful Applications
Securty Testing For RESTful ApplicationsSource Conference
 
Men in the Server Meet the Man in the Browser
Men in the Server Meet the Man in the BrowserMen in the Server Meet the Man in the Browser
Men in the Server Meet the Man in the BrowserSource Conference
 
Advanced Data Exfiltration The Way Q Would Have Done It
Advanced Data Exfiltration The Way Q Would Have Done ItAdvanced Data Exfiltration The Way Q Would Have Done It
Advanced Data Exfiltration The Way Q Would Have Done ItSource Conference
 
Adapting To The Age Of Anonymous
Adapting To The Age Of AnonymousAdapting To The Age Of Anonymous
Adapting To The Age Of AnonymousSource Conference
 
Are Agile And Secure Development Mutually Exclusive?
Are Agile And Secure Development Mutually Exclusive?Are Agile And Secure Development Mutually Exclusive?
Are Agile And Secure Development Mutually Exclusive?Source Conference
 
Advanced (persistent) binary planting
Advanced (persistent) binary plantingAdvanced (persistent) binary planting
Advanced (persistent) binary plantingSource Conference
 
Legal/technical strategies addressing data risks as perimeter shifts to Cloud
Legal/technical strategies addressing data risks as perimeter shifts to CloudLegal/technical strategies addressing data risks as perimeter shifts to Cloud
Legal/technical strategies addressing data risks as perimeter shifts to CloudSource Conference
 
Who should the security team hire next?
Who should the security team hire next?Who should the security team hire next?
Who should the security team hire next?Source Conference
 
The Latest Developments in Computer Crime Law
The Latest Developments in Computer Crime LawThe Latest Developments in Computer Crime Law
The Latest Developments in Computer Crime LawSource Conference
 
How To: Find The Right Amount Of Security Spend
How To: Find The Right Amount Of Security SpendHow To: Find The Right Amount Of Security Spend
How To: Find The Right Amount Of Security SpendSource Conference
 
Everything you should already know about MS-SQL post-exploitation
Everything you should already know about MS-SQL post-exploitationEverything you should already know about MS-SQL post-exploitation
Everything you should already know about MS-SQL post-exploitationSource Conference
 
Reputation Digital Vaccine: Reinventing Internet Blacklists
Reputation Digital Vaccine: Reinventing Internet BlacklistsReputation Digital Vaccine: Reinventing Internet Blacklists
Reputation Digital Vaccine: Reinventing Internet BlacklistsSource Conference
 

Mehr von Source Conference (20)

Million Browser Botnet
Million Browser BotnetMillion Browser Botnet
Million Browser Botnet
 
Extracting Forensic Information From Zeus Derivatives
Extracting Forensic Information From Zeus DerivativesExtracting Forensic Information From Zeus Derivatives
Extracting Forensic Information From Zeus Derivatives
 
How to Like Social Media Network Security
How to Like Social Media Network SecurityHow to Like Social Media Network Security
How to Like Social Media Network Security
 
Wfuzz para Penetration Testers
Wfuzz para Penetration TestersWfuzz para Penetration Testers
Wfuzz para Penetration Testers
 
Security Goodness with Ruby on Rails
Security Goodness with Ruby on RailsSecurity Goodness with Ruby on Rails
Security Goodness with Ruby on Rails
 
Securty Testing For RESTful Applications
Securty Testing For RESTful ApplicationsSecurty Testing For RESTful Applications
Securty Testing For RESTful Applications
 
Esteganografia
EsteganografiaEsteganografia
Esteganografia
 
Men in the Server Meet the Man in the Browser
Men in the Server Meet the Man in the BrowserMen in the Server Meet the Man in the Browser
Men in the Server Meet the Man in the Browser
 
Advanced Data Exfiltration The Way Q Would Have Done It
Advanced Data Exfiltration The Way Q Would Have Done ItAdvanced Data Exfiltration The Way Q Would Have Done It
Advanced Data Exfiltration The Way Q Would Have Done It
 
Adapting To The Age Of Anonymous
Adapting To The Age Of AnonymousAdapting To The Age Of Anonymous
Adapting To The Age Of Anonymous
 
Are Agile And Secure Development Mutually Exclusive?
Are Agile And Secure Development Mutually Exclusive?Are Agile And Secure Development Mutually Exclusive?
Are Agile And Secure Development Mutually Exclusive?
 
Advanced (persistent) binary planting
Advanced (persistent) binary plantingAdvanced (persistent) binary planting
Advanced (persistent) binary planting
 
Legal/technical strategies addressing data risks as perimeter shifts to Cloud
Legal/technical strategies addressing data risks as perimeter shifts to CloudLegal/technical strategies addressing data risks as perimeter shifts to Cloud
Legal/technical strategies addressing data risks as perimeter shifts to Cloud
 
Who should the security team hire next?
Who should the security team hire next?Who should the security team hire next?
Who should the security team hire next?
 
The Latest Developments in Computer Crime Law
The Latest Developments in Computer Crime LawThe Latest Developments in Computer Crime Law
The Latest Developments in Computer Crime Law
 
JSF Security
JSF SecurityJSF Security
JSF Security
 
How To: Find The Right Amount Of Security Spend
How To: Find The Right Amount Of Security SpendHow To: Find The Right Amount Of Security Spend
How To: Find The Right Amount Of Security Spend
 
Everything you should already know about MS-SQL post-exploitation
Everything you should already know about MS-SQL post-exploitationEverything you should already know about MS-SQL post-exploitation
Everything you should already know about MS-SQL post-exploitation
 
Keynote
KeynoteKeynote
Keynote
 
Reputation Digital Vaccine: Reinventing Internet Blacklists
Reputation Digital Vaccine: Reinventing Internet BlacklistsReputation Digital Vaccine: Reinventing Internet Blacklists
Reputation Digital Vaccine: Reinventing Internet Blacklists
 

Adam Meyers - RCE: Obfuscation and Communications

  • 1. RCE: Obfuscation and Communications Adam Meyers - SRA International Significant Work. Extraordinary People. SRA.
  • 2. Agenda • Introduction • Disclaimer • Obfuscation • Analysis Techniques • Reversing Obfuscation • Conclusion • Q&A Significant Work. Extraordinary People. SRA. 2
  • 3. 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 Significant Work. Extraordinary People. SRA. 3
  • 4. 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 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.com City: Piura Hometown: Piura Significant Work. Extraordinary People. SRA. 4
  • 5. Compliance Angry Birds lulz Cyberwar APT Significant Work. Extraordinary People. SRA. 5
  • 6. Agenda • Introduction • Disclaimer • Obfuscation • Analysis Techniques • Reversing Obfuscation • Conclusion • Q&A Significant Work. Extraordinary People. SRA. 6
  • 7. 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. Significant Work. Extraordinary People. SRA. 7
  • 8. Agenda • Introduction • Disclaimer • Obfuscation • Dynamic Techniques • Static Techniques • Reversing Obfuscation • Conclusion • Q&A Significant Work. Extraordinary People. SRA. 8
  • 9. 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 Significant Work. Extraordinary People. SRA. 9
  • 10. 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) Significant Work. Extraordinary People. SRA. 10
  • 11. Obfuscation Math • Mono-Alphabetic Substitution – “Caesar Cipher” || “Shift Cipher” Key http://en.wikipedia.org/wiki/Caesar_cipher • eXlusive OR ⊕/^ – Logic operation “one or the other, never both” – Provides quick obfuscation Clear Text • 1⊕0=1 • ‘a’ ⊕ 1 = ‘`’ – Used as an operator in cryptography • Poly-alphabetic substitution – numerous substitution alphabets – Vigenère Square Significant Work. Extraordinary People. SRA. 11
  • 12. 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 Significant Work. Extraordinary People. SRA. 12
  • 13. 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.
  • 14. 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) • Call Obfuscation { FARPROC obfunc; obfunc = GetProcAddress(“MessageBoxA”, LoadlibraryA (“user32.dll”)); obfunc(0,”test”,”Obfuscate World”,0); } • 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 Significant Work. Extraordinary People. SRA. 14
  • 15. 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... Significant Work. Extraordinary People. SRA. 15
  • 16. 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 Significant Work. Extraordinary People. SRA. 16
  • 17. 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 Significant Work. Extraordinary People. SRA. 17
  • 18. Agenda • Introduction • Disclaimer • Obfuscation • Analysis Techniques • Reversing Obfuscation • Conclusion • Q&A Significant Work. Extraordinary People. SRA. 18
  • 19. 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.
  • 20. 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 Significant Work. Extraordinary People. SRA. 20
  • 21. 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.
  • 22. 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 Significant Work. Extraordinary People. SRA. 22
  • 23. Obfuscated Code Significant Work. Extraordinary People. SRA. 23
  • 24. 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 Significant Work. Extraordinary People. SRA. 24
  • 25. Concept Persistence/Registry Changes a ted u sc JINO^QMDVUCPG^OKAPMQMDV^UKLFMUQ^AWPPGLV bf O TGPQKML^PWL^PWLMLAG Obfuscated Command and Control Obfuscation/Crypto(string) Ob fu sc ate d HKLMSOFTWAREMICROSOFTWINDOWS KeyLog Data/Exfil CURRENTVERSIONRUNRUNONCE Retuned Clear Text Significant Work. Extraordinary People. SRA. 25
  • 26. Concept JINO^QMDVUCPG^OKAPMQMDV^UKLFMUQ^AWPPGLV Persistence/Registry Changes TGPQKML^PWL^PWLMLAG a ted sc Obfu Break Point While(string) { Obfuscated Command and Control Obfuscation/Crypto(string) ^ 0x02 clean = string[count] .... } return clean Ob fu sc ate d HKLMSOFTWAREMICROSOFTWINDOWS KeyLog Data/Exfil CURRENTVERSIONRUNRUNONCE Retuned Clear Text Significant Work. Extraordinary People. SRA. 26
  • 27. Practical Example - Step 1 Obfuscated call breaks IDA XRef Significant Work. Extraordinary People. SRA. 27
  • 28. Practical Example - Step 1 Multiple XRef functions to suspected obfuscation Significant Work. Extraordinary People. SRA. 28
  • 29. Practical Example - Step 2 Jump to Crypto Function Program jumps to Entry Point Significant Work. Extraordinary People. SRA. 29
  • 30. Practical Example - Step 2 Set Break Point at function preamble Significant Work. Extraordinary People. SRA. 30
  • 31. Practical Example - Step 2 Set Break Point at function return Significant Work. Extraordinary People. SRA. 31
  • 32. Practical Example - Step 2 When BP is reached - obfuscated string in ECX Significant Work. Extraordinary People. SRA. 32
  • 33. Practical Example - Step 2 When second BP is reached - deobfuscated string pushed to stack 33 Significant Work. Extraordinary People. SRA.
  • 34. 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 Significant Work. Extraordinary People. SRA. 34
  • 35. Agenda • Introduction • Disclaimer • Obfuscation • Analysis Techniques • Reversing Obfuscation • Conclusion • Q&A Significant Work. Extraordinary People. SRA. 35
  • 36. 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.
  • 37. 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() Significant Work. Extraordinary People. SRA. 37
  • 38. 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 iterations Crypt(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 Significant Work. Extraordinary People. SRA. 38
  • 39. Cheating at Code Deobfuscation Significant Work. Extraordinary People. SRA. 39
  • 40. Cheating at Code Deobfuscation Significant Work. Extraordinary People. SRA. 40
  • 41. Cheating at Code Deobfuscation Significant Work. Extraordinary People. SRA. 41
  • 42. Cheating at Code Deobfuscation Significant Work. Extraordinary People. SRA. 42
  • 43. Cheating at Code Deobfuscation Significant Work. Extraordinary People. SRA. 43
  • 44. Hexrays DeCompiler • One word - awesome • Makes reversing algorithms a snap Significant Work. Extraordinary People. SRA. 44
  • 45. Hexrays DeCompiler Significant Work. Extraordinary People. SRA. 45
  • 46. Script to DeObfuscate Significant Work. Extraordinary People. SRA. 46
  • 47. 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 Significant Work. Extraordinary People. SRA. 47
  • 53. DeXor • Command script written for Immunity Debugger • Pointless? • Learning IMM API - more to come Significant Work. Extraordinary People. SRA. 53
  • 55. Agenda • Introduction • Disclaimer • Obfuscation • Analysis Techniques • Reversing Obfuscation • Conclusion • Q&A Significant Work. Extraordinary People. SRA. 55
  • 56. 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.
  • 57. Agenda • Introduction • Disclaimer • Obfuscation • Analysis Techniques • Reversing Obfuscation • Conclusion • Q&A Significant Work. Extraordinary People. SRA. 57
  • 58. Questions? Adam  Meyers Adam_meyers@sra.com Twi3er:  Cyber_Adam_SRA Significant Work. Extraordinary People. SRA. 58