SlideShare a Scribd company logo
===================================
EXPLOIT TECHNIQUES - A QUICK REVIEW
===================================

Last Modify: 08/12/2011
Author:     luca.mella@studio.unibo.it


Thanks to Corelan Team :)

************************************************************************
*** jmp2reg based exploit *********************************************
************************************************************************

jump (or call) a register that points to the shellcode:
      With this technique, you basically use a register that contains the address
where the shellcode resides and put that address in EIP.
      You try to find the opcode of a jump or call to that register in one of the
dlls that is loaded when the application runs.
      When crafting your payload, instead of overwriting EIP with an address in
memory,
      you need to overwrite EIP with the address of the jump to the register.
      Of course, this only works if one of the available registers contains an
address that points to the shellcode.
      This is how we managed to get our exploit to work in part 1, so I'm not going
to discuss this technique in this post anymore.
      [CLASSICAL]

pop return :
      If none of the registers point directly to the shellcode, but you can see an
address on the stack
      (first, second, address on the stack) that points to the shellcode, then you
can load that value into EIP by first putting
      a pointer to pop ret, or pop pop ret, or pop pop pop ret (all depending on
the location of where the address is found on the stack)
      into EIP.

push return :
      this method is only slightly different than the call register technique.
      If you cannot find a <jump register> or <call register> opcode anywhere, you
could simply put the address on the
      stack and then do a ret.
      So you basically try to find a push <register>, followed by a ret [ ROP
GADGET ? ].
      Find the opcode for this sequence, find an address that performs this
sequence, and overwrite EIP with this address.
      [NICE :D]

jmp [reg + offset] :
      If there is a register that points to the buffer containing the shellcode,
but it does not point at the beginning of the shellcode,
      you can also try to find an instruction in one of the OS or application dlls,
which will add the required bytes to the register and then jumps to the register.
      I'll refer to this method as jmp [reg]+[offset] blind return : in my previous
post I have explained that ESP points to the current stack position (by
definition).
      A RET instruction will pop the last value (4bytes) from the stack and will
put that address in ESP.
      So if you overwrite EIP with the address that will perform a RET instruction,
you will load the value stored at ESP into EIP.
      If you are faced with the fact that the available space in the buffer (after
the EIP overwrite) is limited, but you have plenty of space before overwriting EIP,
then you could use jump code in the smaller buffer to jump to the main shellcode in
the first part of the buffer.

========================================================================
References:
      http://www.corelan.be/index.php/2009/07/23/writing-buffer-overflow-exploits-
a-quick-and-basic-tutorial-part-2/

************************************************************************
*** SEH based exploit *************************************************
************************************************************************

TODO: no time to summarize it :(

User exception handler in the stack:
      http://www.corelan.be:8800/wp-content/uploads/2009/07/image25.png
Detail on the exception handler's list (chain):
      http://www.corelan.be:8800/wp-content/uploads/2009/07/image45.png
SEH exploiting technique (keep in mind the ESP position for understanding it):
      http://www.corelan.be:8800/wp-content/uploads/2010/08/image13.png
========================================================================
References:
      http://www.corelan.be/index.php/2009/07/25/writing-buffer-overflow-exploits-
a-quick-and-basic-tutorial-part-3-seh/

************************************************************************
*** Bypass ALSR+DEP - ROP based exploit *******************************
************************************************************************

Windows DEP options:
      OptIn : Only a limited set of Windows system modules/binaries are protected
by DEP.
      OptOut : All programs, processes, services on the Windows system are
protected, except for processes in the exception list
      AlwaysOn : All programs, processes, services, etc on the Windows system are
protected. No exceptions
      AlwaysOff : DEP is turned off.
      +
      MS Permanent DEP : uses SetProcessDEPPolicy(PROCESS_DEP_ENABLE) to make sure
processes are DEP enabled.

Windows DEP defaults:
      Windows XP SP2, XP SP3, Vista SP0 : OptIn
      Windows Vista SP1 : OptIn + Permanent DEP
      Windows 7: OptIn + Permanent DEP
      Windows Server 2003 SP1 and up : OptOut
      Windows Server 2008 and up : OptOut + Permanent DEP

Change DEP behavior:
      XP and 2003 server                              via boot.ini parameter
            /noexecute=[OptIn|OptOut|AlwaysOn|lwaysOff]
      Vista/Windows 2008/Windows 7        via bcdedit command
            bcdedit.exe /set nx [OptIn|OptOut|AlwaysOn|AlwaysOff]

Windows API functions for bypassing DEP
      VirtualAlloc(MEM_COMMIT + PAGE_READWRITE_EXECUTE) + copy memory : new
executable memory region, copy shellcode, execute
      HeapCreate(HEAP_CREATE_ENABLE_EXECUTE) + HeapAlloc() + copy memory
      SetProcessDEPPolicy()
      : Vista SP1, XP SP3, Server 2008, only if DEP Policy=OptIn|OptOut
      VirtualProtect(PAGE_READ_WRITE_EXECUTE)                               :
change the access protection level of a given memory page
      WriteProcessMemory()
      : the target location must be writable and executable

NOTE :      Each one of those functions requires the stack or registers to be set
up in a specific way.
            Parameters to the function are placed at the top of the stack (= at
ESP).

Primary goal: craft these values on the stack, in a generic and reliable way,
without executing any code from the stack itself.
After crafting the stack, you will most likely end up calling the API. ESP must
point at the API function parameters.
      ---------------------------------------------------------
      |           junk
      |
      |           rop gadgets to craft the stack                             |
      |ESP->      function pointer (to one of the Windows APIs) |
      |           junk (4 bytes)
      |
      |           Function parameter
      |
      |           Function parameter
      |
      |           Function parameter
      |
      |           Maybe some more rop gadgets                                |
      |           nops
      |
      |           shellcode
      |
      |           more data on the stack                                     |
      ---------------------------------------------------------
At that time, a simple "RET" instruction will jump to that address. This will call
the function and will make ESP shift with 4 bytes.
If all goes well, the top of the stack (ESP) points at the function parameters,
when the function is called.

Example:
VirtualAlloc + memcpy. Part of crafted stack..
      ----------------------------------------------------------------------------
      [..]
      |     Pointer to VirtualAlloc |    ESP points here for start the call.
      |     4 bytes junk                 |     Necessary because when entering in
VirtualAlloc, VirtualAlloc will PUSH EIP. He think it is a regular call.
      |     pointer to memcpy       |    Return address field of VirtualAlloc()).
When VirtualAlloc ends, it will return to this address
      |     lpAddress                    |     arbitrary address (where to
allocate new memory. Example 0×00200000)
      |     size                         |     (how big should new memory
allocation be)
      |     flAllocationType        |    0×1000 : MEM_COMMIT
      |     flProtect                    |     0×40 : PAGE_EXECUTE_READWRITE
      |     Arbitrary address       |    Return address for memcpy (same as
lpAddress). used to jump to shellcode after memcpy() returns.
      |     4 bytes junk                 |     Necessary because when entering in
memcpy, memcpy will PUSH EIP. He think it is a regular call.
      |     Arbitrary address       |    same address as lpAddress. Parameter here
will be used as destination address for memcpy().
      |     Address of shellcode    |    source parameter for memcpy().
      |     Size                         |     size parameter for memcpy().
      [..]
      ----------------------------------------------------------------------------

NOTE ON PORTABILITY:
It might be a good idea to verify if the application uses the function that you
want to use to bypass DEP, and see if you can call
that functions using an application/module pointer. That way, you can still make
the exploit portable, without having to generate the
function address, and without having to hardcode addresses from an OS dll.

SUMMARY - HOW TO:

What technique?
      (Windows API) used to bypass DEP and what are the consequences in terms of
stack setup/parameters.
What is the current DEP policy?
What are the ROP GADGETS I can use ?
      (This will be your toolbox and will allow you to craft your stack.)
How to start the chain? How to pivot to your controlled buffer ? (stack pivot)
      In a direct RET exploit, you most likely control ESP, so you can simply
overwrite EIP with a pointer to RETN to kick start the chain
How will you craft the stack ?
      As seen before, we will need to pass a number of parameters to this function.
      These parameters need to sit at the top of the stack at the time the function
gets called.
            option 1) Put the required values in registers and then PUSHAD
            option 2) put some of the params (the static ones/the ones without null
bytes) on the stack already, use ROP GADGETS to calculate the other params and
write them onto the stack.

[ROP GADGET = any instruction followed by a RET]

        -----------------------------------------------------------------------------
-----
      |                       |     junk
      |                       |     eip                     eg. points to a RET
instruction (or a stack pivot?)
      |                       |     junk
      |                       |     rop                     pointer to gadgets and
at least jmp to syscall
      |ESP points here|       parameters        parameters that will be popped by
syscall
      |                       |     more rop
      |                       |     padding / nops
      |                       |     shellcode
      |                       |     junk
      -----------------------------------------------------------------------------
-----

>>> ROP EXPLOIT EXAMPLE >>>
      [Watch picture @ http://www.corelan.be:8800/wp-
content/uploads/2010/06/ropstructure1.png]
>>> Stage 1 : SAVE ESP and JMP over the parameters
      2 of our VirtualProtect() function parameters need to point at our shellcode.
      payload is in the stack, so taking the current stack pointer and storing it
in a register is smart.

      Advantages:
            1)    Easily add/sub the value the reg to make it point at your
shellcode. ADD, SUB, INC, DEC instructions are common.
            2)    Initial value points is pretty close to the stack address where
the pointer to VirtualProtect() is located.
            3)    Close to the stack location of the parameter placeholders.
                  "mov dword ptr ds:[register+offset],register" instruction to
overwrite the parameter placeholder.

      # PUSH ESP # MOV   EAX,EDX # POP EDI # RETN ---> MOV ESP, EDI (EDI is uncommon
register, so this is a   good place to store)
      # PUSH EDI # POP   EAX # POP EBP # RETN           ---> MOV EDI,EAX +     POP
Junk (old ESP = EDI =    EAX)

     Now, jump over params with a gadget like # ADD ESP,20 # RETN

>>> Stage 2 : crafting the first parameter of VirtualProtect() [return address]
      Shellcode is right after the nops...

      # ADD EAX,100 # POP EBP # RETN ---> ADD EAX,0x100     ; So eax = old ESP +
0x100 ...hope will hit the nop sled

      # MOV DWORD PTR DS:[ESI+10],EAX # MOV EAX,ESI # POP ESI # RETN    ---> write
this value onto the stack

     [..]

>>> Stage 3 : crafting the second parameter (lpAddress = location that needs to be
marked executable)

     This means that we can - more or less - repeat the entire sequence from stage
2,
     but before we can do this, we need to reset our start values.

       # PUSH EAX # POP ESI # RETN --->    EAX still holds the initial saved stack
pointer. We have to put it back in ESI

     increase the value in EAX again (add 0x100)
     increase the value in ESI with 4 bytes [ # INC ESI # RETN    (4 times)]

>>> Stage 4 and 5 : third and fourth parameter (size and protection flag)

      The technique to write the resulting value as a parameter is exactly the same
as with the other parameters
            Save EAX into ESI
            Change EAX (XOR EAX,EAX : 0x100307A9, and then ADD EAX,100 + RET, 3
times in a row : 0x1002DC4C)
            Increase ESI with 4 bytes
            Write EAX to ESI+0x10

     The fourth parameter (0x40) uses the same principle again :
           Save EAX into ESI
           Set EAX to zero and then add 40 (XOR EAX,EAX + RET : 0x100307A9     /
ADD EAX,40 + RET : 0x1002DC41)
            Increase ESI with 4 bytes
            Write EAX to ESI+0x10

>>> Final stage : jump to VirtualProtect

      All we need to do now is find a way to make ESP point to the location where
the pointer to VirtualProtect() is stored.
      In this eample EAX already points at this address.

      #SUB EAX,4 # RET        --->   just cause eax doesn't point directly @
virtualprotect pointer
      # PUSH EAX # POP ESP # MOV EAX,EDI # POP EDI # POP ESI # RETN    ---> MOV
EAX,ESP           ; GOGOGO!


========================================================================
References:
      https://www.corelan.be/index.php/2010/06/16/exploit-writing-tutorial-part-10-
chaining-dep-with-rop-the-rubikstm-cube/

************************************************************************
*** Egg Hunting *******************************************************
************************************************************************

     Find shellcode into program memory and jump into it.

      TODO: no time to summarize it :(
========================================================================
References:
      http://www.corelan.be/index.php/2010/01/09/exploit-writing-tutorial-part-8-
win32-egg-hunting/
      https://www.corelan.be/index.php/2011/05/12/hack-notes-ropping-eggs-for-
breakfast/
Ad

More Related Content

What's hot (20)

PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
julien pauli
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
julien pauli
 
Runtime Symbol Resolution
Runtime Symbol ResolutionRuntime Symbol Resolution
Runtime Symbol Resolution
Ken Kawamoto
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
Sheng-Hao Ma
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTS
julien pauli
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
LiviaLiaoFontech
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
julien pauli
 
StackOverflow
StackOverflowStackOverflow
StackOverflow
Susam Pal
 
Advance ROP Attacks
Advance ROP AttacksAdvance ROP Attacks
Advance ROP Attacks
n|u - The Open Security Community
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
charsbar
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension review
julien pauli
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
stn_tkiller
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performances
julien pauli
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
Moriyoshi Koizumi
 
Php engine
Php enginePhp engine
Php engine
julien pauli
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
julien pauli
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
charsbar
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5
julien pauli
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
julien pauli
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
Weber Tsai
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
julien pauli
 
Runtime Symbol Resolution
Runtime Symbol ResolutionRuntime Symbol Resolution
Runtime Symbol Resolution
Ken Kawamoto
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
Sheng-Hao Ma
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTS
julien pauli
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
LiviaLiaoFontech
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
julien pauli
 
StackOverflow
StackOverflowStackOverflow
StackOverflow
Susam Pal
 
typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
charsbar
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension review
julien pauli
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
stn_tkiller
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performances
julien pauli
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
Moriyoshi Koizumi
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
julien pauli
 
What you need to remember when you upload to CPAN
What you need to remember when you upload to CPANWhat you need to remember when you upload to CPAN
What you need to remember when you upload to CPAN
charsbar
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5
julien pauli
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
julien pauli
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
Weber Tsai
 

Similar to Exploit techniques - a quick review (20)

Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Ajin Abraham
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
Payampardaz
 
Exploitation Crash Course
Exploitation Crash CourseExploitation Crash Course
Exploitation Crash Course
UTD Computer Security Group
 
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
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Phil Estes
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
amiable_indian
 
Demystify eBPF JIT Compiler
Demystify eBPF JIT CompilerDemystify eBPF JIT Compiler
Demystify eBPF JIT Compiler
Netronome
 
Bypassing DEP using ROP
Bypassing DEP using ROPBypassing DEP using ROP
Bypassing DEP using ROP
Japneet Singh
 
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
Marina Kolpakova
 
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Elvin Gentiles
 
php & performance
 php & performance php & performance
php & performance
simon8410
 
Reversing & malware analysis training part 4 assembly programming basics
Reversing & malware analysis training part 4   assembly programming basics Reversing & malware analysis training part 4   assembly programming basics
Reversing & malware analysis training part 4 assembly programming basics
Abdulrahman Bassam
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
hughpearse
 
[ASM]Lab6
[ASM]Lab6[ASM]Lab6
[ASM]Lab6
Nora Youssef
 
OpenMP
OpenMPOpenMP
OpenMP
ZongYing Lyu
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
Alexandre Moneger
 
Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06
Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06
Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06
ManhHoangVan
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
Thomas Gregory
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
Akhila Prabhakaran
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
毅 吕
 
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP ChainsExploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Exploit Research and Development Megaprimer: DEP Bypassing with ROP Chains
Ajin Abraham
 
Dive into exploit development
Dive into exploit developmentDive into exploit development
Dive into exploit development
Payampardaz
 
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
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Phil Estes
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
amiable_indian
 
Demystify eBPF JIT Compiler
Demystify eBPF JIT CompilerDemystify eBPF JIT Compiler
Demystify eBPF JIT Compiler
Netronome
 
Bypassing DEP using ROP
Bypassing DEP using ROPBypassing DEP using ROP
Bypassing DEP using ROP
Japneet Singh
 
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
Marina Kolpakova
 
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Elvin Gentiles
 
php & performance
 php & performance php & performance
php & performance
simon8410
 
Reversing & malware analysis training part 4 assembly programming basics
Reversing & malware analysis training part 4   assembly programming basics Reversing & malware analysis training part 4   assembly programming basics
Reversing & malware analysis training part 4 assembly programming basics
Abdulrahman Bassam
 
Low Level Exploits
Low Level ExploitsLow Level Exploits
Low Level Exploits
hughpearse
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
Alexandre Moneger
 
Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06
Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06
Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06Lect-06
ManhHoangVan
 
CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
Thomas Gregory
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
毅 吕
 
Ad

More from Ce.Se.N.A. Security (20)

Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route...
 Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route... Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route...
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route...
Ce.Se.N.A. Security
 
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...
Ce.Se.N.A. Security
 
Msfpayload/Msfencoder cheatsheet
Msfpayload/Msfencoder cheatsheetMsfpayload/Msfencoder cheatsheet
Msfpayload/Msfencoder cheatsheet
Ce.Se.N.A. Security
 
ICTF overview
ICTF overviewICTF overview
ICTF overview
Ce.Se.N.A. Security
 
Anonymous email
Anonymous emailAnonymous email
Anonymous email
Ce.Se.N.A. Security
 
SELinux - overview
SELinux - overviewSELinux - overview
SELinux - overview
Ce.Se.N.A. Security
 
Analisi sulla sicurezza di una autovettura moderna
Analisi sulla sicurezza di una autovettura modernaAnalisi sulla sicurezza di una autovettura moderna
Analisi sulla sicurezza di una autovettura moderna
Ce.Se.N.A. Security
 
Monitoraggio di mac address in lan
Monitoraggio di mac address in lanMonitoraggio di mac address in lan
Monitoraggio di mac address in lan
Ce.Se.N.A. Security
 
Inoltro di pacchetti ip in sistemi linux
Inoltro di pacchetti ip in sistemi linuxInoltro di pacchetti ip in sistemi linux
Inoltro di pacchetti ip in sistemi linux
Ce.Se.N.A. Security
 
Iena
IenaIena
Iena
Ce.Se.N.A. Security
 
Crimini informatici e accesso abusivo
Crimini informatici e accesso abusivoCrimini informatici e accesso abusivo
Crimini informatici e accesso abusivo
Ce.Se.N.A. Security
 
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route...
 Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route... Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route...
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per route...
Ce.Se.N.A. Security
 
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...
Rilevamento di attacchi di rete tramite protocolli di monitoraggio per router...
Ce.Se.N.A. Security
 
Msfpayload/Msfencoder cheatsheet
Msfpayload/Msfencoder cheatsheetMsfpayload/Msfencoder cheatsheet
Msfpayload/Msfencoder cheatsheet
Ce.Se.N.A. Security
 
Analisi sulla sicurezza di una autovettura moderna
Analisi sulla sicurezza di una autovettura modernaAnalisi sulla sicurezza di una autovettura moderna
Analisi sulla sicurezza di una autovettura moderna
Ce.Se.N.A. Security
 
Monitoraggio di mac address in lan
Monitoraggio di mac address in lanMonitoraggio di mac address in lan
Monitoraggio di mac address in lan
Ce.Se.N.A. Security
 
Inoltro di pacchetti ip in sistemi linux
Inoltro di pacchetti ip in sistemi linuxInoltro di pacchetti ip in sistemi linux
Inoltro di pacchetti ip in sistemi linux
Ce.Se.N.A. Security
 
Crimini informatici e accesso abusivo
Crimini informatici e accesso abusivoCrimini informatici e accesso abusivo
Crimini informatici e accesso abusivo
Ce.Se.N.A. Security
 
Ad

Recently uploaded (20)

Top 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing ServicesTop 10 IT Help Desk Outsourcing Services
Top 10 IT Help Desk Outsourcing Services
Infrassist Technologies Pvt. Ltd.
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 

Exploit techniques - a quick review

  • 1. =================================== EXPLOIT TECHNIQUES - A QUICK REVIEW =================================== Last Modify: 08/12/2011 Author: [email protected] Thanks to Corelan Team :) ************************************************************************ *** jmp2reg based exploit ********************************************* ************************************************************************ jump (or call) a register that points to the shellcode: With this technique, you basically use a register that contains the address where the shellcode resides and put that address in EIP. You try to find the opcode of a jump or call to that register in one of the dlls that is loaded when the application runs. When crafting your payload, instead of overwriting EIP with an address in memory, you need to overwrite EIP with the address of the jump to the register. Of course, this only works if one of the available registers contains an address that points to the shellcode. This is how we managed to get our exploit to work in part 1, so I'm not going to discuss this technique in this post anymore. [CLASSICAL] pop return : If none of the registers point directly to the shellcode, but you can see an address on the stack (first, second, address on the stack) that points to the shellcode, then you can load that value into EIP by first putting a pointer to pop ret, or pop pop ret, or pop pop pop ret (all depending on the location of where the address is found on the stack) into EIP. push return : this method is only slightly different than the call register technique. If you cannot find a <jump register> or <call register> opcode anywhere, you could simply put the address on the stack and then do a ret. So you basically try to find a push <register>, followed by a ret [ ROP GADGET ? ]. Find the opcode for this sequence, find an address that performs this sequence, and overwrite EIP with this address. [NICE :D] jmp [reg + offset] : If there is a register that points to the buffer containing the shellcode, but it does not point at the beginning of the shellcode, you can also try to find an instruction in one of the OS or application dlls, which will add the required bytes to the register and then jumps to the register. I'll refer to this method as jmp [reg]+[offset] blind return : in my previous post I have explained that ESP points to the current stack position (by definition). A RET instruction will pop the last value (4bytes) from the stack and will put that address in ESP. So if you overwrite EIP with the address that will perform a RET instruction,
  • 2. you will load the value stored at ESP into EIP. If you are faced with the fact that the available space in the buffer (after the EIP overwrite) is limited, but you have plenty of space before overwriting EIP, then you could use jump code in the smaller buffer to jump to the main shellcode in the first part of the buffer. ======================================================================== References: http://www.corelan.be/index.php/2009/07/23/writing-buffer-overflow-exploits- a-quick-and-basic-tutorial-part-2/ ************************************************************************ *** SEH based exploit ************************************************* ************************************************************************ TODO: no time to summarize it :( User exception handler in the stack: http://www.corelan.be:8800/wp-content/uploads/2009/07/image25.png Detail on the exception handler's list (chain): http://www.corelan.be:8800/wp-content/uploads/2009/07/image45.png SEH exploiting technique (keep in mind the ESP position for understanding it): http://www.corelan.be:8800/wp-content/uploads/2010/08/image13.png ======================================================================== References: http://www.corelan.be/index.php/2009/07/25/writing-buffer-overflow-exploits- a-quick-and-basic-tutorial-part-3-seh/ ************************************************************************ *** Bypass ALSR+DEP - ROP based exploit ******************************* ************************************************************************ Windows DEP options: OptIn : Only a limited set of Windows system modules/binaries are protected by DEP. OptOut : All programs, processes, services on the Windows system are protected, except for processes in the exception list AlwaysOn : All programs, processes, services, etc on the Windows system are protected. No exceptions AlwaysOff : DEP is turned off. + MS Permanent DEP : uses SetProcessDEPPolicy(PROCESS_DEP_ENABLE) to make sure processes are DEP enabled. Windows DEP defaults: Windows XP SP2, XP SP3, Vista SP0 : OptIn Windows Vista SP1 : OptIn + Permanent DEP Windows 7: OptIn + Permanent DEP Windows Server 2003 SP1 and up : OptOut Windows Server 2008 and up : OptOut + Permanent DEP Change DEP behavior: XP and 2003 server via boot.ini parameter /noexecute=[OptIn|OptOut|AlwaysOn|lwaysOff] Vista/Windows 2008/Windows 7 via bcdedit command bcdedit.exe /set nx [OptIn|OptOut|AlwaysOn|AlwaysOff] Windows API functions for bypassing DEP VirtualAlloc(MEM_COMMIT + PAGE_READWRITE_EXECUTE) + copy memory : new
  • 3. executable memory region, copy shellcode, execute HeapCreate(HEAP_CREATE_ENABLE_EXECUTE) + HeapAlloc() + copy memory SetProcessDEPPolicy() : Vista SP1, XP SP3, Server 2008, only if DEP Policy=OptIn|OptOut VirtualProtect(PAGE_READ_WRITE_EXECUTE) : change the access protection level of a given memory page WriteProcessMemory() : the target location must be writable and executable NOTE : Each one of those functions requires the stack or registers to be set up in a specific way. Parameters to the function are placed at the top of the stack (= at ESP). Primary goal: craft these values on the stack, in a generic and reliable way, without executing any code from the stack itself. After crafting the stack, you will most likely end up calling the API. ESP must point at the API function parameters. --------------------------------------------------------- | junk | | rop gadgets to craft the stack | |ESP-> function pointer (to one of the Windows APIs) | | junk (4 bytes) | | Function parameter | | Function parameter | | Function parameter | | Maybe some more rop gadgets | | nops | | shellcode | | more data on the stack | --------------------------------------------------------- At that time, a simple "RET" instruction will jump to that address. This will call the function and will make ESP shift with 4 bytes. If all goes well, the top of the stack (ESP) points at the function parameters, when the function is called. Example: VirtualAlloc + memcpy. Part of crafted stack.. ---------------------------------------------------------------------------- [..] | Pointer to VirtualAlloc | ESP points here for start the call. | 4 bytes junk | Necessary because when entering in VirtualAlloc, VirtualAlloc will PUSH EIP. He think it is a regular call. | pointer to memcpy | Return address field of VirtualAlloc()). When VirtualAlloc ends, it will return to this address | lpAddress | arbitrary address (where to allocate new memory. Example 0×00200000) | size | (how big should new memory allocation be) | flAllocationType | 0×1000 : MEM_COMMIT | flProtect | 0×40 : PAGE_EXECUTE_READWRITE | Arbitrary address | Return address for memcpy (same as
  • 4. lpAddress). used to jump to shellcode after memcpy() returns. | 4 bytes junk | Necessary because when entering in memcpy, memcpy will PUSH EIP. He think it is a regular call. | Arbitrary address | same address as lpAddress. Parameter here will be used as destination address for memcpy(). | Address of shellcode | source parameter for memcpy(). | Size | size parameter for memcpy(). [..] ---------------------------------------------------------------------------- NOTE ON PORTABILITY: It might be a good idea to verify if the application uses the function that you want to use to bypass DEP, and see if you can call that functions using an application/module pointer. That way, you can still make the exploit portable, without having to generate the function address, and without having to hardcode addresses from an OS dll. SUMMARY - HOW TO: What technique? (Windows API) used to bypass DEP and what are the consequences in terms of stack setup/parameters. What is the current DEP policy? What are the ROP GADGETS I can use ? (This will be your toolbox and will allow you to craft your stack.) How to start the chain? How to pivot to your controlled buffer ? (stack pivot) In a direct RET exploit, you most likely control ESP, so you can simply overwrite EIP with a pointer to RETN to kick start the chain How will you craft the stack ? As seen before, we will need to pass a number of parameters to this function. These parameters need to sit at the top of the stack at the time the function gets called. option 1) Put the required values in registers and then PUSHAD option 2) put some of the params (the static ones/the ones without null bytes) on the stack already, use ROP GADGETS to calculate the other params and write them onto the stack. [ROP GADGET = any instruction followed by a RET] ----------------------------------------------------------------------------- ----- | | junk | | eip eg. points to a RET instruction (or a stack pivot?) | | junk | | rop pointer to gadgets and at least jmp to syscall |ESP points here| parameters parameters that will be popped by syscall | | more rop | | padding / nops | | shellcode | | junk ----------------------------------------------------------------------------- ----- >>> ROP EXPLOIT EXAMPLE >>> [Watch picture @ http://www.corelan.be:8800/wp- content/uploads/2010/06/ropstructure1.png]
  • 5. >>> Stage 1 : SAVE ESP and JMP over the parameters 2 of our VirtualProtect() function parameters need to point at our shellcode. payload is in the stack, so taking the current stack pointer and storing it in a register is smart. Advantages: 1) Easily add/sub the value the reg to make it point at your shellcode. ADD, SUB, INC, DEC instructions are common. 2) Initial value points is pretty close to the stack address where the pointer to VirtualProtect() is located. 3) Close to the stack location of the parameter placeholders. "mov dword ptr ds:[register+offset],register" instruction to overwrite the parameter placeholder. # PUSH ESP # MOV EAX,EDX # POP EDI # RETN ---> MOV ESP, EDI (EDI is uncommon register, so this is a good place to store) # PUSH EDI # POP EAX # POP EBP # RETN ---> MOV EDI,EAX + POP Junk (old ESP = EDI = EAX) Now, jump over params with a gadget like # ADD ESP,20 # RETN >>> Stage 2 : crafting the first parameter of VirtualProtect() [return address] Shellcode is right after the nops... # ADD EAX,100 # POP EBP # RETN ---> ADD EAX,0x100 ; So eax = old ESP + 0x100 ...hope will hit the nop sled # MOV DWORD PTR DS:[ESI+10],EAX # MOV EAX,ESI # POP ESI # RETN ---> write this value onto the stack [..] >>> Stage 3 : crafting the second parameter (lpAddress = location that needs to be marked executable) This means that we can - more or less - repeat the entire sequence from stage 2, but before we can do this, we need to reset our start values. # PUSH EAX # POP ESI # RETN ---> EAX still holds the initial saved stack pointer. We have to put it back in ESI increase the value in EAX again (add 0x100) increase the value in ESI with 4 bytes [ # INC ESI # RETN (4 times)] >>> Stage 4 and 5 : third and fourth parameter (size and protection flag) The technique to write the resulting value as a parameter is exactly the same as with the other parameters Save EAX into ESI Change EAX (XOR EAX,EAX : 0x100307A9, and then ADD EAX,100 + RET, 3 times in a row : 0x1002DC4C) Increase ESI with 4 bytes Write EAX to ESI+0x10 The fourth parameter (0x40) uses the same principle again : Save EAX into ESI Set EAX to zero and then add 40 (XOR EAX,EAX + RET : 0x100307A9 /
  • 6. ADD EAX,40 + RET : 0x1002DC41) Increase ESI with 4 bytes Write EAX to ESI+0x10 >>> Final stage : jump to VirtualProtect All we need to do now is find a way to make ESP point to the location where the pointer to VirtualProtect() is stored. In this eample EAX already points at this address. #SUB EAX,4 # RET ---> just cause eax doesn't point directly @ virtualprotect pointer # PUSH EAX # POP ESP # MOV EAX,EDI # POP EDI # POP ESI # RETN ---> MOV EAX,ESP ; GOGOGO! ======================================================================== References: https://www.corelan.be/index.php/2010/06/16/exploit-writing-tutorial-part-10- chaining-dep-with-rop-the-rubikstm-cube/ ************************************************************************ *** Egg Hunting ******************************************************* ************************************************************************ Find shellcode into program memory and jump into it. TODO: no time to summarize it :( ======================================================================== References: http://www.corelan.be/index.php/2010/01/09/exploit-writing-tutorial-part-8- win32-egg-hunting/ https://www.corelan.be/index.php/2011/05/12/hack-notes-ropping-eggs-for- breakfast/