SlideShare a Scribd company logo
FAILURE OF DEP AND ASLR
VISHWAS SHARMA
DEP
Data Execution Prevention
DEP
 DEP – Data execution prevention
    A Protection mechanism that prevents the execution of
    code in the memory non-executable.
    This protect the attacker from running shellcode on stack,
    heap or in data segments
    Now hardware support NX but – NX for No-eXecute
    Two types of DEP – software and hardware protection
DEP POLICIES
DEP @ RUNTIME
          KPROCESS Structure contains DEP information
          DEP Flag is set or queried with

                                  Query - NtQueryInformationProcess

                                       Set – NtSetInformationProcess

                     Flag is contained in ProcessExecuteFlags

Example:                                                                0: kd> dt nt!_KPROCESS 849f3a90 –r
0: kd> !process 0 0 calc.exe                                            +0x06b Flags : _KEXECUTE_OPTIONS
PROCESS 849f3a90 SessionId: 1 Cid: 1474 Peb: 7ffdd000 ParentCid: 077c   +0x000 ExecuteDisable : 0y1
DirBase: 7dc5c820 ObjectTable: a694ce68 HandleCount: 52.                +0x000 ExecuteEnable : 0y0
Image: calc.exe                                                         +0x000 DisableThunkEmulation : 0y1
                                                                        +0x000 Permanent : 0y1
                                                                        +0x000 ExecuteDispatchEnable : 0y0
                                                                        +0x000 ImageDispatchEnable : 0y0
                                                                        +0x000 DisableExceptionChainValidation : 0y1
                                                                        +0x000 Spare : 0y0


       ExecuteDisable - “Disable execution from non-executable memory”
CHEAT BY DEP
 DisableThunkEmulation
    ATL library rely on some code to be executed from the
    writable memory. So permission to run code form heap
    should be given to application
    When Program Attempts to execute code on a non-
    executable page, the kernel calls KiEmulateAtlTrunk to
    check ATL sequences
    IF found any ATL sequence – then continue emulate the
    trunk and as if nothing has happened
NOW THE FUN PART - WEAKNESS
      Incompatible Application – Remember OptIn Policy
      R+W+X mappings – JVM and programming running on java
      has this mapping
      *Return-2-libc Attacks
          Find page mapping and protection functions and change
          default permissions on the page
          Create a process from the dump that is produced in the
          memory
          Just-In-Time compilers are making situation worse
      *Return Oriented Programming – Modern ret2libc
      Runtime Disable DEP
          Finding position of NtSetInformationProcess and changing
          the permission in runtime – This technique would only work
          with OptIn – OptOut policy
* Explanation on board
ASLR
Address Space Layout Randomization
ASLR
 ASLR – Address space Layout Randomization
    Randomize the address where objects are placed in
    virtual space of a given process
    ASLR randomizes the location PE/MZ files that are
    mapped on the virtual memory, Heaps, stacks and PEB
    and TEB
    It provides random stack and heap allocations and page
    load every time a process starts.
    Thus even if process is being hacked it cannot execute
    shellcode with a best chance of 1/254 or 2/255
ASLR
 Image Randomization
    Designed for a capability to randomly position both
    executable and DLLs
    This randomization is system wide and could not switched
    off at runtime
    A Registry entry control the implementation of ASLR
       Respect the base address in PE header
       Randomize all, even those which are incompatible
       Randomize only those which are compatible - Default
ASLR
           DLL Randomization
               DLL must be loaded in each process that uses it to allow
               the physical memory used by the DLL to be shared
               When the same DLL is loaded its section object - A
               section object represents a section of memory that can be
               shared – is reused and it is mapped at the same virtual
               addresses

50960000      50960000         50A28000        50A8C000         50AF0000         50B54000           50BB8000

           _MiImageBitMap – A bitmap of size 0x2800 contains all position of 64KB aligned address




    Loading DLL into process is also randomized by SmpRandomizeDllList
ASLR
 Stack Randomization – 2 fold randomization
    The base of the stack is choose randomly
    This is implemented by searching holes into Virtual
    Memory of the process. Holes are regions where series of
    pages are not mapped into memory.
    Choosing hole is randomized by 5 bits random function
    Again a 9 bit random value is derived from time stamp – y
    Offset = y*4 --- For 32 bit alignment of stack
THE FUN PART
      Incompatible DLL – Statically positioned DLLs and
      Executable
          This can be initializing 3rd party ActiveX components, plugins
          in you browser
          Specially crafted data packet that could result in loading of
          DLL based for parsing the “special” data
          Embedded Media of various types that require loading of
          specific library to parse the data like image, video or flash
          content
      *Partially static object
          This concept is basically the mother of all spraying
          techniques that are used in bypassing ASLR
               For example a heap allocation is randomized by 2 MB but what
               would happen when we allocate data of much greater size eg.
               500MB or similar
* Explanation on board
THE FUN PART
      *Partial overwrites
         As demonstrated earlier that last 2 bytes of address
         space are not randomized we can have a partial overwrite
         or either 1 or 2 bytes of data on the stack
         It would be enough to jump to any offset location which
         would be relative that position by a maximum of 0xffff
         bytes
      *Memory information Leakage
          I have discussed it in null IRC channel this week
          Implications could be getting information of either module
          base address or stack base address, heap base address
          or TEB and PEB leakages


* Explanation on board
Research
Failure Of DEP And ASLR
Failure Of DEP And ASLR
Failure Of DEP And ASLR
Failure Of DEP And ASLR
Failure Of DEP And ASLR
Failure Of DEP And ASLR

More Related Content

PPTX
The TCP/IP Stack in the Linux Kernel
PDF
Profiling Ruby
PDF
Fun with FUSE
PDF
OpenZFS novel algorithms: snapshots, space allocation, RAID-Z - Matt Ahrens
PPTX
OpenZFS data-driven performance
PDF
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
PPTX
Operating Systems - A Primer
PDF
Performance Profiling in Rust
The TCP/IP Stack in the Linux Kernel
Profiling Ruby
Fun with FUSE
OpenZFS novel algorithms: snapshots, space allocation, RAID-Z - Matt Ahrens
OpenZFS data-driven performance
The TCP/IP stack in the FreeBSD kernel COSCUP 2014
Operating Systems - A Primer
Performance Profiling in Rust

What's hot (20)

PDF
Introduction to eBPF and XDP
PPTX
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
PDF
Configuration management II - Terraform
PPTX
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
PPTX
Automatic Storage Management (ASM) metrics are a goldmine: Let's use them!
PDF
Exploitation Crash Course
PDF
Performance Analysis Tools for Linux Kernel
PDF
Performance Analysis: new tools and concepts from the cloud
PDF
JavaOne 2015 Java Mixed-Mode Flame Graphs
PDF
Easy deployment & management of cloud apps
PDF
Exploitation of counter overflows in the Linux kernel
PDF
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
PDF
Jsonnet, terraform & packer
PDF
Security Monitoring with eBPF
PDF
System Programming and Administration
PPTX
Operating System Engineering Quiz
PDF
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
PPT
PPTX
Computer Science Homework Help
Introduction to eBPF and XDP
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
Configuration management II - Terraform
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
Automatic Storage Management (ASM) metrics are a goldmine: Let's use them!
Exploitation Crash Course
Performance Analysis Tools for Linux Kernel
Performance Analysis: new tools and concepts from the cloud
JavaOne 2015 Java Mixed-Mode Flame Graphs
Easy deployment & management of cloud apps
Exploitation of counter overflows in the Linux kernel
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Jsonnet, terraform & packer
Security Monitoring with eBPF
System Programming and Administration
Operating System Engineering Quiz
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Computer Science Homework Help
Ad

Viewers also liked (8)

PDF
Reversing & malware analysis training part 5 reverse engineering tools basics
PDF
Reversing & malware analysis training part 8 malware memory forensics
PDF
Reversing & malware analysis training part 11 exploit development advanced
PDF
Reversing & malware analysis training part 7 unpacking upx
PDF
Reversing & malware analysis training part 6 practical reversing (i)
PDF
SEH overwrite and its exploitability
PDF
YEAR 5 TEACHER'S RESOURCE BOOK
PDF
Reversing & malware analysis training part 9 advanced malware analysis
Reversing & malware analysis training part 5 reverse engineering tools basics
Reversing & malware analysis training part 8 malware memory forensics
Reversing & malware analysis training part 11 exploit development advanced
Reversing & malware analysis training part 7 unpacking upx
Reversing & malware analysis training part 6 practical reversing (i)
SEH overwrite and its exploitability
YEAR 5 TEACHER'S RESOURCE BOOK
Reversing & malware analysis training part 9 advanced malware analysis
Ad

Similar to Failure Of DEP And ASLR (20)

PDF
Low Level Exploits
PDF
Eusecwest
PPT
[CCC-28c3] Post Memory Corruption Memory Analysis
PDF
Performance and Predictability - Richard Warburton
PDF
Performance and predictability (1)
PDF
DTrace Topics: Introduction
PDF
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe Shockwave
PPTX
Sql server engine cpu cache as the new ram
PPTX
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
PDF
Potapenko, vyukov forewarned is forearmed. a san and tsan
PDF
Docker
PDF
[Ruxcon 2011] Post Memory Corruption Memory Analysis
PDF
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
PDF
Shellcoding in linux
PDF
Finding Xori: Malware Analysis Triage with Automated Disassembly
PPTX
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
PDF
Data Grids with Oracle Coherence
PDF
IMCSummit 2015 - Day 2 IT Business Track - 4 Myths about In-Memory Databases ...
PDF
ruby2600 - an Atari 2600 emulator written in Ruby
PDF
VLANs in the Linux Kernel
Low Level Exploits
Eusecwest
[CCC-28c3] Post Memory Corruption Memory Analysis
Performance and Predictability - Richard Warburton
Performance and predictability (1)
DTrace Topics: Introduction
HES2011 - Aaron Portnoy and Logan Brown - Black Box Auditing Adobe Shockwave
Sql server engine cpu cache as the new ram
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Potapenko, vyukov forewarned is forearmed. a san and tsan
Docker
[Ruxcon 2011] Post Memory Corruption Memory Analysis
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Shellcoding in linux
Finding Xori: Malware Analysis Triage with Automated Disassembly
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Data Grids with Oracle Coherence
IMCSummit 2015 - Day 2 IT Business Track - 4 Myths about In-Memory Databases ...
ruby2600 - an Atari 2600 emulator written in Ruby
VLANs in the Linux Kernel

More from n|u - The Open Security Community (20)

PDF
Hardware security testing 101 (Null - Delhi Chapter)
PPTX
SSRF exploit the trust relationship
PDF
PDF
Api security-testing
PDF
Introduction to TLS 1.3
PDF
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
PDF
Talking About SSRF,CRLF
PPTX
Building active directory lab for red teaming
PPTX
Owning a company through their logs
PPTX
Introduction to shodan
PDF
Detecting persistence in windows
PPTX
Frida - Objection Tool Usage
PDF
OSQuery - Monitoring System Process
PDF
DevSecOps Jenkins Pipeline -Security
PDF
Extensible markup language attacks
PPTX
PDF
Hardware security testing 101 (Null - Delhi Chapter)
SSRF exploit the trust relationship
Api security-testing
Introduction to TLS 1.3
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Talking About SSRF,CRLF
Building active directory lab for red teaming
Owning a company through their logs
Introduction to shodan
Detecting persistence in windows
Frida - Objection Tool Usage
OSQuery - Monitoring System Process
DevSecOps Jenkins Pipeline -Security
Extensible markup language attacks

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Encapsulation theory and applications.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Getting Started with Data Integration: FME Form 101
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Tartificialntelligence_presentation.pptx
Group 1 Presentation -Planning and Decision Making .pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A comparative analysis of optical character recognition models for extracting...
Encapsulation theory and applications.pdf
1. Introduction to Computer Programming.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Getting Started with Data Integration: FME Form 101
Unlocking AI with Model Context Protocol (MCP)
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Per capita expenditure prediction using model stacking based on satellite ima...

Failure Of DEP And ASLR

  • 1. FAILURE OF DEP AND ASLR VISHWAS SHARMA
  • 3. DEP DEP – Data execution prevention A Protection mechanism that prevents the execution of code in the memory non-executable. This protect the attacker from running shellcode on stack, heap or in data segments Now hardware support NX but – NX for No-eXecute Two types of DEP – software and hardware protection
  • 5. DEP @ RUNTIME KPROCESS Structure contains DEP information DEP Flag is set or queried with Query - NtQueryInformationProcess Set – NtSetInformationProcess Flag is contained in ProcessExecuteFlags Example: 0: kd> dt nt!_KPROCESS 849f3a90 –r 0: kd> !process 0 0 calc.exe +0x06b Flags : _KEXECUTE_OPTIONS PROCESS 849f3a90 SessionId: 1 Cid: 1474 Peb: 7ffdd000 ParentCid: 077c +0x000 ExecuteDisable : 0y1 DirBase: 7dc5c820 ObjectTable: a694ce68 HandleCount: 52. +0x000 ExecuteEnable : 0y0 Image: calc.exe +0x000 DisableThunkEmulation : 0y1 +0x000 Permanent : 0y1 +0x000 ExecuteDispatchEnable : 0y0 +0x000 ImageDispatchEnable : 0y0 +0x000 DisableExceptionChainValidation : 0y1 +0x000 Spare : 0y0 ExecuteDisable - “Disable execution from non-executable memory”
  • 6. CHEAT BY DEP DisableThunkEmulation ATL library rely on some code to be executed from the writable memory. So permission to run code form heap should be given to application When Program Attempts to execute code on a non- executable page, the kernel calls KiEmulateAtlTrunk to check ATL sequences IF found any ATL sequence – then continue emulate the trunk and as if nothing has happened
  • 7. NOW THE FUN PART - WEAKNESS Incompatible Application – Remember OptIn Policy R+W+X mappings – JVM and programming running on java has this mapping *Return-2-libc Attacks Find page mapping and protection functions and change default permissions on the page Create a process from the dump that is produced in the memory Just-In-Time compilers are making situation worse *Return Oriented Programming – Modern ret2libc Runtime Disable DEP Finding position of NtSetInformationProcess and changing the permission in runtime – This technique would only work with OptIn – OptOut policy * Explanation on board
  • 9. ASLR ASLR – Address space Layout Randomization Randomize the address where objects are placed in virtual space of a given process ASLR randomizes the location PE/MZ files that are mapped on the virtual memory, Heaps, stacks and PEB and TEB It provides random stack and heap allocations and page load every time a process starts. Thus even if process is being hacked it cannot execute shellcode with a best chance of 1/254 or 2/255
  • 10. ASLR Image Randomization Designed for a capability to randomly position both executable and DLLs This randomization is system wide and could not switched off at runtime A Registry entry control the implementation of ASLR Respect the base address in PE header Randomize all, even those which are incompatible Randomize only those which are compatible - Default
  • 11. ASLR DLL Randomization DLL must be loaded in each process that uses it to allow the physical memory used by the DLL to be shared When the same DLL is loaded its section object - A section object represents a section of memory that can be shared – is reused and it is mapped at the same virtual addresses 50960000 50960000 50A28000 50A8C000 50AF0000 50B54000 50BB8000 _MiImageBitMap – A bitmap of size 0x2800 contains all position of 64KB aligned address Loading DLL into process is also randomized by SmpRandomizeDllList
  • 12. ASLR Stack Randomization – 2 fold randomization The base of the stack is choose randomly This is implemented by searching holes into Virtual Memory of the process. Holes are regions where series of pages are not mapped into memory. Choosing hole is randomized by 5 bits random function Again a 9 bit random value is derived from time stamp – y Offset = y*4 --- For 32 bit alignment of stack
  • 13. THE FUN PART Incompatible DLL – Statically positioned DLLs and Executable This can be initializing 3rd party ActiveX components, plugins in you browser Specially crafted data packet that could result in loading of DLL based for parsing the “special” data Embedded Media of various types that require loading of specific library to parse the data like image, video or flash content *Partially static object This concept is basically the mother of all spraying techniques that are used in bypassing ASLR For example a heap allocation is randomized by 2 MB but what would happen when we allocate data of much greater size eg. 500MB or similar * Explanation on board
  • 14. THE FUN PART *Partial overwrites As demonstrated earlier that last 2 bytes of address space are not randomized we can have a partial overwrite or either 1 or 2 bytes of data on the stack It would be enough to jump to any offset location which would be relative that position by a maximum of 0xffff bytes *Memory information Leakage I have discussed it in null IRC channel this week Implications could be getting information of either module base address or stack base address, heap base address or TEB and PEB leakages * Explanation on board