SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
Everybody be cool, this is a roppery!


           Vincenzo Iozzo (vincenzo.iozzo@zynamics.com) zynamics GmbH
              Tim Kornau (tim.kornau@zynamics.com) zynamics GmbH
 Ralf-Philipp Weinmann (ralf-philipp.weinmann@uni.lu) Université du Luxembourg
                                BlackHat Vegas 2010
Overview

1. Introduction
2. Gentle overview
3. Finding gadgets
4. Compile gadgets
5. Some fancy demos
6. Further work
Introduction



   Exploitation with non-
executable pages is not much
             fun
But we have funny ideas



    Exploitation with non-
executable pages is not much
fun.. Unless you use “return-
   oriented programming”
Gentle introduction
But life is hard


Code signing
                       Sandboxing


  ROP
                    We were lucky!
Code Signing


Used to make sure that only signed
(Apple verified) binaries can be executed

• If a page has write permissions it can’t
have executable permissions
• No executable pages on the heap
• Only signed pages can be executed
ROP

       Instructions           Variables for the gadget

     return sequence         Address of the next gadget

       Instructions           Variables for the gadget

     return sequence         Address of the next gadget

       Instructions           Variables for the gadget

     return sequence         Address of the next gadget

       Instructions           Variables for the gadget

     return sequence         Address of the next gadget


Instruction sequences           Attacker controlled
within the attacked binary      memory
ROP - Workflow



1. Find the gadgets

2. Chain them to form a payload

3. Test the payload on your target
Finding Gadgets Overview

1. Goal definition
2. Motivation
3. Strategy
4. Algorithms
5. Results
6. Further improvement
Goal definition



 Build an algorithm which is
 capable of locating gadgets
    within a given binary
automatically without major
         side effects.
Motivation I




Little spirits need access to a wide range of devices.
Because what is a device without a spirit?
Motivation II

We want to be able to execute our code:
• in the presents of non-executable protection (AKA
NX bit)

• when code signing of binaries is enabled.

• but we do not aim at ASLR.
Strategy I


• Build a program from parts of another program
• These parts are named gadgets
• A gadget is a sequence of (useable) instructions
• Gadget combination must be possible
   • end in a “free-branch”
• Gadgets must provide a useful operation
   • for example A + B
Strategy II

• The subset of useful gadgets must be locatable in
the set of all gadgets
• Only the “simplest” gadget for an operation
should be used
• Side effects of gadgets must be near to zero to
avoid destroying results of previous executed code
sequences.
• Use the REIL meta language to be platform
independent.
Strategy III
A small introduction to the REIL meta language
• small RISC instruction set (17 instructions)
   • Arithmetic instructions (ADD, SUB, MUL,   DIV, MOD, BSH)
   • Bitwise instructions (AND, OR, XOR)
   • Logical instructions (BISZ, JCC)
   • Data transfer instructions (LDM, STM, STR)
   • Other instructions (NOP, UNDEF, UNKN)

• register machine
• unlimited number of temp registers
• side effect free
• no exceptions, floating point, 64Bit, ..
Algorithms



• Stage I → Collect data from the binary

• Stage II → Merge the collected data

• Stage III → Locate useful gadgets in merged data
Algorithms stage I (I)

Goal of the stage I algorithms:
  • Collect data from the binary
     1. Extract expression trees from native
         instructions
                                        A
     2. Extract path information

                                  B
          +
                                               D
                                  C
   R0          15
                                        E
Algorithms stage I (II)

Details of the stage I algorithms:
1. Expression tree extraction
   • Handlers for each possible REIL instruction
     1. Most of the handlers are simple transformations
     2. STM and JCC need to be treated specially
2. Path extraction
   • Path is extracted in reverse control flow order
             +                 *
  *
                                   OP
                        BISZ
        OP
COND
                 COND
Algorithms stage II (I)

Goal of the stage II algorithms:
  • Merge the collected data from stage I
     1. Combine the expression trees for single
         native instructions along a path
     2. Determine jump conditions on the path
     3. Simplify the result
Algorithms stage II (II)

Details of the stage II algorithms:
  • Combine the expression trees for single native
  instructions along a path
1.   0x00000001 ADD R0, R1, R2
2.   0x00000002 STR R0, R4
3.   0x00000003 LDMFD SP! {R4,LR}
4.   0x00000004 BX LR
Algorithms stage II (III)

Details of the stage II algorithms:
  • Determine jump conditions on the path:
                                                         Z FLAG MUST BE FALSE

1.   0x00000001 SOME INSTRUCTION
2.   0x00000002 BEQ 0xADDRESS
                                                         Generate condition tree
3.   0x00000003 SOME INSTRUCTION
4.   0x00000004 SOME INSTRUCTION



     • Simplify the result:
       R0 = ((((((R2+4)+4)+4)+4) OR 0) AND 0xFFFFFFFF)
       R0 = R2+16
Algorithms stage III (I)

Goal of the stage III algorithms:
  • Search for useful gadgets in the merged data
      Use a tree match handler for each
         operation.

  • Select the simplest gadget for each operation
      Use a complexity value to determine the
        gadget which is least complex. (side-
        effects)
Algorithms stage III (II)

Details of the stage III algorithms:
  • Search for useful gadgets in the merged data

                    Trees of a gadget candidate
                    are compared to the tree of a
                    specific operation.
                    Can you spot the match ?
Algorithms stage III (III)

Details of the stage III algorithms:
  • Select the simplest gadget for each operation
                                     There are in most cases
                                     more instruction
                                     sequences which
                                     provide a specific
                                     operation. The overall
                                     complexity of all trees
                                     is used to determine
                                     which gadget is the
                                     simplest.
Results of gadget finding


• Algorithms for automatic return-oriented
programming gadget search are possible.
• The described algorithms automatically find the
necessary parts to build the return-oriented
program.
• Searching for gadgets is not only platform but also
very compiler dependent.
So what is next


After automatic gadget extraction
we need a simple and effective way
        to combine them.
Chaining gadgets
Chaining gadgets



 … by hand is like playing Tetris
 With very ugly blocks

 Each gadget set defines custom ISA

 We have better scores that at...
Chaining gadgets
Chaining gadgets



 Hence we have decided to
   bring in some help...
The Wolf



 A ROP compiler for gadget
sets with side-effects
 Very basic language

 Allows for easy ROPperies on

ARM devices
Living with side-effects

 “allowread”: specifies readable memory
ranges
 “allowcorrupt”: expendable memory

ranges
 [corruption may occur here]

 protect: registers must stay invariant

 [SP and PC implicitly guarded]
Statements

 (multi-)assignment
 Conditional goto statement

 Call statement (calling lib functions)

 Data definitions

 Labels for data/code
Multi-assignment

     Example from PWN2OWN payload:

(r0, r1, r2) <<_| (mem[sockloc], sin, SIZE_SIN)

targets        memory read         constant

assignment operator         data reference
Loops
                                      define label for
label(clear_loop)                     conditional jump
r1 = 256
(mem[r0], r2, r1) <<_| (0, (3*r1) & 255, r1-1)
r0 = r0+4
gotoifnz(r1, clear_loop)



RHS may contain arithmetic-logical
calculations:
{+,-,*,/, %, ^, |, &, <<, >>}
Hired help: STP



 Mr. Wolf is a high-level problem solver:
he likes to delegate
 Menial work: let someone else do it

 In this case STP

 [Simple Theorem Prover]
What is STP?

 Constraint solver for problems involving bit-
vectors and arrays
 Open-source, written by Vijay Ganesh

 Used for model-checking, theorem proving,

EXE, etc.
 Gives Boolean answer whether formula is

satisfiable & assignment if it is
STP formulae

Just a bunch of assertions in QF_ABV

Simple example:

 x0 : BITVECTOR(4);
 ...

 x9 : BITVECTOR(4);

 ASSERT (BVPLUS(4,BVMULT(4,x0, 0hex6), 0hex0, 0hex0,

      BVMULT(4,x3, 0hex7), BVMULT(4,x4, 0hex4),
      BVMULT(4,x5, 0hex6), BVMULT(4,x6, 0hex4),
      0hex0, 0hex0, BVMULT(4,x9, 0hex8),0hex0) = 0hex7);
High-level algorithm


For multi-assignments:

1.   Find all gadgets assigning to targets
2.   Verify constraints for each
     (protect/memread/memcorrupt)
3.   Find all gadgets for expressions on RHS
4.   Chain expression gadgets
5.   Connect LHS and RHS
Notes on chaining algorithm

 Chaining for arithmetic/logical expressions
may use registers/memory locations for
temporary results
 Multi-assignments give us freedom

 Algorithm sometimes may fail because

constraints cannot be satisfied [insufficient
gadgets]
K got the payload, now?


You could test it on a jailbroken phone

• Does not match reality!
• No code signing for instance
• Still an option if exploit reliability is not
your primary concern
K got the payload, now?


You could test it on a developer phone

• Have a small application to reproduce a
“ROP scenario”
• Depending on the application you’re
targeting the sandbox policy is different
• Still closer to reality
Simple plan


• Allocate a buffer on the heap
• Fill the buffer with the shellcode
• Point the stack pointer to the beginning
of the attacker controlled memory
• Execute the payload
• Restore
Future work


• Port to other platforms (eg: x86)
• Abstract language to describe gadgets
• Try to avoid “un-decidable” constraints
• Make it more flexible to help when
ASLR is in place
Thanks for your time




        Questions?

Más contenido relacionado

La actualidad más candente

Detecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic SearchDetecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic SearchShinpei Hayashi
 
1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTPJordi Llonch
 
EXTENT-2016: Industry Practices of Advanced Program Analysis
EXTENT-2016: Industry Practices of Advanced Program AnalysisEXTENT-2016: Industry Practices of Advanced Program Analysis
EXTENT-2016: Industry Practices of Advanced Program AnalysisIosif Itkin
 
Data types and Operators Continued
Data types and Operators ContinuedData types and Operators Continued
Data types and Operators ContinuedMohamed Samy
 
Kostis Sagonas: Cool Tools for Modern Erlang Program Developmen
Kostis Sagonas: Cool Tools for Modern Erlang Program DevelopmenKostis Sagonas: Cool Tools for Modern Erlang Program Developmen
Kostis Sagonas: Cool Tools for Modern Erlang Program DevelopmenKonstantin Sorokin
 
45 aop-programming
45 aop-programming45 aop-programming
45 aop-programmingdaotuan85
 
P04 restricted boltzmann machines cvpr2012 deep learning methods for vision
P04 restricted boltzmann machines cvpr2012 deep learning methods for visionP04 restricted boltzmann machines cvpr2012 deep learning methods for vision
P04 restricted boltzmann machines cvpr2012 deep learning methods for visionzukun
 
14.jun.2012
14.jun.201214.jun.2012
14.jun.2012Tech_MX
 
Sentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain OntologiesSentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain OntologiesShinpei Hayashi
 
Bert pre_training_of_deep_bidirectional_transformers_for_language_understanding
Bert  pre_training_of_deep_bidirectional_transformers_for_language_understandingBert  pre_training_of_deep_bidirectional_transformers_for_language_understanding
Bert pre_training_of_deep_bidirectional_transformers_for_language_understandingThyrixYang1
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipelineGirish Ghate
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Iffat Anjum
 
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language UnderstandingBERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language UnderstandingMinh Pham
 
Programmable logic devices
Programmable logic devicesProgrammable logic devices
Programmable logic devicesISMT College
 

La actualidad más candente (20)

Detecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic SearchDetecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic Search
 
Al2ed chapter5
Al2ed chapter5Al2ed chapter5
Al2ed chapter5
 
1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP1 hour dive into Erlang/OTP
1 hour dive into Erlang/OTP
 
Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
 
EXTENT-2016: Industry Practices of Advanced Program Analysis
EXTENT-2016: Industry Practices of Advanced Program AnalysisEXTENT-2016: Industry Practices of Advanced Program Analysis
EXTENT-2016: Industry Practices of Advanced Program Analysis
 
Data types and Operators Continued
Data types and Operators ContinuedData types and Operators Continued
Data types and Operators Continued
 
Kostis Sagonas: Cool Tools for Modern Erlang Program Developmen
Kostis Sagonas: Cool Tools for Modern Erlang Program DevelopmenKostis Sagonas: Cool Tools for Modern Erlang Program Developmen
Kostis Sagonas: Cool Tools for Modern Erlang Program Developmen
 
45 aop-programming
45 aop-programming45 aop-programming
45 aop-programming
 
P04 restricted boltzmann machines cvpr2012 deep learning methods for vision
P04 restricted boltzmann machines cvpr2012 deep learning methods for visionP04 restricted boltzmann machines cvpr2012 deep learning methods for vision
P04 restricted boltzmann machines cvpr2012 deep learning methods for vision
 
14.jun.2012
14.jun.201214.jun.2012
14.jun.2012
 
Sentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain OntologiesSentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain Ontologies
 
Bert pre_training_of_deep_bidirectional_transformers_for_language_understanding
Bert  pre_training_of_deep_bidirectional_transformers_for_language_understandingBert  pre_training_of_deep_bidirectional_transformers_for_language_understanding
Bert pre_training_of_deep_bidirectional_transformers_for_language_understanding
 
Lect04
Lect04Lect04
Lect04
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipeline
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
Bert
BertBert
Bert
 
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language UnderstandingBERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
 
args_types
args_typesargs_types
args_types
 
Encryption basics
Encryption basicsEncryption basics
Encryption basics
 
Programmable logic devices
Programmable logic devicesProgrammable logic devices
Programmable logic devices
 

Similar a ROP Gadgets for Non-Executable Pages

cinema_time_new.pdf
cinema_time_new.pdfcinema_time_new.pdf
cinema_time_new.pdfMaxDmitriev
 
Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes Jonathan Salwan
 
Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Nelson Brito
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerMarina Kolpakova
 
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012DefCamp
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsRajendran
 
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...CODE BLUE
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONLyon Yang
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the ArduinoWingston
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeDmitri Nesteruk
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...Positive Hack Days
 
Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)Emilio Coppa
 
JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixCodemotion Tel Aviv
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...chen yuki
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013midnite_runr
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangLyon Yang
 
introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfintroductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfHebaEng
 

Similar a ROP Gadgets for Non-Executable Pages (20)

cinema_time_new.pdf
cinema_time_new.pdfcinema_time_new.pdf
cinema_time_new.pdf
 
Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes
 
Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
 
Fedor Polyakov - Optimizing computer vision problems on mobile platforms
Fedor Polyakov - Optimizing computer vision problems on mobile platforms Fedor Polyakov - Optimizing computer vision problems on mobile platforms
Fedor Polyakov - Optimizing computer vision problems on mobile platforms
 
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
 
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
 
Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)
 
JVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, WixJVM Memory Model - Yoav Abrahami, Wix
JVM Memory Model - Yoav Abrahami, Wix
 
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
2013 syscan360 yuki_chen_syscan360_exploit your java native vulnerabilities o...
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
 
introductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdfintroductiontoarduino-111120102058-phpapp02.pdf
introductiontoarduino-111120102058-phpapp02.pdf
 

Más de zynamics GmbH

Automated Mobile Malware Classification
Automated Mobile Malware ClassificationAutomated Mobile Malware Classification
Automated Mobile Malware Classificationzynamics GmbH
 
Applications of the Reverse Engineering Language REIL
Applications of the Reverse Engineering Language REILApplications of the Reverse Engineering Language REIL
Applications of the Reverse Engineering Language REILzynamics GmbH
 
VxClass for Incident Response
VxClass for Incident ResponseVxClass for Incident Response
VxClass for Incident Responsezynamics GmbH
 
Malware classification
Malware classificationMalware classification
Malware classificationzynamics GmbH
 
Automated static deobfuscation in the context of Reverse Engineering
Automated static deobfuscation in the context of Reverse EngineeringAutomated static deobfuscation in the context of Reverse Engineering
Automated static deobfuscation in the context of Reverse Engineeringzynamics GmbH
 

Más de zynamics GmbH (8)

Automated Mobile Malware Classification
Automated Mobile Malware ClassificationAutomated Mobile Malware Classification
Automated Mobile Malware Classification
 
Applications of the Reverse Engineering Language REIL
Applications of the Reverse Engineering Language REILApplications of the Reverse Engineering Language REIL
Applications of the Reverse Engineering Language REIL
 
VxClass for Incident Response
VxClass for Incident ResponseVxClass for Incident Response
VxClass for Incident Response
 
Malware classification
Malware classificationMalware classification
Malware classification
 
Hitb
HitbHitb
Hitb
 
Eusecwest
EusecwestEusecwest
Eusecwest
 
Bh dc09
Bh dc09Bh dc09
Bh dc09
 
Automated static deobfuscation in the context of Reverse Engineering
Automated static deobfuscation in the context of Reverse EngineeringAutomated static deobfuscation in the context of Reverse Engineering
Automated static deobfuscation in the context of Reverse Engineering
 

Último

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

ROP Gadgets for Non-Executable Pages

  • 1. Everybody be cool, this is a roppery! Vincenzo Iozzo (vincenzo.iozzo@zynamics.com) zynamics GmbH Tim Kornau (tim.kornau@zynamics.com) zynamics GmbH Ralf-Philipp Weinmann (ralf-philipp.weinmann@uni.lu) Université du Luxembourg BlackHat Vegas 2010
  • 2. Overview 1. Introduction 2. Gentle overview 3. Finding gadgets 4. Compile gadgets 5. Some fancy demos 6. Further work
  • 3. Introduction Exploitation with non- executable pages is not much fun
  • 4. But we have funny ideas Exploitation with non- executable pages is not much fun.. Unless you use “return- oriented programming”
  • 6. But life is hard Code signing Sandboxing ROP We were lucky!
  • 7. Code Signing Used to make sure that only signed (Apple verified) binaries can be executed • If a page has write permissions it can’t have executable permissions • No executable pages on the heap • Only signed pages can be executed
  • 8. ROP Instructions Variables for the gadget return sequence Address of the next gadget Instructions Variables for the gadget return sequence Address of the next gadget Instructions Variables for the gadget return sequence Address of the next gadget Instructions Variables for the gadget return sequence Address of the next gadget Instruction sequences Attacker controlled within the attacked binary memory
  • 9. ROP - Workflow 1. Find the gadgets 2. Chain them to form a payload 3. Test the payload on your target
  • 10. Finding Gadgets Overview 1. Goal definition 2. Motivation 3. Strategy 4. Algorithms 5. Results 6. Further improvement
  • 11. Goal definition Build an algorithm which is capable of locating gadgets within a given binary automatically without major side effects.
  • 12. Motivation I Little spirits need access to a wide range of devices. Because what is a device without a spirit?
  • 13. Motivation II We want to be able to execute our code: • in the presents of non-executable protection (AKA NX bit) • when code signing of binaries is enabled. • but we do not aim at ASLR.
  • 14. Strategy I • Build a program from parts of another program • These parts are named gadgets • A gadget is a sequence of (useable) instructions • Gadget combination must be possible • end in a “free-branch” • Gadgets must provide a useful operation • for example A + B
  • 15. Strategy II • The subset of useful gadgets must be locatable in the set of all gadgets • Only the “simplest” gadget for an operation should be used • Side effects of gadgets must be near to zero to avoid destroying results of previous executed code sequences. • Use the REIL meta language to be platform independent.
  • 16. Strategy III A small introduction to the REIL meta language • small RISC instruction set (17 instructions) • Arithmetic instructions (ADD, SUB, MUL, DIV, MOD, BSH) • Bitwise instructions (AND, OR, XOR) • Logical instructions (BISZ, JCC) • Data transfer instructions (LDM, STM, STR) • Other instructions (NOP, UNDEF, UNKN) • register machine • unlimited number of temp registers • side effect free • no exceptions, floating point, 64Bit, ..
  • 17. Algorithms • Stage I → Collect data from the binary • Stage II → Merge the collected data • Stage III → Locate useful gadgets in merged data
  • 18. Algorithms stage I (I) Goal of the stage I algorithms: • Collect data from the binary 1. Extract expression trees from native instructions A 2. Extract path information B + D C R0 15 E
  • 19. Algorithms stage I (II) Details of the stage I algorithms: 1. Expression tree extraction • Handlers for each possible REIL instruction 1. Most of the handlers are simple transformations 2. STM and JCC need to be treated specially 2. Path extraction • Path is extracted in reverse control flow order + * * OP BISZ OP COND COND
  • 20. Algorithms stage II (I) Goal of the stage II algorithms: • Merge the collected data from stage I 1. Combine the expression trees for single native instructions along a path 2. Determine jump conditions on the path 3. Simplify the result
  • 21. Algorithms stage II (II) Details of the stage II algorithms: • Combine the expression trees for single native instructions along a path 1. 0x00000001 ADD R0, R1, R2 2. 0x00000002 STR R0, R4 3. 0x00000003 LDMFD SP! {R4,LR} 4. 0x00000004 BX LR
  • 22. Algorithms stage II (III) Details of the stage II algorithms: • Determine jump conditions on the path: Z FLAG MUST BE FALSE 1. 0x00000001 SOME INSTRUCTION 2. 0x00000002 BEQ 0xADDRESS Generate condition tree 3. 0x00000003 SOME INSTRUCTION 4. 0x00000004 SOME INSTRUCTION • Simplify the result: R0 = ((((((R2+4)+4)+4)+4) OR 0) AND 0xFFFFFFFF) R0 = R2+16
  • 23. Algorithms stage III (I) Goal of the stage III algorithms: • Search for useful gadgets in the merged data  Use a tree match handler for each operation. • Select the simplest gadget for each operation  Use a complexity value to determine the gadget which is least complex. (side- effects)
  • 24. Algorithms stage III (II) Details of the stage III algorithms: • Search for useful gadgets in the merged data Trees of a gadget candidate are compared to the tree of a specific operation. Can you spot the match ?
  • 25. Algorithms stage III (III) Details of the stage III algorithms: • Select the simplest gadget for each operation There are in most cases more instruction sequences which provide a specific operation. The overall complexity of all trees is used to determine which gadget is the simplest.
  • 26. Results of gadget finding • Algorithms for automatic return-oriented programming gadget search are possible. • The described algorithms automatically find the necessary parts to build the return-oriented program. • Searching for gadgets is not only platform but also very compiler dependent.
  • 27. So what is next After automatic gadget extraction we need a simple and effective way to combine them.
  • 29. Chaining gadgets  … by hand is like playing Tetris  With very ugly blocks  Each gadget set defines custom ISA  We have better scores that at...
  • 31. Chaining gadgets Hence we have decided to bring in some help...
  • 32. The Wolf  A ROP compiler for gadget sets with side-effects  Very basic language  Allows for easy ROPperies on ARM devices
  • 33. Living with side-effects  “allowread”: specifies readable memory ranges  “allowcorrupt”: expendable memory ranges  [corruption may occur here]  protect: registers must stay invariant  [SP and PC implicitly guarded]
  • 34. Statements  (multi-)assignment  Conditional goto statement  Call statement (calling lib functions)  Data definitions  Labels for data/code
  • 35. Multi-assignment Example from PWN2OWN payload: (r0, r1, r2) <<_| (mem[sockloc], sin, SIZE_SIN) targets memory read constant assignment operator data reference
  • 36. Loops define label for label(clear_loop) conditional jump r1 = 256 (mem[r0], r2, r1) <<_| (0, (3*r1) & 255, r1-1) r0 = r0+4 gotoifnz(r1, clear_loop) RHS may contain arithmetic-logical calculations: {+,-,*,/, %, ^, |, &, <<, >>}
  • 37. Hired help: STP  Mr. Wolf is a high-level problem solver: he likes to delegate  Menial work: let someone else do it  In this case STP  [Simple Theorem Prover]
  • 38. What is STP?  Constraint solver for problems involving bit- vectors and arrays  Open-source, written by Vijay Ganesh  Used for model-checking, theorem proving, EXE, etc.  Gives Boolean answer whether formula is satisfiable & assignment if it is
  • 39. STP formulae Just a bunch of assertions in QF_ABV Simple example:  x0 : BITVECTOR(4);  ...  x9 : BITVECTOR(4);  ASSERT (BVPLUS(4,BVMULT(4,x0, 0hex6), 0hex0, 0hex0,  BVMULT(4,x3, 0hex7), BVMULT(4,x4, 0hex4),  BVMULT(4,x5, 0hex6), BVMULT(4,x6, 0hex4),  0hex0, 0hex0, BVMULT(4,x9, 0hex8),0hex0) = 0hex7);
  • 40. High-level algorithm For multi-assignments: 1. Find all gadgets assigning to targets 2. Verify constraints for each (protect/memread/memcorrupt) 3. Find all gadgets for expressions on RHS 4. Chain expression gadgets 5. Connect LHS and RHS
  • 41. Notes on chaining algorithm  Chaining for arithmetic/logical expressions may use registers/memory locations for temporary results  Multi-assignments give us freedom  Algorithm sometimes may fail because constraints cannot be satisfied [insufficient gadgets]
  • 42. K got the payload, now? You could test it on a jailbroken phone • Does not match reality! • No code signing for instance • Still an option if exploit reliability is not your primary concern
  • 43. K got the payload, now? You could test it on a developer phone • Have a small application to reproduce a “ROP scenario” • Depending on the application you’re targeting the sandbox policy is different • Still closer to reality
  • 44. Simple plan • Allocate a buffer on the heap • Fill the buffer with the shellcode • Point the stack pointer to the beginning of the attacker controlled memory • Execute the payload • Restore
  • 45. Future work • Port to other platforms (eg: x86) • Abstract language to describe gadgets • Try to avoid “un-decidable” constraints • Make it more flexible to help when ASLR is in place
  • 46. Thanks for your time Questions?