SlideShare a Scribd company logo
Reversing malware analysis training part11 exploit development advanced
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 Cysinfo is
responsible for any damage or loss caused due to use or misuse of the
information presented here.
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.
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.
Who am I #1
Amit Malik (sometimes DouBle_Zer0,DZZ)
 Member of Cysinfo
 Security Researcher @ McAfee Labs
 RE, Exploit Analysis/Development, Malware Analysis
 Email: m.amit30@gmail.com
 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
 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.
ASLR
DEP
GS Cookies SAFESEH
SEHOP
Forced ASLR
*Safe unlinking, Heap cookies etc. are also protection methods added into the
OS.
 Fortunately or Unfortunately both protection schemes are
based on compiler/Linker options.
 * 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.
GS Cookie
EIP Overwrite ?
SafeSEH (SEHop*)
SEH Overwrite ?
 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.
Function Start:
Function end:
Cookie check function (see
“function end” in below picture.)
 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.
Leverage the implementation. Did you see something ?
 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.
 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
seh
payload
payload
nseh
seh
Forward
jump
Backward
jump
 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.
 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 
 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)
 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”
Reversing malware analysis training part11 exploit development advanced
 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
 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
 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.
 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.
 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.
Valid address invalid address range
(allocated area)
0x200... 0x400.. 0x500..
Valid address invalid address range
(allocated area)
0x200... 0x300.. 0x500..
Before Allocation
After Allocation
(0x300.. To 0x400..
Is valid now)
 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..
http://vimeo.com/49070337
 Use intelligent guesses
 Stability depends on the exploitation conditions
 Fragmented heap, choose little higher addresses.
 Large number of allocations, choose little lower
addresses 
Thank You !

More Related Content

PPTX
Advanced malware analysis training session8 introduction to android
PPTX
Advanced malware analysis training session 7 malware memory forensics
PPTX
Reversing malware analysis training part6 practical reversing
PPTX
Reversing malware analysis trainingpart9 advanced malware analysis
PPTX
Advanced malware analysis training session5 reversing automation
PPTX
Advanced malwareanalysis training session2 botnet analysis part1
PPTX
Reversing malware analysis training part2 introduction to windows internals
PPTX
Reversing malware analysis training part7 unpackingupx
Advanced malware analysis training session8 introduction to android
Advanced malware analysis training session 7 malware memory forensics
Reversing malware analysis training part6 practical reversing
Reversing malware analysis trainingpart9 advanced malware analysis
Advanced malware analysis training session5 reversing automation
Advanced malwareanalysis training session2 botnet analysis part1
Reversing malware analysis training part2 introduction to windows internals
Reversing malware analysis training part7 unpackingupx

What's hot (20)

PPTX
Reversing malware analysis training part1 lab setup guide
PPTX
Reversing malware analysis training part10 exploit development basics
PPTX
Advanced Malware Analysis Training Session 6 - Malware Sandbox Analysis
PPTX
Advanced malware analysis training session3 botnet analysis part2
PPTX
Reversing & malware analysis training part 1 lab setup guide
PPTX
Advanced malware analysis training session10 part1
PPTX
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
PPTX
Advanced malware analysis training session4 anti-analysis techniques
PPTX
Advanced malware analysis training session6 malware sandbox analysis
PPTX
Advanced Malware Analysis Training Session 7 - Malware Memory Forensics
PPTX
Dissecting Android APK
PPTX
Advanced malware analysis training session1 detection and removal of malwares
PPTX
Reversing malware analysis training part3 windows pefile formatbasics
PPTX
Advanced Malware Analysis Training Session 5 - Reversing Automation
PPTX
Defeating public exploit protections (EMET v5.2 and more)
PPTX
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
PPTX
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
PPTX
Advanced Malware Analysis Training Session 8 - Introduction to Android
PPTX
Reversing & malware analysis training part 2 introduction to windows internals
Reversing malware analysis training part1 lab setup guide
Reversing malware analysis training part10 exploit development basics
Advanced Malware Analysis Training Session 6 - Malware Sandbox Analysis
Advanced malware analysis training session3 botnet analysis part2
Reversing & malware analysis training part 1 lab setup guide
Advanced malware analysis training session10 part1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced malware analysis training session4 anti-analysis techniques
Advanced malware analysis training session6 malware sandbox analysis
Advanced Malware Analysis Training Session 7 - Malware Memory Forensics
Dissecting Android APK
Advanced malware analysis training session1 detection and removal of malwares
Reversing malware analysis training part3 windows pefile formatbasics
Advanced Malware Analysis Training Session 5 - Reversing Automation
Defeating public exploit protections (EMET v5.2 and more)
Advanced Malware Analysis Training Session 3 - Botnet Analysis Part 2
Reversing & Malware Analysis Training Part 9 - Advanced Malware Analysis
Advanced Malware Analysis Training Session 8 - Introduction to Android
Reversing & malware analysis training part 2 introduction to windows internals
Ad

Viewers also liked (13)

PPTX
Advanced malware analysis training session11 part2 dissecting the heart beat ...
PPTX
Dll preloading-attack
PDF
Buffer overflow Attacks
PPTX
Watering hole attacks case study analysis
PPTX
Homomorphic encryption
PDF
Format string vunerability
PDF
Dynamic Binary Instrumentation
PPTX
Investigating Malware using Memory Forensics
ODP
Introduction to Binary Exploitation
PPTX
Exploits & Mitigations - Memory Corruption Techniques
PDF
POS Malware: Is your Debit/Credit Transcations Secure?
PPTX
Introduction to ICS/SCADA security
PPTX
Reversing malware analysis training part4 assembly programming basics
Advanced malware analysis training session11 part2 dissecting the heart beat ...
Dll preloading-attack
Buffer overflow Attacks
Watering hole attacks case study analysis
Homomorphic encryption
Format string vunerability
Dynamic Binary Instrumentation
Investigating Malware using Memory Forensics
Introduction to Binary Exploitation
Exploits & Mitigations - Memory Corruption Techniques
POS Malware: Is your Debit/Credit Transcations Secure?
Introduction to ICS/SCADA security
Reversing malware analysis training part4 assembly programming basics
Ad

Similar to Reversing malware analysis training part11 exploit development advanced (20)

PDF
Reversing & malware analysis training part 11 exploit development advanced
PPTX
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
PPTX
Dont run with scissors
PDF
Reversing & malware analysis training part 2 introduction to windows internals
PDF
Reversing & malware analysis training part 5 reverse engineering tools basics
PDF
OpenStack in the Enterprise - Are You Ready? - Maish Saidel-Keesing
PDF
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
PPTX
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
DOCX
Training report anish
PDF
JVM Support for Multitenant Applications - Steve Poole (IBM)
ODP
Deployment talk dpc 13
PDF
Code Coverage for Total Security in Application Migrations
PDF
Software Reverse Engineering in a Security Context
PDF
Hacking Vulnerable Websites to Bypass Firewalls
PDF
Reversing & malware analysis training part 10 exploit development basics
PPTX
AppSec California 2016 - Making Security Agile
PDF
System Hardening Using Ansible
PPTX
Help Doctor, my application is an onion!
PDF
Shift Left Security
PPTX
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers
Reversing & malware analysis training part 11 exploit development advanced
Reversing & Malware Analysis Training Part 11 - Exploit Development [Advanced]
Dont run with scissors
Reversing & malware analysis training part 2 introduction to windows internals
Reversing & malware analysis training part 5 reverse engineering tools basics
OpenStack in the Enterprise - Are You Ready? - Maish Saidel-Keesing
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
Training report anish
JVM Support for Multitenant Applications - Steve Poole (IBM)
Deployment talk dpc 13
Code Coverage for Total Security in Application Migrations
Software Reverse Engineering in a Security Context
Hacking Vulnerable Websites to Bypass Firewalls
Reversing & malware analysis training part 10 exploit development basics
AppSec California 2016 - Making Security Agile
System Hardening Using Ansible
Help Doctor, my application is an onion!
Shift Left Security
Defcon 22 - Stitching numbers - generating rop payloads from in memory numbers

More from Cysinfo Cyber Security Community (20)

PDF
Understanding Malware Persistence Techniques by Monnappa K A
PDF
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
PDF
Getting started with cybersecurity through CTFs by Shruti Dixit & Geethna TK
PPTX
Emerging Trends in Cybersecurity by Amar Prusty
PDF
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
PDF
Closer look at PHP Unserialization by Ashwin Shenoi
PDF
Unicorn: The Ultimate CPU Emulator by Akshay Ajayan
PDF
The Art of Executing JavaScript by Akhil Mahendra
PDF
Reversing and Decrypting Malware Communications by Monnappa
PPTX
DeViL - Detect Virtual Machine in Linux by Sreelakshmi
PPTX
Analysis of android apk using adhrit by Abhishek J.M
PDF
Understanding evasive hollow process injection techniques monnappa k a
PPTX
Security challenges in d2d communication by ajithkumar vyasarao
PPTX
S2 e (selective symbolic execution) -shivkrishna a
PPTX
Dynamic binary analysis using angr siddharth muralee
PPTX
Bit flipping attack on aes cbc - ashutosh ahelleya
PDF
Security Analytics using ELK stack
PDF
Linux Malware Analysis
PDF
ATM Malware: Understanding the threat
PPTX
XXE - XML External Entity Attack
Understanding Malware Persistence Techniques by Monnappa K A
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
Getting started with cybersecurity through CTFs by Shruti Dixit & Geethna TK
Emerging Trends in Cybersecurity by Amar Prusty
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
Closer look at PHP Unserialization by Ashwin Shenoi
Unicorn: The Ultimate CPU Emulator by Akshay Ajayan
The Art of Executing JavaScript by Akhil Mahendra
Reversing and Decrypting Malware Communications by Monnappa
DeViL - Detect Virtual Machine in Linux by Sreelakshmi
Analysis of android apk using adhrit by Abhishek J.M
Understanding evasive hollow process injection techniques monnappa k a
Security challenges in d2d communication by ajithkumar vyasarao
S2 e (selective symbolic execution) -shivkrishna a
Dynamic binary analysis using angr siddharth muralee
Bit flipping attack on aes cbc - ashutosh ahelleya
Security Analytics using ELK stack
Linux Malware Analysis
ATM Malware: Understanding the threat
XXE - XML External Entity Attack

Recently uploaded (20)

PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
observCloud-Native Containerability and monitoring.pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPT
What is a Computer? Input Devices /output devices
PPTX
Modernising the Digital Integration Hub
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
August Patch Tuesday
PPTX
The various Industrial Revolutions .pptx
PDF
project resource management chapter-09.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
WOOl fibre morphology and structure.pdf for textiles
1 - Historical Antecedents, Social Consideration.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Getting started with AI Agents and Multi-Agent Systems
Web App vs Mobile App What Should You Build First.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
Programs and apps: productivity, graphics, security and other tools
observCloud-Native Containerability and monitoring.pptx
cloud_computing_Infrastucture_as_cloud_p
What is a Computer? Input Devices /output devices
Modernising the Digital Integration Hub
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Group 1 Presentation -Planning and Decision Making .pptx
August Patch Tuesday
The various Industrial Revolutions .pptx
project resource management chapter-09.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf

Reversing malware analysis training part11 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 Cysinfo is responsible for any damage or loss caused due to use or misuse of the information presented here.
  • 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.
  • 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.
  • 5. Who am I #1 Amit Malik (sometimes DouBle_Zer0,DZZ)  Member of Cysinfo  Security Researcher @ McAfee Labs  RE, Exploit Analysis/Development, Malware Analysis  Email: [email protected]
  • 6.  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
  • 7.  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.
  • 8. ASLR DEP GS Cookies SAFESEH SEHOP Forced ASLR *Safe unlinking, Heap cookies etc. are also protection methods added into the OS.
  • 9.  Fortunately or Unfortunately both protection schemes are based on compiler/Linker options.  * 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. GS Cookie EIP Overwrite ? SafeSEH (SEHop*) SEH Overwrite ?
  • 10.  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.
  • 11. Function Start: Function end: Cookie check function (see “function end” in below picture.)
  • 12.  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.
  • 13. Leverage the implementation. Did you see something ?
  • 14.  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.
  • 15.  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 seh payload payload nseh seh Forward jump Backward jump
  • 16.  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.
  • 17.  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 
  • 18.  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)
  • 19.  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”
  • 21.  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
  • 22.  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
  • 23.  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.
  • 24.  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.
  • 25.  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. Valid address invalid address range (allocated area) 0x200... 0x400.. 0x500.. Valid address invalid address range (allocated area) 0x200... 0x300.. 0x500.. Before Allocation After Allocation (0x300.. To 0x400.. Is valid now)
  • 26.  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..
  • 28.  Use intelligent guesses  Stability depends on the exploitation conditions  Fragmented heap, choose little higher addresses.  Large number of allocations, choose little lower addresses 