SlideShare a Scribd company logo
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 & Garage4Hackers community for their extended
  support and cooperation.
 Thanks to all the Trainers who have devoted their precious time and
  countless hours to make it happen.
 Thanks to ThoughtWorks for the beautiful and bigger venue.




                               www.SecurityXploded.com
Reversing & Malware Analysis Training

This presentation is a part of our Reverse Engineering & Malware
Analysis training program. Currently it is delivered only during our local
meet for FREE of cost.




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


                              www.SecurityXploded.com
Who am I #1
Amit Malik (sometimes DouBle_Zer0,DZZ)
     Member SecurityXploded & Garage4Hackers
     Security Researcher @ McAfee Labs
     RE, Exploit Analysis/Development, Malware Analysis
     Email: m.amit30@gmail.com




                        www.SecurityXploded.com
Agenda
   The material in this presentation is a bit complicated so
    I will be using the zig-zag approach.
     Recap

     Protections (GS and SAFESEH)

     Client side exploits and Heap Spray
     Protections (DEP)

     Protections (ASLR)

   If time permits then few words on the following:
     Heap buffer overflows


                           www.SecurityXploded.com
Recap
   In previous session we covered:
       Stack based buffer overflow
        ○ EIP overwrite (saved return address)

        ○ SEH Overwrite


   We also discussed “why we need pop pop ret or other
    similar instruction in SEH overflow”
   Now Question: Which one is more reliable or considered
    to be more reliable in terms of exploitation ?
     Consider we have overwritten EIP and SEH successfully.

                                  www.SecurityXploded.com
Protections Enforced by OS and
             Processor

                             ASLR
                  DEP                                   SEHOP
                                                           Forced
GS Cookies                  SAFESEH
                                                            ASLR
*Safe unlinking, Heap cookies etc. are also protection methods added into the
OS.                           www.SecurityXploded.com
Protections for stack based buffer
            overflow (Primary)
   Fortunately or Unfortunately both protection schemes are
    based on compiler/Linker options.

      EIP Overwrite ?                                            SEH Overwrite ?


           GS Cookie                                       SafeSEH (SEHop*)

   * SEHOP is a different protection scheme based on run time SEH chain validation, It is not based
    on compiler options however can be enabled or disabled through registry.


                                       www.SecurityXploded.com
GS Cookie (/GS)

   Put some random value (cookie – 32 bit) on stack
    before return address.

   While returning, compare the value of saved
    cookie, if not same then we have an overwrite.

   Generate “ Security Exception (if any)”, terminate
    the Application.



                        www.SecurityXploded.com
/GS Cookie Cont...
 Function Start:



                                               Cookie check function (see
                                               “function end” in below picture.)




Function end:




                         www.SecurityXploded.com
/GS Cookie Bypass
   Generate exception before cookie check
     Code dependent – if some overwritten variables are used
      before function return.
     Overwrite stack up to the end, further overwrite will
      generate exception

   Back to the question which exploitation (EIP or
    SEH) is more reliable ?
     SEH method is considered to be a bit more safe and
      reliable regardless of this bypassing technique.


                            www.SecurityXploded.com
/GS Cookie Bypass Cont..
Leverage the implementation. Did you see something ?




                        www.SecurityXploded.com
SafeSEH
   Compiler [Linker] /SAFESEH option

   Static list of known good exception handlers for the binary.

   Checks every time when a handler is called against the static list, if

    not in the list then handler is invalid and takes preventive measures.

   Load configuration directory stores meta information about safe

    exception handlers.

   If any module is not compiled with /SAFESEH then no check is

    done to ensure the integrity of the handler for that module.

                             www.SecurityXploded.com
/SAFESEH Bypassing
   If any loaded module in the vulnerable binary is not /SAFESEH
    compiled then no check is done to ensure the integrity of the handler
    for that module, so we can use any p/p/r address from that module.

   Use the address that is outside the address range of loaded modules.

   Importance of forward and backward jump.



               nseh                                       payload

                          Forward                                           Backward
                seh                                         nseh            jump
                          jump

             payload                                        seh
                                www.SecurityXploded.com
DEP (Data Execution Prevention)

   Two types:
     Software DEP (forget it)

     Hardware DEP (NX/XD enabled processors) – we will be

      talking about it in the rest of the session.

   We can’t execute the code from non executable
    area anymore.

   We are directly dealing with processer in this case.


                             www.SecurityXploded.com
DEP (HW) Bypass

   ROP (Return Oriented Programming)
     Use the system/existing code

     How stack works ?

   Main theme
     Either make non executable area executable

     Or allocate new area with executable permissions

     How ?

      ○ Well, use ROP 

                           www.SecurityXploded.com
Stack Heap Flipping (Stack Pivoting)

   I think this deserve a dedicated slide

   Depending on the conditions we may have large ROP payload while
    space on stack may be less or may be our entire payload is on heap.

   Flip the heap on to the stack so that we can get larger room.

   Instructions like XCHG ESP[REG], REG[ESP] can be used.

   We can also jump inside the valid instructions to change their meaning.

     Example: jump one byte inside “setz al” instruction ( From Adobe

       U3D exploit in wild)




                                www.SecurityXploded.com
DEP (HW) Bypass (DEMO)

   Methods
     HeapCreate

     VirtualAlloc

     VirtualProtect

     WriteProcessMemory (DEMO – simple, easy,

      demonstrate the entire concept – XpSp3)

   Often times the small code chunks in ROP are
    termed as “gadgets”

                          www.SecurityXploded.com
DEP (HW) Bypass (DEMO)



   http://vimeo.com/49069964




             www.SecurityXploded.com
ASLR

   Address Space Layout Randomization

   Involves randomly positioning the memory areas
    like base address of the binary, position of stack
    and heap.

   Compiler[linker] /DYNAMICBASE option




                          www.SecurityXploded.com
ASLR Bypass

   Search for Non-ASLR loaded libraries in the
    vulnerable application or if possible load one. 
     JRE ?

   Memory leaks

   Brute force

   Heavily depends on vulnerability conditions



                         www.SecurityXploded.com
Client Side Exploits
   Exploits that targets client applications like
    browsers, plugins, media players, readers etc.
   Much more dangerous then any other form of
    exploits
   Huge impact and landscape
   Provides solid infection vector
   Big malicious infrastructure.
     Botnets, DDOS, Spam etc.


                         www.SecurityXploded.com
Heap Spray
   A technique used in client side exploits
   IT’S NOT A VULNERABILITY or CLASS OF VUL.
   It’s a technique used for code execution.
   Think about the followings again:
     EIP overwrite

     SEH overwrite

    • What we used in the above and why we used that ?

   Heap spray provides very simple method for code execution.



                             www.SecurityXploded.com
Heap Spray Cont...
    Fortunately or unfortunately client side scripting languages like javascript,
     vbscript etc. provides methods to allocate and deallocate memory on the client.

    Which means we can make invalid memory addresses valid.
    0x200...           0x300..                             0x500..

    Valid address          invalid address range                     Before Allocation
    (allocated area)

                                   0x200...                            0x400..            0x500..

    After Allocation               Valid address                           invalid address range
    (0x300.. To 0x400..
                                   (allocated area)
    Is valid now)
                                 www.SecurityXploded.com
Heap Spray Cont..

   Allocate memory and fill with nop + shellcode

   Overwrite the EIP or SEH with any address within
    the newly allocated area (the nop region).

   Here EIP overwrite or SEH overwrite can be by
    any means.
     Stack buffer overflow, Heap buffer overflow, memory

      corruption, use after free etc..


                             www.SecurityXploded.com
Heap Spray (DEMO – IEPeers
  Vulnerability (IE6, IE7)
       http://vimeo.com/49070337




            www.SecurityXploded.com
Heap Spray (Stability Comments)

   Use intelligent guesses

   Stability depends on the exploitation conditions

   Fragmented heap, choose little higher addresses.

   Large number of allocations, choose little lower
    addresses 




                        www.SecurityXploded.com
Reference
   Complete Reference Guide for Reversing & Malware
    Analysis Training




                           www.SecurityXploded.com
Thank You !



www.SecurityXploded.com

More Related Content

What's hot (20)

PPTX
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
securityxploded
 
PPTX
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
securityxploded
 
PPTX
Advanced Malware Analysis Training Session 1 - Detection and Removal of Malwares
securityxploded
 
PPTX
Reversing & Malware Analysis Training Part 13 - Future Roadmap
securityxploded
 
PPTX
Advanced Malware Analysis Training Session 7 - Malware Memory Forensics
securityxploded
 
PPTX
Advanced Malware Analysis Training Session 4 - Anti-Analysis Techniques
securityxploded
 
PPTX
Anatomy of Exploit Kits
securityxploded
 
PPTX
Advanced malware analysis training session 7 malware memory forensics
Cysinfo Cyber Security Community
 
PPTX
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
securityxploded
 
PPTX
Reversing malware analysis training part6 practical reversing
Cysinfo Cyber Security Community
 
PPTX
Reversing malware analysis training part11 exploit development advanced
Cysinfo Cyber Security Community
 
PPTX
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
securityxploded
 
PPTX
Advanced malwareanalysis training session2 botnet analysis part1
Cysinfo Cyber Security Community
 
PPTX
Advanced malware analysis training session5 reversing automation
Cysinfo Cyber Security Community
 
PPTX
Advanced malware analysis training session8 introduction to android
Cysinfo Cyber Security Community
 
PPTX
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
securityxploded
 
PPTX
Reversing malware analysis training part1 lab setup guide
Cysinfo Cyber Security Community
 
PPTX
Reversing malware analysis training part7 unpackingupx
Cysinfo Cyber Security Community
 
PPTX
Dissecting Android APK
Cysinfo Cyber Security Community
 
PPTX
Reversing malware analysis training part2 introduction to windows internals
Cysinfo Cyber Security Community
 
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
securityxploded
 
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
securityxploded
 
Advanced Malware Analysis Training Session 1 - Detection and Removal of Malwares
securityxploded
 
Reversing & Malware Analysis Training Part 13 - Future Roadmap
securityxploded
 
Advanced Malware Analysis Training Session 7 - Malware Memory Forensics
securityxploded
 
Advanced Malware Analysis Training Session 4 - Anti-Analysis Techniques
securityxploded
 
Anatomy of Exploit Kits
securityxploded
 
Advanced malware analysis training session 7 malware memory forensics
Cysinfo Cyber Security Community
 
Advanced Malware Analysis Training Session 11 - (Part 2) Dissecting the Heart...
securityxploded
 
Reversing malware analysis training part6 practical reversing
Cysinfo Cyber Security Community
 
Reversing malware analysis training part11 exploit development advanced
Cysinfo Cyber Security Community
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
securityxploded
 
Advanced malwareanalysis training session2 botnet analysis part1
Cysinfo Cyber Security Community
 
Advanced malware analysis training session5 reversing automation
Cysinfo Cyber Security Community
 
Advanced malware analysis training session8 introduction to android
Cysinfo Cyber Security Community
 
Reversing & Malware Analysis Training Part 6 - Practical Reversing (I)
securityxploded
 
Reversing malware analysis training part1 lab setup guide
Cysinfo Cyber Security Community
 
Reversing malware analysis training part7 unpackingupx
Cysinfo Cyber Security Community
 
Dissecting Android APK
Cysinfo Cyber Security Community
 
Reversing malware analysis training part2 introduction to windows internals
Cysinfo Cyber Security Community
 

Similar to Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced] (20)

PDF
Reversing & malware analysis training part 11 exploit development advanced
Abdulrahman Bassam
 
PDF
Structured Exception Handler Exploitation
High-Tech Bridge SA (HTBridge)
 
PDF
Reversing & malware analysis training part 10 exploit development basics
Abdulrahman Bassam
 
PDF
Smashing the Buffer
Miroslav Stampar
 
PDF
[ENG] Hacktivity 2013 - Alice in eXploitland
Zoltan Balazs
 
PPTX
Return Oriented Programming (ROP) Based Exploits - Part I
n|u - The Open Security Community
 
PPTX
Stack-Based Buffer Overflows
Daniel Tumser
 
PPTX
Reversing malware analysis training part10 exploit development basics
Cysinfo Cyber Security Community
 
PDF
Buffer overflow attacks
Sandun Perera
 
PDF
Buffer Overflow - Smashing the Stack
ironSource
 
PDF
Riding the Overflow - Then and Now
Miroslav Stampar
 
PDF
From SEH Overwrite with Egg Hunter to Get a Shell!
Rodolpho Concurde
 
PDF
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
Rodolpho Concurde
 
PPT
Writing Metasploit Plugins
amiable_indian
 
PPTX
Buffer overflow – Smashing The Stack
Tomer Zait
 
PPTX
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
ahmed8790
 
PPTX
owasp lithuania chapter - exploit vs anti-exploit
Kęstutis Meškonis
 
PPTX
20101017 program analysis_for_security_livshits_lecture03_security
Computer Science Club
 
PDF
Buffer overflow attacks
Sandun Perera
 
PDF
CNIT 127 14: Protection Mechanisms
Sam Bowne
 
Reversing & malware analysis training part 11 exploit development advanced
Abdulrahman Bassam
 
Structured Exception Handler Exploitation
High-Tech Bridge SA (HTBridge)
 
Reversing & malware analysis training part 10 exploit development basics
Abdulrahman Bassam
 
Smashing the Buffer
Miroslav Stampar
 
[ENG] Hacktivity 2013 - Alice in eXploitland
Zoltan Balazs
 
Return Oriented Programming (ROP) Based Exploits - Part I
n|u - The Open Security Community
 
Stack-Based Buffer Overflows
Daniel Tumser
 
Reversing malware analysis training part10 exploit development basics
Cysinfo Cyber Security Community
 
Buffer overflow attacks
Sandun Perera
 
Buffer Overflow - Smashing the Stack
ironSource
 
Riding the Overflow - Then and Now
Miroslav Stampar
 
From SEH Overwrite with Egg Hunter to Get a Shell!
Rodolpho Concurde
 
From SEH Overwrite with Egg Hunter to Get a Shell_by_RodolphoConcurde
Rodolpho Concurde
 
Writing Metasploit Plugins
amiable_indian
 
Buffer overflow – Smashing The Stack
Tomer Zait
 
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
ahmed8790
 
owasp lithuania chapter - exploit vs anti-exploit
Kęstutis Meškonis
 
20101017 program analysis_for_security_livshits_lecture03_security
Computer Science Club
 
Buffer overflow attacks
Sandun Perera
 
CNIT 127 14: Protection Mechanisms
Sam Bowne
 
Ad

More from securityxploded (20)

PPTX
Fingerprinting healthcare institutions
securityxploded
 
PDF
Hollow Process Injection - Reversing and Investigating Malware Evasive Tactics
securityxploded
 
PDF
Buffer Overflow Attacks
securityxploded
 
PPTX
Malicious Client Detection Using Machine Learning
securityxploded
 
PDF
Understanding CryptoLocker (Ransomware) with a Case Study
securityxploded
 
PDF
Linux Malware Analysis using Limon Sandbox
securityxploded
 
PPT
Introduction to SMPC
securityxploded
 
PPTX
Breaking into hospitals
securityxploded
 
PPTX
Bluetooth [in]security
securityxploded
 
PPTX
Basic malware analysis
securityxploded
 
PPTX
Automating Malware Analysis
securityxploded
 
PPTX
Reverse Engineering Malware
securityxploded
 
PPTX
DLL Preloading Attack
securityxploded
 
PPTX
Partial Homomorphic Encryption
securityxploded
 
PPTX
Hunting Rootkit From the Dark Corners Of Memory
securityxploded
 
PPTX
Return Address – The Silver Bullet
securityxploded
 
PPTX
Defeating public exploit protections (EMET v5.2 and more)
securityxploded
 
PPTX
Hunting Ghost RAT Using Memory Forensics
securityxploded
 
PPTX
Malicious Url Detection Using Machine Learning
securityxploded
 
PPTX
MalwareNet Project
securityxploded
 
Fingerprinting healthcare institutions
securityxploded
 
Hollow Process Injection - Reversing and Investigating Malware Evasive Tactics
securityxploded
 
Buffer Overflow Attacks
securityxploded
 
Malicious Client Detection Using Machine Learning
securityxploded
 
Understanding CryptoLocker (Ransomware) with a Case Study
securityxploded
 
Linux Malware Analysis using Limon Sandbox
securityxploded
 
Introduction to SMPC
securityxploded
 
Breaking into hospitals
securityxploded
 
Bluetooth [in]security
securityxploded
 
Basic malware analysis
securityxploded
 
Automating Malware Analysis
securityxploded
 
Reverse Engineering Malware
securityxploded
 
DLL Preloading Attack
securityxploded
 
Partial Homomorphic Encryption
securityxploded
 
Hunting Rootkit From the Dark Corners Of Memory
securityxploded
 
Return Address – The Silver Bullet
securityxploded
 
Defeating public exploit protections (EMET v5.2 and more)
securityxploded
 
Hunting Ghost RAT Using Memory Forensics
securityxploded
 
Malicious Url Detection Using Machine Learning
securityxploded
 
MalwareNet Project
securityxploded
 
Ad

Recently uploaded (20)

PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 

Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]

  • 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 & Garage4Hackers community for their extended support and cooperation.  Thanks to all the Trainers who have devoted their precious time and countless hours to make it happen.  Thanks to ThoughtWorks for the beautiful and bigger venue. www.SecurityXploded.com
  • 4. Reversing & Malware Analysis Training This presentation is a part of our Reverse Engineering & Malware Analysis training program. Currently it is delivered only during our local meet for FREE of cost. For complete details of this course, visit our Security Training page. www.SecurityXploded.com
  • 5. Who am I #1 Amit Malik (sometimes DouBle_Zer0,DZZ)  Member SecurityXploded & Garage4Hackers  Security Researcher @ McAfee Labs  RE, Exploit Analysis/Development, Malware Analysis  Email: [email protected] www.SecurityXploded.com
  • 6. Agenda  The material in this presentation is a bit complicated so I will be using the zig-zag approach.  Recap  Protections (GS and SAFESEH)  Client side exploits and Heap Spray  Protections (DEP)  Protections (ASLR)  If time permits then few words on the following:  Heap buffer overflows www.SecurityXploded.com
  • 7. Recap  In previous session we covered:  Stack based buffer overflow ○ EIP overwrite (saved return address) ○ SEH Overwrite  We also discussed “why we need pop pop ret or other similar instruction in SEH overflow”  Now Question: Which one is more reliable or considered to be more reliable in terms of exploitation ?  Consider we have overwritten EIP and SEH successfully. www.SecurityXploded.com
  • 8. Protections Enforced by OS and Processor ASLR DEP SEHOP Forced GS Cookies SAFESEH ASLR *Safe unlinking, Heap cookies etc. are also protection methods added into the OS. www.SecurityXploded.com
  • 9. Protections for stack based buffer overflow (Primary)  Fortunately or Unfortunately both protection schemes are based on compiler/Linker options. EIP Overwrite ? SEH Overwrite ? GS Cookie SafeSEH (SEHop*)  * SEHOP is a different protection scheme based on run time SEH chain validation, It is not based on compiler options however can be enabled or disabled through registry. www.SecurityXploded.com
  • 10. GS Cookie (/GS)  Put some random value (cookie – 32 bit) on stack before return address.  While returning, compare the value of saved cookie, if not same then we have an overwrite.  Generate “ Security Exception (if any)”, terminate the Application. www.SecurityXploded.com
  • 11. /GS Cookie Cont... Function Start: Cookie check function (see “function end” in below picture.) Function end: www.SecurityXploded.com
  • 12. /GS Cookie Bypass  Generate exception before cookie check  Code dependent – if some overwritten variables are used before function return.  Overwrite stack up to the end, further overwrite will generate exception  Back to the question which exploitation (EIP or SEH) is more reliable ?  SEH method is considered to be a bit more safe and reliable regardless of this bypassing technique. www.SecurityXploded.com
  • 13. /GS Cookie Bypass Cont.. Leverage the implementation. Did you see something ? www.SecurityXploded.com
  • 14. SafeSEH  Compiler [Linker] /SAFESEH option  Static list of known good exception handlers for the binary.  Checks every time when a handler is called against the static list, if not in the list then handler is invalid and takes preventive measures.  Load configuration directory stores meta information about safe exception handlers.  If any module is not compiled with /SAFESEH then no check is done to ensure the integrity of the handler for that module. www.SecurityXploded.com
  • 15. /SAFESEH Bypassing  If any loaded module in the vulnerable binary is not /SAFESEH compiled then no check is done to ensure the integrity of the handler for that module, so we can use any p/p/r address from that module.  Use the address that is outside the address range of loaded modules.  Importance of forward and backward jump. nseh payload Forward Backward seh nseh jump jump payload seh www.SecurityXploded.com
  • 16. DEP (Data Execution Prevention)  Two types:  Software DEP (forget it)  Hardware DEP (NX/XD enabled processors) – we will be talking about it in the rest of the session.  We can’t execute the code from non executable area anymore.  We are directly dealing with processer in this case. www.SecurityXploded.com
  • 17. DEP (HW) Bypass  ROP (Return Oriented Programming)  Use the system/existing code  How stack works ?  Main theme  Either make non executable area executable  Or allocate new area with executable permissions  How ? ○ Well, use ROP  www.SecurityXploded.com
  • 18. Stack Heap Flipping (Stack Pivoting)  I think this deserve a dedicated slide  Depending on the conditions we may have large ROP payload while space on stack may be less or may be our entire payload is on heap.  Flip the heap on to the stack so that we can get larger room.  Instructions like XCHG ESP[REG], REG[ESP] can be used.  We can also jump inside the valid instructions to change their meaning.  Example: jump one byte inside “setz al” instruction ( From Adobe U3D exploit in wild) www.SecurityXploded.com
  • 19. DEP (HW) Bypass (DEMO)  Methods  HeapCreate  VirtualAlloc  VirtualProtect  WriteProcessMemory (DEMO – simple, easy, demonstrate the entire concept – XpSp3)  Often times the small code chunks in ROP are termed as “gadgets” www.SecurityXploded.com
  • 20. DEP (HW) Bypass (DEMO) http://vimeo.com/49069964 www.SecurityXploded.com
  • 21. ASLR  Address Space Layout Randomization  Involves randomly positioning the memory areas like base address of the binary, position of stack and heap.  Compiler[linker] /DYNAMICBASE option www.SecurityXploded.com
  • 22. ASLR Bypass  Search for Non-ASLR loaded libraries in the vulnerable application or if possible load one.   JRE ?  Memory leaks  Brute force  Heavily depends on vulnerability conditions www.SecurityXploded.com
  • 23. Client Side Exploits  Exploits that targets client applications like browsers, plugins, media players, readers etc.  Much more dangerous then any other form of exploits  Huge impact and landscape  Provides solid infection vector  Big malicious infrastructure.  Botnets, DDOS, Spam etc. www.SecurityXploded.com
  • 24. Heap Spray  A technique used in client side exploits  IT’S NOT A VULNERABILITY or CLASS OF VUL.  It’s a technique used for code execution.  Think about the followings again:  EIP overwrite  SEH overwrite • What we used in the above and why we used that ?  Heap spray provides very simple method for code execution. www.SecurityXploded.com
  • 25. Heap Spray Cont...  Fortunately or unfortunately client side scripting languages like javascript, vbscript etc. provides methods to allocate and deallocate memory on the client.  Which means we can make invalid memory addresses valid. 0x200... 0x300.. 0x500.. Valid address invalid address range Before Allocation (allocated area) 0x200... 0x400.. 0x500.. After Allocation Valid address invalid address range (0x300.. To 0x400.. (allocated area) Is valid now) www.SecurityXploded.com
  • 26. Heap Spray Cont..  Allocate memory and fill with nop + shellcode  Overwrite the EIP or SEH with any address within the newly allocated area (the nop region).  Here EIP overwrite or SEH overwrite can be by any means.  Stack buffer overflow, Heap buffer overflow, memory corruption, use after free etc.. www.SecurityXploded.com
  • 27. Heap Spray (DEMO – IEPeers Vulnerability (IE6, IE7) http://vimeo.com/49070337 www.SecurityXploded.com
  • 28. Heap Spray (Stability Comments)  Use intelligent guesses  Stability depends on the exploitation conditions  Fragmented heap, choose little higher addresses.  Large number of allocations, choose little lower addresses  www.SecurityXploded.com
  • 29. Reference  Complete Reference Guide for Reversing & Malware Analysis Training www.SecurityXploded.com