SlideShare a Scribd company logo
Advance ROP Attacks

     Rashid Bhatt

      @raashidbhatt
Agenda
• Introduction to ROP Attacks

• ROP Attack Variants

• Alphanumeric ROP exploits

• Searching gadgets

• Questions?
ROP Attacks
•   Introduced by hovad shacham
•   Circumvents DEP (data execution prevention)
•   Turing Complete`ness
•   More useful than ret-2-lib ( branching)
•   Applicable to various architectures
ROP Attacks
• Gadgets are the building blocks
• Gadgets end with RET instruction
• Example gadgets
     •   Mov eax, ebx
     •   Ret
     •   Pop eax
     •   Ret
ROP attacks
    x86 stack layout
    . Registers ebp and esp point to base and top of the
stack respective
    . EBP used to access local and passed paramters
    eg . [ebp + 8] first parameter (EBP + 4) for ret
address
    . ESP used are a pointer for popping values out from
stack
ROP attacks
• RET x86 instruction
     • Pops a value from the stack into EIP

     • Used to return control from a function

     • RET can have a argument eg RET 8

     • RET 8 == EIP = stack[top], add ESP , 8
X86 stack layout
                             calling conventions
                             __stdcall ( varadic arguments)
Int __stdcall function(int a, int b) // < paramerts
              {
                             int b,c; // local c variables
                             return 0;
              }
function(10, 20); // function call __stdcall

X86 disassembly

              push 20 // arguments pushed from right to left
              push 10
              call function
function:
              push ebp                                        // Stack epilouge
              mov ebp, esp
              sub esp, 8                                      //8 bytes for two variabeles
              ….
              ….
              add esp, 8
              pop ebp
              ret 8                                           // ret 8 stack clearance by callie
X86 stack layout
                             calling conventions
                             __cdecl( const no of args)
Int __cdelc function(int a, int b) // < paramerts
              {
                             int b,c; // local c variables
                             return 0;
              }
function(10, 20); // function call __cdecl

X86 disassembly

              push 20 // arguments pushed from right to left
              push 10
              call function
              add esp, 8 // stack clearance
function:
              push ebp                                       // Stack epilouge
              mov ebp, esp
              sub esp, 8                                     //8 bytes for two variabeles
              ….
              ….
              add esp, 8
              pop ebp
              ret                                            // ret no stack clearence
Basic stack overflow
• A local stack variable gets overflowed

• CALL instruction pushes the EIP to the stack

• Find a trampoline eg jmp esp to change the
  value to eip to attacker controlled buffer

• demo
What about NX bit ?
• DEP restricts the execution of segments
  marked as r/w
• We can re-use code from the address space of
  executable
• Useful code chunks called as ROP gadgets
• Multiple gadgets can be chained together and
  even API calls
ROP Basics(load and store gadgets)
• storing and loading values from and into
  memory

• Primitive example pop eax; ret / pop ebx ret/ pop r32, ret

• To memory store           pop eax, pop edx, ret / mov [eax], edx; ret
Wait a sec!
            » Handling NULL bytes



•   Some parameters contain NULL
•   Even some addresses contain zero values
•   Cannot inject NULL or zero values
•   Bug prone functions eg strcpy stop copying
    when they encounter a NULL byte (00 hex)
Handling NULL bytes
•   Let x = value containing a ( many) NULL byte
•   Let y = mask = 0xffffffff
•   Mathematical axiom
•   A xor B = z (say)
•   Now z xor B = A
•   We can 0x00000000 xor 0xffffffff = z (say)
•   Xor it back to get the original value
•   We have xor esi, ebx ; ret!
ROP basics(arithmetic )
• Msvcrt32.dll 0x77c4d6f add ebx, esi; stc; ret

• Kernel32.dll 0x7c902af5 sub eax,ecx; ret

• We have same for mul and div !

• Try in immunity search: add r32, r32;any;ret;

• You will find huge no. of gadgets
ROP basics(LOOPS)
• UNCONDITIONAL LOOPS or INFINITE LOOPS
• Pop back the value in ESP, pop esp;ret
 7C80BCA8 5C     POP ESP //kernel32.dll
 7C80BCA9 C3     RETN
ROP basics(conditional jumps )
• The tricky part
• We need to modify ESP , based on certain
  comparisons
. comparisons include greater than , less than ,
  equal to;
    X <y
    X >y
    X == some_val
.
Comparing with zero
•   Divert flow through adding a certain value to esp

•   Store two values on the stack , value_to_be_checked and esp_delta (the value to
    be added to esp)


• Load the val in a general purpose register say eax
•   X86 instruction NEG computes the two's complement and updates CF

. if val == 0 the CF = 0; else CF = 1
• ADC x86 instruction add the source and dest with carry flag(ADC – add
  with carry flag)
• Make a general purpose reg and zero by xor r32,r32; then apply adc
  r32,32
Comparing with zero(contd..)
•   We have a REG (say eax) containing a single 1 bit or all 0 bits

•   Apply NEG instruction on that REG to obtain the two's complement


• 2's comp will transform it into all zero's or all ones
•   Perform bit-wise AND with ESP_DELTA

.   according we will get ESP_DELTA as zero or its original value


• ADD esp, ESP_DALTA to divert the control flow


• DEMO
Checking for == (equality)
•   Two values val1, val2 to be checked for equality

•   Load two values using load and store gadgets as shown earlier


• Perform x86 SUB val1, val2,store back the result
•   If both the values are same result will be zero,

.   Check the result to zero as show in the previous slide
• ADD esp, ESP_DALTA to divert the control flow


• DEMO
Checking for <, > (less or greater)
•   Two values val1, val2 to be checked for equality

•   Load two values using load and store gadgets as shown earlier


• Perform x86 SUB val1, val2, SUB intruction sets the CF if dest > source
•   Save CF using xor r32, r32;ret; adc r32,r32 ret; as shown in ealier slide

.   CF will be 1 if dest > source else 0
• DEMO
ROP Attack Variants
JUMP oriented Programming
                  Attacks

•   ROP used gadgets ending with RET x86 instruction

•   JOP uses statements ending with Indirect Jump call


• Instead of stack uses a dispatcher table to jump to different locations

•   Thwarts certain Anti-ROP defences
JOP attacks (Dispatch table and
      Dispatcher gadget)
JUMP oriented Programming
                  Attacks

•   Dispatcher gadget increments a REG by certain value to make it point to next loc to
    jump on

•   Add ebx, 4 ; JMP [ebx]


•   Here , EBX points to the Dispatcher table


•   Same gadgets as in ROP attacks
JOP(attack Model)


•   Cannot work on stack buffer overflow , because control flow diverts through a ret
    Instruction
•   Will be detected by anti-ROP defenses if(stack overflow is used)


•   Attack vectors include


•   1: pointer overwrite
•   2: Arbitrary DWORD overwrite
•   3: C++ vtable overwrite
Alphanumeric ROP Shell-code
Alphanumeric ROP Shellcode
•   Traditional Shellcode can be made alphanumeric by choosing only certain
    instruction

Example . pop ecx has an
opcode 0x59 which is the ASCII code of the character Y)



•   Similar technique used in ROP shellcode

.   Selecting a printable address rather than a printable opcode(in trad.
    shellcodes)
Alphanumeric ROP Shellcode
Basic Technique by adding two printable addresses. The range of ASCII printable
   characters is between 0x21 and 0x7e

Example . A non-printable gadget in kernel32.dll at 0x77D4B8C2 {pop ebx;ret} can be
   represented by adding two printable addresses

0X225D414B(printable) + 0x55777777(printable) = 0x77D4B8C2(no-printable)


• Combined together can be used to transform a printable code into non-
  printable
•   Similar technique used in ROP shellcode

.   Selecting a printable address rather than a printable opcode(in trad.
    shellcodes)
Alphanumeric ROP
                   Shellcode(gadgets)
• Gadgets used for decoding addresses should be printable(bytes should be
  in range of 0x21 - 0x7e
•   We also need a memory region which has a printable address to store the
    decoded gadgets addresses marked as r/w

.   From reg to mem we have urlmon.dll
        0x772C2E5E      MOV DWORD PTR DS:[ECX],EAX
. ESP related CRYPTUI.dll 0x775513E30 XCHG EAX,ESP
.   MSCTF.DLL 0x74722973         POP EAX
. Mshtml.dll     0x7D504962         ADD EAX,ECX
. msimtf.dll MEM to reg        0x74714263 MOV EAX,DWORD PTR DS:[ECX]
. All of the dll's loaded by internet explorer
Alphanumeric ROP Shellcode

Alphanumeric ROP Messagebeep Shellcode >>




s)rt:i=3PI'w""w"bIP}PI'www""bIP}PI'w"P`
w^.,wxxxxs)rt"P`w0>Qu

 DEMO
Effectively searching gadgets


•   Immunity debugger search for all sequences in all modules

•   ANY for any no of op codes and any reg


•   Match Different registers eg POP RA, RB ; RA and RB will be different


•   Best Practice search in reverse order
Questions ?

More Related Content

What's hot

gcc and friends
gcc and friendsgcc and friends
gcc and friends
Anil Kumar Pugalia
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O
YourHelper1
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and output
MythiliA5
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
Sam Bowne
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
Sam Bowne
 
Sisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselorSisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselor
Alexandru Radovici
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
Ray Jenkins
 
ARM and SoC Traning Part I -- Overview
ARM and SoC Traning Part I -- OverviewARM and SoC Traning Part I -- Overview
ARM and SoC Traning Part I -- Overview
National Cheng Kung University
 
Unix signals
Unix signalsUnix signals
Unix signals
Isaac George
 
ARM and SoC Traning Part II - System
ARM and SoC Traning Part II - SystemARM and SoC Traning Part II - System
ARM and SoC Traning Part II - System
National Cheng Kung University
 
Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
Angel Boy
 
Ipmi Server Management
Ipmi Server ManagementIpmi Server Management
Ipmi Server Management
sjtu1234567
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
shimosawa
 
4章 Linuxカーネル - 割り込み・例外 3
4章 Linuxカーネル - 割り込み・例外 34章 Linuxカーネル - 割り込み・例外 3
4章 Linuxカーネル - 割り込み・例外 3
mao999
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
Adrian Huang
 
LCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted FirmwareLCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted Firmware
Linaro
 
MacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationMacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) Exploitation
Angel Boy
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
Alexei Starovoitov
 

What's hot (20)

gcc and friends
gcc and friendsgcc and friends
gcc and friends
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and output
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
8086 assembly
8086 assembly8086 assembly
8086 assembly
 
Sisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselorSisteme de Operare: Analiza executabilelor și proceselor
Sisteme de Operare: Analiza executabilelor și proceselor
 
The Internals of "Hello World" Program
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" Program
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
ARM and SoC Traning Part I -- Overview
ARM and SoC Traning Part I -- OverviewARM and SoC Traning Part I -- Overview
ARM and SoC Traning Part I -- Overview
 
Unix signals
Unix signalsUnix signals
Unix signals
 
ARM and SoC Traning Part II - System
ARM and SoC Traning Part II - SystemARM and SoC Traning Part II - System
ARM and SoC Traning Part II - System
 
Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
 
Ipmi Server Management
Ipmi Server ManagementIpmi Server Management
Ipmi Server Management
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
 
4章 Linuxカーネル - 割り込み・例外 3
4章 Linuxカーネル - 割り込み・例外 34章 Linuxカーネル - 割り込み・例外 3
4章 Linuxカーネル - 割り込み・例外 3
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
LCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted FirmwareLCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted Firmware
 
MacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationMacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) Exploitation
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 

Similar to Advance ROP Attacks

The Stack and Buffer Overflows
The Stack and Buffer OverflowsThe Stack and Buffer Overflows
The Stack and Buffer Overflows
UTD Computer Security Group
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
Japneet Singh
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter ppt
Muhammad Sikandar Mustafa
 
Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basics
Cysinfo Cyber Security Community
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
Nora Youssef
 
lec15_x86procedure_4up.pdf
lec15_x86procedure_4up.pdflec15_x86procedure_4up.pdf
lec15_x86procedure_4up.pdf
hasan58964
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
securityxploded
 
Exploitation Crash Course
Exploitation Crash CourseExploitation Crash Course
Exploitation Crash Course
UTD Computer Security Group
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
commiebstrd
 
1. For each instruction, give the 80x86 opcode and total number of b.docx
1. For each instruction, give the 80x86 opcode and total number of b.docx1. For each instruction, give the 80x86 opcode and total number of b.docx
1. For each instruction, give the 80x86 opcode and total number of b.docx
blondellchancy
 
04basic Concepts
04basic Concepts04basic Concepts
04basic ConceptsZhiwen Guo
 
Assembly language
Assembly languageAssembly language
Assembly language
Piyush Jain
 
CNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in LinuxCNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in Linux
Sam Bowne
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
Selomon birhane
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
Sam Bowne
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Willem van Ketwich
 
Basic ASM by @binaryheadache
Basic ASM by @binaryheadacheBasic ASM by @binaryheadache
Basic ASM by @binaryheadache
camsec
 
Coal (1)
Coal (1)Coal (1)
Coal (1)
talhashahid40
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDB
Jian-Yu Li
 

Similar to Advance ROP Attacks (20)

The Stack and Buffer Overflows
The Stack and Buffer OverflowsThe Stack and Buffer Overflows
The Stack and Buffer Overflows
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter ppt
 
Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basics
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
 
lec15_x86procedure_4up.pdf
lec15_x86procedure_4up.pdflec15_x86procedure_4up.pdf
lec15_x86procedure_4up.pdf
 
Assem -lect-6
Assem -lect-6Assem -lect-6
Assem -lect-6
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
 
Exploitation Crash Course
Exploitation Crash CourseExploitation Crash Course
Exploitation Crash Course
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
 
1. For each instruction, give the 80x86 opcode and total number of b.docx
1. For each instruction, give the 80x86 opcode and total number of b.docx1. For each instruction, give the 80x86 opcode and total number of b.docx
1. For each instruction, give the 80x86 opcode and total number of b.docx
 
04basic Concepts
04basic Concepts04basic Concepts
04basic Concepts
 
Assembly language
Assembly languageAssembly language
Assembly language
 
CNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in LinuxCNIT 127: Ch 2: Stack Overflows in Linux
CNIT 127: Ch 2: Stack Overflows in Linux
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
 
Basic ASM by @binaryheadache
Basic ASM by @binaryheadacheBasic ASM by @binaryheadache
Basic ASM by @binaryheadache
 
Coal (1)
Coal (1)Coal (1)
Coal (1)
 
X86 assembly & GDB
X86 assembly & GDBX86 assembly & GDB
X86 assembly & GDB
 

More from n|u - The Open Security Community

Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)
n|u - The Open Security Community
 
SSRF exploit the trust relationship
SSRF exploit the trust relationshipSSRF exploit the trust relationship
SSRF exploit the trust relationship
n|u - The Open Security Community
 
Metasploit primary
Metasploit primaryMetasploit primary
Api security-testing
Api security-testingApi security-testing
Api security-testing
n|u - The Open Security Community
 
Introduction to TLS 1.3
Introduction to TLS 1.3Introduction to TLS 1.3
Introduction to TLS 1.3
n|u - The Open Security Community
 
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
n|u - The Open Security Community
 
Talking About SSRF,CRLF
Talking About SSRF,CRLFTalking About SSRF,CRLF
Talking About SSRF,CRLF
n|u - The Open Security Community
 
Building active directory lab for red teaming
Building active directory lab for red teamingBuilding active directory lab for red teaming
Building active directory lab for red teaming
n|u - The Open Security Community
 
Owning a company through their logs
Owning a company through their logsOwning a company through their logs
Owning a company through their logs
n|u - The Open Security Community
 
Introduction to shodan
Introduction to shodanIntroduction to shodan
Introduction to shodan
n|u - The Open Security Community
 
Cloud security
Cloud security Cloud security
Detecting persistence in windows
Detecting persistence in windowsDetecting persistence in windows
Detecting persistence in windows
n|u - The Open Security Community
 
Frida - Objection Tool Usage
Frida - Objection Tool UsageFrida - Objection Tool Usage
Frida - Objection Tool Usage
n|u - The Open Security Community
 
OSQuery - Monitoring System Process
OSQuery - Monitoring System ProcessOSQuery - Monitoring System Process
OSQuery - Monitoring System Process
n|u - The Open Security Community
 
DevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -SecurityDevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -Security
n|u - The Open Security Community
 
Extensible markup language attacks
Extensible markup language attacksExtensible markup language attacks
Extensible markup language attacks
n|u - The Open Security Community
 
Linux for hackers
Linux for hackersLinux for hackers
Android Pentesting
Android PentestingAndroid Pentesting

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

Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)
 
Osint primer
Osint primerOsint primer
Osint primer
 
SSRF exploit the trust relationship
SSRF exploit the trust relationshipSSRF exploit the trust relationship
SSRF exploit the trust relationship
 
Nmap basics
Nmap basicsNmap basics
Nmap basics
 
Metasploit primary
Metasploit primaryMetasploit primary
Metasploit primary
 
Api security-testing
Api security-testingApi security-testing
Api security-testing
 
Introduction to TLS 1.3
Introduction to TLS 1.3Introduction to TLS 1.3
Introduction to TLS 1.3
 
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
 
Talking About SSRF,CRLF
Talking About SSRF,CRLFTalking About SSRF,CRLF
Talking About SSRF,CRLF
 
Building active directory lab for red teaming
Building active directory lab for red teamingBuilding active directory lab for red teaming
Building active directory lab for red teaming
 
Owning a company through their logs
Owning a company through their logsOwning a company through their logs
Owning a company through their logs
 
Introduction to shodan
Introduction to shodanIntroduction to shodan
Introduction to shodan
 
Cloud security
Cloud security Cloud security
Cloud security
 
Detecting persistence in windows
Detecting persistence in windowsDetecting persistence in windows
Detecting persistence in windows
 
Frida - Objection Tool Usage
Frida - Objection Tool UsageFrida - Objection Tool Usage
Frida - Objection Tool Usage
 
OSQuery - Monitoring System Process
OSQuery - Monitoring System ProcessOSQuery - Monitoring System Process
OSQuery - Monitoring System Process
 
DevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -SecurityDevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -Security
 
Extensible markup language attacks
Extensible markup language attacksExtensible markup language attacks
Extensible markup language attacks
 
Linux for hackers
Linux for hackersLinux for hackers
Linux for hackers
 
Android Pentesting
Android PentestingAndroid Pentesting
Android Pentesting
 

Recently uploaded

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

Advance ROP Attacks

  • 1. Advance ROP Attacks Rashid Bhatt @raashidbhatt
  • 2. Agenda • Introduction to ROP Attacks • ROP Attack Variants • Alphanumeric ROP exploits • Searching gadgets • Questions?
  • 3. ROP Attacks • Introduced by hovad shacham • Circumvents DEP (data execution prevention) • Turing Complete`ness • More useful than ret-2-lib ( branching) • Applicable to various architectures
  • 4. ROP Attacks • Gadgets are the building blocks • Gadgets end with RET instruction • Example gadgets • Mov eax, ebx • Ret • Pop eax • Ret
  • 5. ROP attacks x86 stack layout . Registers ebp and esp point to base and top of the stack respective . EBP used to access local and passed paramters eg . [ebp + 8] first parameter (EBP + 4) for ret address . ESP used are a pointer for popping values out from stack
  • 6. ROP attacks • RET x86 instruction • Pops a value from the stack into EIP • Used to return control from a function • RET can have a argument eg RET 8 • RET 8 == EIP = stack[top], add ESP , 8
  • 7. X86 stack layout calling conventions __stdcall ( varadic arguments) Int __stdcall function(int a, int b) // < paramerts { int b,c; // local c variables return 0; } function(10, 20); // function call __stdcall X86 disassembly push 20 // arguments pushed from right to left push 10 call function function: push ebp // Stack epilouge mov ebp, esp sub esp, 8 //8 bytes for two variabeles …. …. add esp, 8 pop ebp ret 8 // ret 8 stack clearance by callie
  • 8. X86 stack layout calling conventions __cdecl( const no of args) Int __cdelc function(int a, int b) // < paramerts { int b,c; // local c variables return 0; } function(10, 20); // function call __cdecl X86 disassembly push 20 // arguments pushed from right to left push 10 call function add esp, 8 // stack clearance function: push ebp // Stack epilouge mov ebp, esp sub esp, 8 //8 bytes for two variabeles …. …. add esp, 8 pop ebp ret // ret no stack clearence
  • 9. Basic stack overflow • A local stack variable gets overflowed • CALL instruction pushes the EIP to the stack • Find a trampoline eg jmp esp to change the value to eip to attacker controlled buffer • demo
  • 10. What about NX bit ? • DEP restricts the execution of segments marked as r/w • We can re-use code from the address space of executable • Useful code chunks called as ROP gadgets • Multiple gadgets can be chained together and even API calls
  • 11. ROP Basics(load and store gadgets) • storing and loading values from and into memory • Primitive example pop eax; ret / pop ebx ret/ pop r32, ret • To memory store pop eax, pop edx, ret / mov [eax], edx; ret
  • 12. Wait a sec! » Handling NULL bytes • Some parameters contain NULL • Even some addresses contain zero values • Cannot inject NULL or zero values • Bug prone functions eg strcpy stop copying when they encounter a NULL byte (00 hex)
  • 13. Handling NULL bytes • Let x = value containing a ( many) NULL byte • Let y = mask = 0xffffffff • Mathematical axiom • A xor B = z (say) • Now z xor B = A • We can 0x00000000 xor 0xffffffff = z (say) • Xor it back to get the original value • We have xor esi, ebx ; ret!
  • 14. ROP basics(arithmetic ) • Msvcrt32.dll 0x77c4d6f add ebx, esi; stc; ret • Kernel32.dll 0x7c902af5 sub eax,ecx; ret • We have same for mul and div ! • Try in immunity search: add r32, r32;any;ret; • You will find huge no. of gadgets
  • 15. ROP basics(LOOPS) • UNCONDITIONAL LOOPS or INFINITE LOOPS • Pop back the value in ESP, pop esp;ret 7C80BCA8 5C POP ESP //kernel32.dll 7C80BCA9 C3 RETN
  • 16. ROP basics(conditional jumps ) • The tricky part • We need to modify ESP , based on certain comparisons . comparisons include greater than , less than , equal to; X <y X >y X == some_val .
  • 17. Comparing with zero • Divert flow through adding a certain value to esp • Store two values on the stack , value_to_be_checked and esp_delta (the value to be added to esp) • Load the val in a general purpose register say eax • X86 instruction NEG computes the two's complement and updates CF . if val == 0 the CF = 0; else CF = 1 • ADC x86 instruction add the source and dest with carry flag(ADC – add with carry flag) • Make a general purpose reg and zero by xor r32,r32; then apply adc r32,32
  • 18. Comparing with zero(contd..) • We have a REG (say eax) containing a single 1 bit or all 0 bits • Apply NEG instruction on that REG to obtain the two's complement • 2's comp will transform it into all zero's or all ones • Perform bit-wise AND with ESP_DELTA . according we will get ESP_DELTA as zero or its original value • ADD esp, ESP_DALTA to divert the control flow • DEMO
  • 19. Checking for == (equality) • Two values val1, val2 to be checked for equality • Load two values using load and store gadgets as shown earlier • Perform x86 SUB val1, val2,store back the result • If both the values are same result will be zero, . Check the result to zero as show in the previous slide • ADD esp, ESP_DALTA to divert the control flow • DEMO
  • 20. Checking for <, > (less or greater) • Two values val1, val2 to be checked for equality • Load two values using load and store gadgets as shown earlier • Perform x86 SUB val1, val2, SUB intruction sets the CF if dest > source • Save CF using xor r32, r32;ret; adc r32,r32 ret; as shown in ealier slide . CF will be 1 if dest > source else 0 • DEMO
  • 22. JUMP oriented Programming Attacks • ROP used gadgets ending with RET x86 instruction • JOP uses statements ending with Indirect Jump call • Instead of stack uses a dispatcher table to jump to different locations • Thwarts certain Anti-ROP defences
  • 23. JOP attacks (Dispatch table and Dispatcher gadget)
  • 24. JUMP oriented Programming Attacks • Dispatcher gadget increments a REG by certain value to make it point to next loc to jump on • Add ebx, 4 ; JMP [ebx] • Here , EBX points to the Dispatcher table • Same gadgets as in ROP attacks
  • 25. JOP(attack Model) • Cannot work on stack buffer overflow , because control flow diverts through a ret Instruction • Will be detected by anti-ROP defenses if(stack overflow is used) • Attack vectors include • 1: pointer overwrite • 2: Arbitrary DWORD overwrite • 3: C++ vtable overwrite
  • 27. Alphanumeric ROP Shellcode • Traditional Shellcode can be made alphanumeric by choosing only certain instruction Example . pop ecx has an opcode 0x59 which is the ASCII code of the character Y) • Similar technique used in ROP shellcode . Selecting a printable address rather than a printable opcode(in trad. shellcodes)
  • 28. Alphanumeric ROP Shellcode Basic Technique by adding two printable addresses. The range of ASCII printable characters is between 0x21 and 0x7e Example . A non-printable gadget in kernel32.dll at 0x77D4B8C2 {pop ebx;ret} can be represented by adding two printable addresses 0X225D414B(printable) + 0x55777777(printable) = 0x77D4B8C2(no-printable) • Combined together can be used to transform a printable code into non- printable • Similar technique used in ROP shellcode . Selecting a printable address rather than a printable opcode(in trad. shellcodes)
  • 29. Alphanumeric ROP Shellcode(gadgets) • Gadgets used for decoding addresses should be printable(bytes should be in range of 0x21 - 0x7e • We also need a memory region which has a printable address to store the decoded gadgets addresses marked as r/w . From reg to mem we have urlmon.dll 0x772C2E5E MOV DWORD PTR DS:[ECX],EAX . ESP related CRYPTUI.dll 0x775513E30 XCHG EAX,ESP . MSCTF.DLL 0x74722973 POP EAX . Mshtml.dll 0x7D504962 ADD EAX,ECX . msimtf.dll MEM to reg 0x74714263 MOV EAX,DWORD PTR DS:[ECX] . All of the dll's loaded by internet explorer
  • 30. Alphanumeric ROP Shellcode Alphanumeric ROP Messagebeep Shellcode >> s)rt:i=3PI'w""w"bIP}PI'www""bIP}PI'w"P` w^.,wxxxxs)rt"P`w0>Qu DEMO
  • 31. Effectively searching gadgets • Immunity debugger search for all sequences in all modules • ANY for any no of op codes and any reg • Match Different registers eg POP RA, RB ; RA and RB will be different • Best Practice search in reverse order