SlideShare a Scribd company logo
1 of 31
Advanced Malware Analysis Training Series




        www.SecurityXploded.com
Disclaimer
The Content, Demonstration, Source Code and Programs presented here is "AS IS" without
any warranty or conditions of any kind. Also the views/ideas/knowledge expressed here are
solely of the trainer’s only and nothing to do with the company or the organization in which
the trainer is currently working.

However in no circumstances neither the Trainer nor SecurityXploded is responsible for any
damage or loss caused due to use or misuse of the information presented here.




                                        www.SecurityXploded.com
Acknowledgement
 Special thanks to Null community for their extended support and co-operation.


 Special thanks to ThoughtWorks for the beautiful venue.


 Thanks to all the trainers who have devoted their precious time and countless hours to make it
  happen.




                                        www.SecurityXploded.com
Advanced Malware Analysis Training

This presentation is part of our Advanced Malware Analysis Training program. Currently it
is delivered only during our local meets for FREE of cost.




For complete details of this course, visit our Security Training page.

                                          www.SecurityXploded.com
Who am I?
Amit Malik
     Member, SecurityXploded
     Security Researcher, McAfee Labs
     Reversing, Malware Analysis, Exploit Analysis/Development etc.
     E-mail: m.amit30@gmail.com




                                     www.SecurityXploded.com
Content
   Bots and Botnets
   Important point #1 (Registers etc.)
   Important point #2 (Procedure calls etc.)
   Important point #3 (code injection etc.)
   Case Study: Waledac Botnet
     Waledac C&C communication
     Rapid Reversing Techniques
     Waledac Analysis (C&C)
     Summary



                                               www.SecurityXploded.com
Bots and Botnets
   What is a Bot and Botnet?

   Commercialized and Infrastructure based malware class.

   C&C – Command and Control

   Centralized C&C communication

   Distributed C&C communication (e.g: P2P)

   Some Popular Bots

     Kehlios, Carberp, Zeus, Nittol, Alureon, Maazben, Waledac etc.




                                         www.SecurityXploded.com
Important point #1
   Pay very close attention to the following registers in the code.

     Fs:[0]

     Fs:[18]

     Fs:[30]

   When function returns check EAX register

   Check ECX when you are in loop

   ESI and EDI locations during string copy ops.




                                             www.SecurityXploded.com
Fs:[0] (SEH)
   Fs:[0] holds SEH (Structured Exception Handler) address
   Some malicious programs abuses SEH in order to fool novice reverse engineer.
     Example code

       Mov eax, some address
       Push eax
       Push dword ptr fs:[0]
       Mov fs:[0], esp ; EAX addr now becomes SEH.
       Some invalid instruction that generate an exception and transfer the execution to the
         address (which was in EAX).


                                           www.SecurityXploded.com
Fs:[18] and Fs:[30]
   Fs:[18] holds TEB (Thread Environment Block) Address

     From TEB structure we can access stack base, stack end and PEB address.

     Use dt nt!_TEB –r1 command in windbg to see the TEB structure.

   Fs:[30] holds PEB (Process Environment Block) Address

     From PEB we can access some key information like process heaps, loaded modules,
      some debugger detection flags.

     Use dt nt!_PEB –r2 command in windbg to see the PEB structure




                                         www.SecurityXploded.com
Fs:[18] and fs:[30] example codes
   Loaded modules enumeration (Extremely important) – IAT rebuilding, get function
    addresses etc.




   Debugger detection




                                         www.SecurityXploded.com
Important point #2
   Asynchronous procedure calls (APC)

     IRQL (Interrupt Request Level) 1

     Used by malicious softwares to fool beginner reverse engineers

     WriteFileEx, ReadFileEx, SetWaitableTimer,

     SetWaitableTimerEx, QueueUserAPC API can be used to execute code via APC

     http://msdn.microsoft.com/en-us/library/windows/desktop/ms681951(v=vs.85).aspx




                                          www.SecurityXploded.com
E.g. ReadFileEx
   Reads data from the specified file or input/output (I/O) device. It reports its completion
    status asynchronously, calling the specified completion routine when reading is
    completed or cancelled and the calling thread is in an alertable wait state.

   BOOL WINAPI ReadFileEx( _In_            HANDLE hFile, _Out_opt_ LPVOID lpBuffer,
    _In_     DWORD nNumberOfBytesToRead, _Inout_ LPOVERLAPPED
    lpOverlapped, _In_opt_ LPOVERLAPPED_COMPLETION_ROUTINE
    lpCompletionRoutine );




                                             www.SecurityXploded.com
Role of SleepEx and Similar APIs
   Suspends the current thread until the specified condition is met. Execution resumes when
    one of the following occurs:
     An I/O completion callback function is called.
     An asynchronous procedure call (APC) is queued to the thread.
     The time-out interval elapses.
     SleepEx, SignalObjectAndWait,MsgWaitForMultipleObjectsEx, WaitForMultipleObjectsEx,
       or WaitForSingleObjectEx
 DWORD WINAPI SleepEx( _In_ DWORD dwMilliseconds, _In_ BOOL bAlertable
  );
 If the parameter is TRUE and the thread that called this function is the same thread that
  called the extended I/O function (ReadFileEx or WriteFileEx), the function returns
  when either the time-out period has elapsed or when an I/O completion callback function
  occurs. If an I/O completion callback occurs, the I/O completion function is called. If an
  APC is queued to the thread (QueueUserAPC), the function returns when either the
  timer-out period has elapsed or when the APC function is called.
                                                www.SecurityXploded.com
Important point #3
   Code Injection – Very well explained in our couple of articles, check article section at
    securityxploded.
   Malwares often inject code to some legitimate processes to bypass host based security
    solutions or to minimize the footprints
   Injected code can be direct executable code or can be a DLL(Dynamic Link Library).
   OpenProcess, VirtualAllocEx, WriteProcessMemory, CreateRemoteThread,
    NtCreateThreadEx, ZwCreateThread, APC APIs
   Services – CreateService, StartService.
   New Process – CreateProcessA/W, ShellExecute/Ex, WinExec etc.
   **Process Hollowing and variants, In-Memory execution, Packers etc.


                                               www.SecurityXploded.com
Case Study: Waledac botnet
   Popular e-mail spam botnet

   Taken down by microsoft in march 2010

   Around 90,000 computers were infected

   Capable to send 1.5 billion spam messages a day. (1% of the total global spam volume)

   http://en.wikipedia.org/wiki/Waledac_botnet

   In this presentation we will focus only on C&C communication




                                          www.SecurityXploded.com
Waledac C&C Communication
   Bzip, AES, base64 encryption/encoding algorithms used in the network communication

   Custom header field in HTTP protocol

   P2P style communication over HTTP protocol




                                           www.SecurityXploded.com
Waledac C&C Communication
   Ok, We have enough information to start our analysis

   Now our task is to

     Indentify which functions are responsible for encryption

     Identify which function is responsible for sending the request

     Identify what sent into the request (Clear Text)

   Challenge
     Lots of code (around 950 KB, ~14 MB IDB binary)
     More than 4,000 functions
     Completely unaware about the malware behaviour (code based)



                                           www.SecurityXploded.com
Rapid Reversing Techniques
   Tracing - most common approach
     Instruction based tracing
      ○ Pros
         Complete flow including branching /decisions made by program during execution
         Powerful, given time and space provides solid results
      ○ Cons
         Very slow (each instruction logging)
         Huge output, difficult to analyze
         For huge code base nearly impossible
     Functions call based tracing
      ○ Pros
         Functions call flow during execution
         Provides fair details about the binary
      ○ Cons
         Not very helpful in malware analysis (packers, run rime executable code generation etc.)




                                                     www.SecurityXploded.com
Rapid Reversing Techniques
     API call based tracing
       ○ Pros
           Can log all API calls even from newly allocated regions i.e. run rime unpacked code or run rime
           generated code
          Provides good details about the malware and system interaction
          Excellent for malware analysis, more advanced and sophisticated techniques can be used like API
           call clustering, API call based execution path diffing, Automated unpacking etc.
       ○ Cons
          Efficiency and flexibility is based on the actual tracing software otherwise it can be very painful
           like instruction based tracing (hook hopping, API calls in big loops etc.)


   These techniques are often used with conditions after a specific point/address




                                                   www.SecurityXploded.com
Waledac Analysis (C&C)
   Our encryption routines should be near this code segment. We will look into function call flow of
    the malware upto this code so that we can get better understanding of the nearby code.




                                           www.SecurityXploded.com
Continue...
   In snapshot we see following things

     Calls to LocalAlloc API (Another point confirming encryption routines near the code)

     Call to HttpSendRequestA API (send the encrypted payload to C&C server)

   Now identify the functions that are calling the above APIs, How ?

   Static cross references doesn’t provide much details so we will use tracing.

   * I am not going to share my tracing tools so please don’t make request for them .




                                            www.SecurityXploded.com
Continue...
   Below snapshot is from single shot function call ( and partial API) tracing of the malware.




   We can mark sub_44DCCC as start point, because sub_408CC9 is directly calling our APIs.


                                           www.SecurityXploded.com
Tracing Function SUB_44DCCC
   Full function and API trace of the function sub_44DCCC.




   Inside sub_44DCCC we see an another call (zoom-next slide) to a function which seems to hold
    60% of code for sub_44DCCC and also calls LocalAlloc API, so that is our function.

                                         www.SecurityXploded.com
Important Function
   Put breakpoint on this function, run, put breakpoint on LocalAlloc, use single stepping
    (F8) and wait for LocalAlloc call.




 Monitor LocalAlloc returned pointer, and keep single stepping on. Eventually you will
  see the answer of all the questions.
 So pretty simple huh?? Try it yourself. 



                                           www.SecurityXploded.com
C&C Payload (Clear Text)
   Waledac uses xml style in its payload as we can see in the below snapshot.




   However to know the meaning and purpose of this payload we need more analysis and
    threat intelligence, but most of the time it will suffice. 




                                           www.SecurityXploded.com
Demonstration


https://vimeo.com/57755964




           www.SecurityXploded.com
Summary
   Complete analysis and threat report can take weeks to months, depending on the threat.

   Tracing methods are extremely helpful in large code base malwares. Actually tracing is
    much more powerful, think about taint analysis.

   Reverse Engineering Automation is a fascinating and useful study area.

   VERA (ether dependent), Zynamics BinNavi (not very useful for malware analysis) etc.
    can be used to accelerate reverse engineering but they are not very flexible. (inclusion,
    exclusion, trace from one node to another node etc.)

   I know it’s a lots of load on your brain but try to understand the malware yourself.

   Malware MD5 : 0A0E0AD7175B17A5D6AFFC73279BDA8B


                                            www.SecurityXploded.com
Single Shot Function Call Trace
   In our analysis we discussed only the marked area in this snapshot.




   This trace still not covering entire malware calls (because c&c is down)

                                           www.SecurityXploded.com
Reference
Complete Reference Guide for Advanced Malware Analysis Training
[Include links for all the Demos & Tools]




                                            www.SecurityXploded.com
Thank You !



www.SecurityXploded.com




       www.SecurityXploded.com

More Related Content

What's hot

Primer on password security
Primer on password securityPrimer on password security
Primer on password securitysecurityxploded
 
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2securityxploded
 
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...securityxploded
 
Advanced Malware Analysis Training Session 7 - Malware Memory Forensics
Advanced Malware Analysis Training Session 7  - Malware Memory ForensicsAdvanced Malware Analysis Training Session 7  - Malware Memory Forensics
Advanced Malware Analysis Training Session 7 - Malware Memory Forensicssecurityxploded
 
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 -  Advanced Malware AnalysisReversing & Malware Analysis Training Part 9 -  Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysissecurityxploded
 
Reversing & Malware Analysis Training Part 13 - Future Roadmap
Reversing & Malware Analysis Training Part 13 - Future RoadmapReversing & Malware Analysis Training Part 13 - Future Roadmap
Reversing & Malware Analysis Training Part 13 - Future Roadmapsecurityxploded
 
Advanced Malware Analysis Training Session 4 - Anti-Analysis Techniques
Advanced Malware Analysis Training Session 4 - Anti-Analysis TechniquesAdvanced Malware Analysis Training Session 4 - Anti-Analysis Techniques
Advanced Malware Analysis Training Session 4 - Anti-Analysis Techniquessecurityxploded
 
Advanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to AndroidAdvanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to Androidsecurityxploded
 
Advanced malware analysis training session5 reversing automation
Advanced malware analysis training session5 reversing automationAdvanced malware analysis training session5 reversing automation
Advanced malware analysis training session5 reversing automationCysinfo Cyber Security Community
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Cysinfo Cyber Security Community
 
Application Virtualization
Application VirtualizationApplication Virtualization
Application Virtualizationsecurityxploded
 
Reversing malware analysis training part6 practical reversing
Reversing malware analysis training part6 practical reversingReversing malware analysis training part6 practical reversing
Reversing malware analysis training part6 practical reversingCysinfo Cyber Security Community
 
Advanced malware analysis training session 7 malware memory forensics
Advanced malware analysis training session 7 malware memory forensicsAdvanced malware analysis training session 7 malware memory forensics
Advanced malware analysis training session 7 malware memory forensicsCysinfo Cyber Security Community
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basicssecurityxploded
 
Reversing malware analysis training part11 exploit development advanced
Reversing malware analysis training part11 exploit development advancedReversing malware analysis training part11 exploit development advanced
Reversing malware analysis training part11 exploit development advancedCysinfo Cyber Security Community
 
Hunting Rootkit From the Dark Corners Of Memory
Hunting Rootkit From the Dark Corners Of MemoryHunting Rootkit From the Dark Corners Of Memory
Hunting Rootkit From the Dark Corners Of Memorysecurityxploded
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)securityxploded
 
Reversing malware analysis training part3 windows pefile formatbasics
Reversing malware analysis training part3 windows pefile formatbasicsReversing malware analysis training part3 windows pefile formatbasics
Reversing malware analysis training part3 windows pefile formatbasicsCysinfo Cyber Security Community
 

What's hot (20)

Primer on password security
Primer on password securityPrimer on password security
Primer on password security
 
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
 
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
 
Advanced Malware Analysis Training Session 7 - Malware Memory Forensics
Advanced Malware Analysis Training Session 7  - Malware Memory ForensicsAdvanced Malware Analysis Training Session 7  - Malware Memory Forensics
Advanced Malware Analysis Training Session 7 - Malware Memory Forensics
 
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 -  Advanced Malware AnalysisReversing & Malware Analysis Training Part 9 -  Advanced Malware Analysis
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
 
Reversing & Malware Analysis Training Part 13 - Future Roadmap
Reversing & Malware Analysis Training Part 13 - Future RoadmapReversing & Malware Analysis Training Part 13 - Future Roadmap
Reversing & Malware Analysis Training Part 13 - Future Roadmap
 
Advanced Malware Analysis Training Session 4 - Anti-Analysis Techniques
Advanced Malware Analysis Training Session 4 - Anti-Analysis TechniquesAdvanced Malware Analysis Training Session 4 - Anti-Analysis Techniques
Advanced Malware Analysis Training Session 4 - Anti-Analysis Techniques
 
Advanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to AndroidAdvanced Malware Analysis Training Session 8 - Introduction to Android
Advanced Malware Analysis Training Session 8 - Introduction to Android
 
Advanced malware analysis training session5 reversing automation
Advanced malware analysis training session5 reversing automationAdvanced malware analysis training session5 reversing automation
Advanced malware analysis training session5 reversing automation
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1
 
Application Virtualization
Application VirtualizationApplication Virtualization
Application Virtualization
 
Reversing malware analysis training part6 practical reversing
Reversing malware analysis training part6 practical reversingReversing malware analysis training part6 practical reversing
Reversing malware analysis training part6 practical reversing
 
Advanced malware analysis training session 7 malware memory forensics
Advanced malware analysis training session 7 malware memory forensicsAdvanced malware analysis training session 7 malware memory forensics
Advanced malware analysis training session 7 malware memory forensics
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
 
Reversing malware analysis training part11 exploit development advanced
Reversing malware analysis training part11 exploit development advancedReversing malware analysis training part11 exploit development advanced
Reversing malware analysis training part11 exploit development advanced
 
Hunting Rootkit From the Dark Corners Of Memory
Hunting Rootkit From the Dark Corners Of MemoryHunting Rootkit From the Dark Corners Of Memory
Hunting Rootkit From the Dark Corners Of Memory
 
Anatomy of Exploit Kits
Anatomy of Exploit KitsAnatomy of Exploit Kits
Anatomy of Exploit Kits
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)Reversing & Malware Analysis Training Part 6 -  Practical Reversing (I)
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
 
Reversing malware analysis training part3 windows pefile formatbasics
Reversing malware analysis training part3 windows pefile formatbasicsReversing malware analysis training part3 windows pefile formatbasics
Reversing malware analysis training part3 windows pefile formatbasics
 
Dissecting Android APK
Dissecting Android APKDissecting Android APK
Dissecting Android APK
 

Similar to Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1

The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022lior mazor
 
Reversing & malware analysis training part 10 exploit development basics
Reversing & malware analysis training part 10   exploit development basicsReversing & malware analysis training part 10   exploit development basics
Reversing & malware analysis training part 10 exploit development basicsAbdulrahman Bassam
 
Reversing & malware analysis training part 11 exploit development advanced
Reversing & malware analysis training part 11   exploit development advancedReversing & malware analysis training part 11   exploit development advanced
Reversing & malware analysis training part 11 exploit development advancedAbdulrahman Bassam
 
Native client (Евгений Эльцин)
Native client (Евгений Эльцин)Native client (Евгений Эльцин)
Native client (Евгений Эльцин)Ontico
 
Fast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility PluginFast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility PluginTakahiro Haruyama
 
VB2013 - Security Research and Development Framework
VB2013 - Security Research and Development FrameworkVB2013 - Security Research and Development Framework
VB2013 - Security Research and Development FrameworkAmr Thabet
 
DEFCON 21: EDS: Exploitation Detection System WP
DEFCON 21: EDS: Exploitation Detection System WPDEFCON 21: EDS: Exploitation Detection System WP
DEFCON 21: EDS: Exploitation Detection System WPAmr Thabet
 
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware AnalysisInside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware AnalysisChong-Kuan Chen
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitDimitry Snezhkov
 
DEFCON 21: EDS: Exploitation Detection System Slides
DEFCON 21: EDS: Exploitation Detection System SlidesDEFCON 21: EDS: Exploitation Detection System Slides
DEFCON 21: EDS: Exploitation Detection System SlidesAmr Thabet
 
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It PosesEnterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It PosesAlex Senkevitch
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazyMichael Boman
 
44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON
 
Penetrating Windows 8 with syringe utility
Penetrating Windows 8 with syringe utilityPenetrating Windows 8 with syringe utility
Penetrating Windows 8 with syringe utilityIOSR Journals
 
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...Felipe Prado
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsCaptain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsenSilo
 

Similar to Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1 (20)

AntiRE en Masse
AntiRE en MasseAntiRE en Masse
AntiRE en Masse
 
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
 
Reversing & malware analysis training part 10 exploit development basics
Reversing & malware analysis training part 10   exploit development basicsReversing & malware analysis training part 10   exploit development basics
Reversing & malware analysis training part 10 exploit development basics
 
Reversing & malware analysis training part 11 exploit development advanced
Reversing & malware analysis training part 11   exploit development advancedReversing & malware analysis training part 11   exploit development advanced
Reversing & malware analysis training part 11 exploit development advanced
 
Native client (Евгений Эльцин)
Native client (Евгений Эльцин)Native client (Евгений Эльцин)
Native client (Евгений Эльцин)
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
 
Fast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility PluginFast and Generic Malware Triage Using openioc_scan Volatility Plugin
Fast and Generic Malware Triage Using openioc_scan Volatility Plugin
 
VB2013 - Security Research and Development Framework
VB2013 - Security Research and Development FrameworkVB2013 - Security Research and Development Framework
VB2013 - Security Research and Development Framework
 
DEFCON 21: EDS: Exploitation Detection System WP
DEFCON 21: EDS: Exploitation Detection System WPDEFCON 21: EDS: Exploitation Detection System WP
DEFCON 21: EDS: Exploitation Detection System WP
 
Was faqs
Was faqsWas faqs
Was faqs
 
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware AnalysisInside the Matrix,How to Build Transparent Sandbox for Malware Analysis
Inside the Matrix,How to Build Transparent Sandbox for Malware Analysis
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution Toolkit
 
OIVM
OIVMOIVM
OIVM
 
DEFCON 21: EDS: Exploitation Detection System Slides
DEFCON 21: EDS: Exploitation Detection System SlidesDEFCON 21: EDS: Exploitation Detection System Slides
DEFCON 21: EDS: Exploitation Detection System Slides
 
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It PosesEnterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazy
 
44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy
 
Penetrating Windows 8 with syringe utility
Penetrating Windows 8 with syringe utilityPenetrating Windows 8 with syringe utility
Penetrating Windows 8 with syringe utility
 
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
 
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit MitigationsCaptain Hook: Pirating AVs to Bypass Exploit Mitigations
Captain Hook: Pirating AVs to Bypass Exploit Mitigations
 

More from securityxploded

Fingerprinting healthcare institutions
Fingerprinting healthcare institutionsFingerprinting healthcare institutions
Fingerprinting healthcare institutionssecurityxploded
 
Hollow Process Injection - Reversing and Investigating Malware Evasive Tactics
Hollow Process Injection - Reversing and Investigating Malware Evasive TacticsHollow Process Injection - Reversing and Investigating Malware Evasive Tactics
Hollow Process Injection - Reversing and Investigating Malware Evasive Tacticssecurityxploded
 
Malicious Client Detection Using Machine Learning
Malicious Client Detection Using Machine LearningMalicious Client Detection Using Machine Learning
Malicious Client Detection Using Machine Learningsecurityxploded
 
Understanding CryptoLocker (Ransomware) with a Case Study
Understanding CryptoLocker (Ransomware) with a Case StudyUnderstanding CryptoLocker (Ransomware) with a Case Study
Understanding CryptoLocker (Ransomware) with a Case Studysecurityxploded
 
Linux Malware Analysis using Limon Sandbox
Linux Malware Analysis using Limon SandboxLinux Malware Analysis using Limon Sandbox
Linux Malware Analysis using Limon Sandboxsecurityxploded
 
Automating Malware Analysis
Automating Malware AnalysisAutomating Malware Analysis
Automating Malware Analysissecurityxploded
 
Reverse Engineering Malware
Reverse Engineering MalwareReverse Engineering Malware
Reverse Engineering Malwaresecurityxploded
 
Partial Homomorphic Encryption
Partial Homomorphic EncryptionPartial Homomorphic Encryption
Partial Homomorphic Encryptionsecurityxploded
 
Return Address – The Silver Bullet
Return Address – The Silver BulletReturn Address – The Silver Bullet
Return Address – The Silver Bulletsecurityxploded
 
Defeating public exploit protections (EMET v5.2 and more)
Defeating public exploit protections (EMET v5.2 and more)Defeating public exploit protections (EMET v5.2 and more)
Defeating public exploit protections (EMET v5.2 and more)securityxploded
 
Hunting Ghost RAT Using Memory Forensics
Hunting Ghost RAT Using Memory ForensicsHunting Ghost RAT Using Memory Forensics
Hunting Ghost RAT Using Memory Forensicssecurityxploded
 
Malicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine LearningMalicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine Learningsecurityxploded
 
Reversing and Decrypting the Communications of APT Malware (Etumbot)
Reversing and Decrypting the Communications of APT Malware (Etumbot)Reversing and Decrypting the Communications of APT Malware (Etumbot)
Reversing and Decrypting the Communications of APT Malware (Etumbot)securityxploded
 

More from securityxploded (20)

Fingerprinting healthcare institutions
Fingerprinting healthcare institutionsFingerprinting healthcare institutions
Fingerprinting healthcare institutions
 
Hollow Process Injection - Reversing and Investigating Malware Evasive Tactics
Hollow Process Injection - Reversing and Investigating Malware Evasive TacticsHollow Process Injection - Reversing and Investigating Malware Evasive Tactics
Hollow Process Injection - Reversing and Investigating Malware Evasive Tactics
 
Buffer Overflow Attacks
Buffer Overflow AttacksBuffer Overflow Attacks
Buffer Overflow Attacks
 
Malicious Client Detection Using Machine Learning
Malicious Client Detection Using Machine LearningMalicious Client Detection Using Machine Learning
Malicious Client Detection Using Machine Learning
 
Understanding CryptoLocker (Ransomware) with a Case Study
Understanding CryptoLocker (Ransomware) with a Case StudyUnderstanding CryptoLocker (Ransomware) with a Case Study
Understanding CryptoLocker (Ransomware) with a Case Study
 
Linux Malware Analysis using Limon Sandbox
Linux Malware Analysis using Limon SandboxLinux Malware Analysis using Limon Sandbox
Linux Malware Analysis using Limon Sandbox
 
Introduction to SMPC
Introduction to SMPCIntroduction to SMPC
Introduction to SMPC
 
Breaking into hospitals
Breaking into hospitalsBreaking into hospitals
Breaking into hospitals
 
Bluetooth [in]security
Bluetooth [in]securityBluetooth [in]security
Bluetooth [in]security
 
Basic malware analysis
Basic malware analysisBasic malware analysis
Basic malware analysis
 
Automating Malware Analysis
Automating Malware AnalysisAutomating Malware Analysis
Automating Malware Analysis
 
Reverse Engineering Malware
Reverse Engineering MalwareReverse Engineering Malware
Reverse Engineering Malware
 
DLL Preloading Attack
DLL Preloading AttackDLL Preloading Attack
DLL Preloading Attack
 
Partial Homomorphic Encryption
Partial Homomorphic EncryptionPartial Homomorphic Encryption
Partial Homomorphic Encryption
 
Return Address – The Silver Bullet
Return Address – The Silver BulletReturn Address – The Silver Bullet
Return Address – The Silver Bullet
 
Defeating public exploit protections (EMET v5.2 and more)
Defeating public exploit protections (EMET v5.2 and more)Defeating public exploit protections (EMET v5.2 and more)
Defeating public exploit protections (EMET v5.2 and more)
 
Hunting Ghost RAT Using Memory Forensics
Hunting Ghost RAT Using Memory ForensicsHunting Ghost RAT Using Memory Forensics
Hunting Ghost RAT Using Memory Forensics
 
Malicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine LearningMalicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine Learning
 
MalwareNet Project
MalwareNet ProjectMalwareNet Project
MalwareNet Project
 
Reversing and Decrypting the Communications of APT Malware (Etumbot)
Reversing and Decrypting the Communications of APT Malware (Etumbot)Reversing and Decrypting the Communications of APT Malware (Etumbot)
Reversing and Decrypting the Communications of APT Malware (Etumbot)
 

Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1

  • 1. Advanced Malware Analysis Training Series www.SecurityXploded.com
  • 2. Disclaimer The Content, Demonstration, Source Code and Programs presented here is "AS IS" without any warranty or conditions of any kind. Also the views/ideas/knowledge expressed here are solely of the trainer’s only and nothing to do with the company or the organization in which the trainer is currently working. However in no circumstances neither the Trainer nor SecurityXploded is responsible for any damage or loss caused due to use or misuse of the information presented here. www.SecurityXploded.com
  • 3. Acknowledgement  Special thanks to Null community for their extended support and co-operation.  Special thanks to ThoughtWorks for the beautiful venue.  Thanks to all the trainers who have devoted their precious time and countless hours to make it happen. www.SecurityXploded.com
  • 4. Advanced Malware Analysis Training This presentation is part of our Advanced Malware Analysis Training program. Currently it is delivered only during our local meets for FREE of cost. For complete details of this course, visit our Security Training page. www.SecurityXploded.com
  • 5. Who am I? Amit Malik  Member, SecurityXploded  Security Researcher, McAfee Labs  Reversing, Malware Analysis, Exploit Analysis/Development etc.  E-mail: m.amit30@gmail.com www.SecurityXploded.com
  • 6. Content  Bots and Botnets  Important point #1 (Registers etc.)  Important point #2 (Procedure calls etc.)  Important point #3 (code injection etc.)  Case Study: Waledac Botnet  Waledac C&C communication  Rapid Reversing Techniques  Waledac Analysis (C&C)  Summary www.SecurityXploded.com
  • 7. Bots and Botnets  What is a Bot and Botnet?  Commercialized and Infrastructure based malware class.  C&C – Command and Control  Centralized C&C communication  Distributed C&C communication (e.g: P2P)  Some Popular Bots  Kehlios, Carberp, Zeus, Nittol, Alureon, Maazben, Waledac etc. www.SecurityXploded.com
  • 8. Important point #1  Pay very close attention to the following registers in the code.  Fs:[0]  Fs:[18]  Fs:[30]  When function returns check EAX register  Check ECX when you are in loop  ESI and EDI locations during string copy ops. www.SecurityXploded.com
  • 9. Fs:[0] (SEH)  Fs:[0] holds SEH (Structured Exception Handler) address  Some malicious programs abuses SEH in order to fool novice reverse engineer.  Example code Mov eax, some address Push eax Push dword ptr fs:[0] Mov fs:[0], esp ; EAX addr now becomes SEH. Some invalid instruction that generate an exception and transfer the execution to the address (which was in EAX). www.SecurityXploded.com
  • 10. Fs:[18] and Fs:[30]  Fs:[18] holds TEB (Thread Environment Block) Address  From TEB structure we can access stack base, stack end and PEB address.  Use dt nt!_TEB –r1 command in windbg to see the TEB structure.  Fs:[30] holds PEB (Process Environment Block) Address  From PEB we can access some key information like process heaps, loaded modules, some debugger detection flags.  Use dt nt!_PEB –r2 command in windbg to see the PEB structure www.SecurityXploded.com
  • 11. Fs:[18] and fs:[30] example codes  Loaded modules enumeration (Extremely important) – IAT rebuilding, get function addresses etc.  Debugger detection www.SecurityXploded.com
  • 12. Important point #2  Asynchronous procedure calls (APC)  IRQL (Interrupt Request Level) 1  Used by malicious softwares to fool beginner reverse engineers  WriteFileEx, ReadFileEx, SetWaitableTimer,  SetWaitableTimerEx, QueueUserAPC API can be used to execute code via APC  http://msdn.microsoft.com/en-us/library/windows/desktop/ms681951(v=vs.85).aspx www.SecurityXploded.com
  • 13. E.g. ReadFileEx  Reads data from the specified file or input/output (I/O) device. It reports its completion status asynchronously, calling the specified completion routine when reading is completed or cancelled and the calling thread is in an alertable wait state.  BOOL WINAPI ReadFileEx( _In_ HANDLE hFile, _Out_opt_ LPVOID lpBuffer, _In_ DWORD nNumberOfBytesToRead, _Inout_ LPOVERLAPPED lpOverlapped, _In_opt_ LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine ); www.SecurityXploded.com
  • 14. Role of SleepEx and Similar APIs  Suspends the current thread until the specified condition is met. Execution resumes when one of the following occurs:  An I/O completion callback function is called.  An asynchronous procedure call (APC) is queued to the thread.  The time-out interval elapses.  SleepEx, SignalObjectAndWait,MsgWaitForMultipleObjectsEx, WaitForMultipleObjectsEx, or WaitForSingleObjectEx  DWORD WINAPI SleepEx( _In_ DWORD dwMilliseconds, _In_ BOOL bAlertable );  If the parameter is TRUE and the thread that called this function is the same thread that called the extended I/O function (ReadFileEx or WriteFileEx), the function returns when either the time-out period has elapsed or when an I/O completion callback function occurs. If an I/O completion callback occurs, the I/O completion function is called. If an APC is queued to the thread (QueueUserAPC), the function returns when either the timer-out period has elapsed or when the APC function is called. www.SecurityXploded.com
  • 15. Important point #3  Code Injection – Very well explained in our couple of articles, check article section at securityxploded.  Malwares often inject code to some legitimate processes to bypass host based security solutions or to minimize the footprints  Injected code can be direct executable code or can be a DLL(Dynamic Link Library).  OpenProcess, VirtualAllocEx, WriteProcessMemory, CreateRemoteThread, NtCreateThreadEx, ZwCreateThread, APC APIs  Services – CreateService, StartService.  New Process – CreateProcessA/W, ShellExecute/Ex, WinExec etc.  **Process Hollowing and variants, In-Memory execution, Packers etc. www.SecurityXploded.com
  • 16. Case Study: Waledac botnet  Popular e-mail spam botnet  Taken down by microsoft in march 2010  Around 90,000 computers were infected  Capable to send 1.5 billion spam messages a day. (1% of the total global spam volume)  http://en.wikipedia.org/wiki/Waledac_botnet  In this presentation we will focus only on C&C communication www.SecurityXploded.com
  • 17. Waledac C&C Communication  Bzip, AES, base64 encryption/encoding algorithms used in the network communication  Custom header field in HTTP protocol  P2P style communication over HTTP protocol www.SecurityXploded.com
  • 18. Waledac C&C Communication  Ok, We have enough information to start our analysis  Now our task is to  Indentify which functions are responsible for encryption  Identify which function is responsible for sending the request  Identify what sent into the request (Clear Text)  Challenge  Lots of code (around 950 KB, ~14 MB IDB binary)  More than 4,000 functions  Completely unaware about the malware behaviour (code based) www.SecurityXploded.com
  • 19. Rapid Reversing Techniques  Tracing - most common approach  Instruction based tracing ○ Pros  Complete flow including branching /decisions made by program during execution  Powerful, given time and space provides solid results ○ Cons  Very slow (each instruction logging)  Huge output, difficult to analyze  For huge code base nearly impossible  Functions call based tracing ○ Pros  Functions call flow during execution  Provides fair details about the binary ○ Cons  Not very helpful in malware analysis (packers, run rime executable code generation etc.) www.SecurityXploded.com
  • 20. Rapid Reversing Techniques  API call based tracing ○ Pros  Can log all API calls even from newly allocated regions i.e. run rime unpacked code or run rime generated code  Provides good details about the malware and system interaction  Excellent for malware analysis, more advanced and sophisticated techniques can be used like API call clustering, API call based execution path diffing, Automated unpacking etc. ○ Cons  Efficiency and flexibility is based on the actual tracing software otherwise it can be very painful like instruction based tracing (hook hopping, API calls in big loops etc.)  These techniques are often used with conditions after a specific point/address www.SecurityXploded.com
  • 21. Waledac Analysis (C&C)  Our encryption routines should be near this code segment. We will look into function call flow of the malware upto this code so that we can get better understanding of the nearby code. www.SecurityXploded.com
  • 22. Continue...  In snapshot we see following things  Calls to LocalAlloc API (Another point confirming encryption routines near the code)  Call to HttpSendRequestA API (send the encrypted payload to C&C server)  Now identify the functions that are calling the above APIs, How ?  Static cross references doesn’t provide much details so we will use tracing.  * I am not going to share my tracing tools so please don’t make request for them . www.SecurityXploded.com
  • 23. Continue...  Below snapshot is from single shot function call ( and partial API) tracing of the malware.  We can mark sub_44DCCC as start point, because sub_408CC9 is directly calling our APIs. www.SecurityXploded.com
  • 24. Tracing Function SUB_44DCCC  Full function and API trace of the function sub_44DCCC.  Inside sub_44DCCC we see an another call (zoom-next slide) to a function which seems to hold 60% of code for sub_44DCCC and also calls LocalAlloc API, so that is our function. www.SecurityXploded.com
  • 25. Important Function  Put breakpoint on this function, run, put breakpoint on LocalAlloc, use single stepping (F8) and wait for LocalAlloc call.  Monitor LocalAlloc returned pointer, and keep single stepping on. Eventually you will see the answer of all the questions.  So pretty simple huh?? Try it yourself.  www.SecurityXploded.com
  • 26. C&C Payload (Clear Text)  Waledac uses xml style in its payload as we can see in the below snapshot.  However to know the meaning and purpose of this payload we need more analysis and threat intelligence, but most of the time it will suffice.  www.SecurityXploded.com
  • 27. Demonstration https://vimeo.com/57755964 www.SecurityXploded.com
  • 28. Summary  Complete analysis and threat report can take weeks to months, depending on the threat.  Tracing methods are extremely helpful in large code base malwares. Actually tracing is much more powerful, think about taint analysis.  Reverse Engineering Automation is a fascinating and useful study area.  VERA (ether dependent), Zynamics BinNavi (not very useful for malware analysis) etc. can be used to accelerate reverse engineering but they are not very flexible. (inclusion, exclusion, trace from one node to another node etc.)  I know it’s a lots of load on your brain but try to understand the malware yourself.  Malware MD5 : 0A0E0AD7175B17A5D6AFFC73279BDA8B www.SecurityXploded.com
  • 29. Single Shot Function Call Trace  In our analysis we discussed only the marked area in this snapshot.  This trace still not covering entire malware calls (because c&c is down) www.SecurityXploded.com
  • 30. Reference Complete Reference Guide for Advanced Malware Analysis Training [Include links for all the Demos & Tools] www.SecurityXploded.com
  • 31. Thank You ! www.SecurityXploded.com www.SecurityXploded.com