• Aucun résultat trouvé

Return-Oriented Programming

N/A
N/A
Protected

Academic year: 2022

Partager "Return-Oriented Programming"

Copied!
20
0
0

Texte intégral

(1)

Return-Oriented Programming

Scott Hand

CS 6v81.005 Spring 2012

(2)
(3)

Traditional Stack Overflow

Payload

NOP Sled Saved EIP

(4)

Traditional Stack Overflow

• The simplest stack overflow exploit is the one that operates as follows:

1. Send a payload with a NOP sled, shellcode, and a pointer to the NOP sled

2. The pointer to the NOP sled overwrites the

saved return address and thereby takes over the stored EIP

3. EIP now points to the machine code and the program executes arbitrary code

(5)

Evaluation

• Pros

▫ Very easy to trigger

▫ Simple to understand

▫ Being able to inject code means our payloads are powerful and flexible

• Cons

▫ Just make the stack non-executable

▫ Lots of problems with bad characters, buffer sizes, payload detection, etc.

(6)

Return-to-libc

Padding system() exit() “/bin/sh”

(7)

Return-to-libc

• Used primarily to streamline exploitation to bypass mitigation and situational limitations

• We want to spawn a shell. Send a payload that overwrites the saved EIP with the address of system(), the address of exit(), and a pointer to

“/bin/sh”.

• The system call will return directly to exit()

which will then shut down the program cleanly.

(8)

Evaluation

• Pros

▫ Does not need executable stack

▫ Also pretty easy to understand and implement

• Cons

▫ Relies on access to library functions

▫ Can only execute sequential instructions, no branching or fancy stuff

▫ Can only use code in .text and loaded libraries

(9)
(10)

Basic Idea

• We want to take advantage of the code that already exists in the program

• We will use ESP as a combination of program code and memory

• Each return will be stepping along our ESP

program

(11)

Gadgets

• ROP operates by executing a string of “gadgets”

• Each gadget will

▫ Take values from stack to registers via POP commands

▫ Once we have done what we needed to do, return to the next gadget

• Given enough code in a program, gadgets are

Turing-complete

(12)

Sample Gadgets

• pop eax; ret

▫ Loads esp into eax

• pop eax; pop ebx; ret

▫ Loads two words from stack and returns. Is a way of incrementing the stack pointer or stepping over instructions

• mov esp, ebx; ret

▫ Moves (or “pivots”) the stack into the pointer stored in ebx

(13)

Capabilities of Gadgets

• Loading a constant

• Loading from memory

• Storing to memory

• Adding

• Xor

• And, Or, Not

• Shifts, Rotates

• Unconditional and conditional jumps

(14)
(15)

Finding Gadgets Automatically

• Obviously looking through a binary for gadgets manually will take a long time

• Tools to help:

▫ ropeme

▫ ROPgadget

▫ Msfrop

• Each one will give a list of addresses of useful

gadgets and allow for searching

(16)

Automating it All

• ROPgadget has an automated payload generator that transforms any given shellcode into a

gadget sequence

• Ropeme has a Python library as well as

command line interface that automates many

tasks of crafting a ROP payload

(17)

Ropeme – Stage 0

• Stage-0

▫ Creates a fixed stack at a given writable section

▫ This bypasses ASLR and gives better control

• Transfer stage-1 payload to custom stack

▫ Pick a byte in payload

▫ Search for bytes in binary

▫ Generate a strcpy() call

▫ Repeat for all bytes in payload

• Transfer control to custom stack with pop ebp;

ret followed by move esp, ebp; ret gadgets

(18)

Ropeme – Stage 1

• Executing chained ret-to-libc calls

▫ Addresses are randomized, but offsets remain constant

▫ Can resolve run-time randomized libc addresses by using ROP gadgets to calculate the distance from a known address in GOT

• Overwrite GOT entries

▫ Load an offset into register

▫ Add register to GOT entry

▫ Return to PLT entry

(19)

Demo

• Ropeme demonstration

(20)

Conclusion

• Any questions?

Références

Documents relatifs

The new class F address would be placed in the same locations that are used for source and destination IP address in the IP header, but would specify that part of the

A leaf routing domain that is willing to accept prefixes derived from its direct provider gets a prefix from the provider’s address space subdivision associated

Host A will assume, based on the subnet mask, that the remote host is actually attached to the LAN and will issue an ARP Request to determine its hardware address.. Naturally,

This memo documents MAPOS 16, a multiple access protocol for transmission of network-protocol datagrams, encapsulated in HDLC frames with 16 bit addressing, over SONET/SDH..

If this were true, a telephone numbering plan based on 10 digits would be able to number 10 billion telephones, and the IPv4 32 bit addresses would be adequate for numbering

Once the identity of the VPIM directory server is known, the email address, capabilities, and spoken name confirmation information can be retrieved.. This query is expected to

o An attacking network entity purporting to offer the mobile node a legitimate home agent address or bootstrapping for the IPsec SAs may instead offer a bogus home

IANA may undertake IPv6 address designations in support of special purposes as requested in "IANA Considerations" sections in IESG- reviewed RFCs, where an address