Stack Pivoting
Pivoting for more space, or freedom of payload
TLDR
Requirements
Somewhere to pivot to obviously (.bss, buffer on the stack)
Stack Pivoting Gadget - something that controls RSP
leave retpop rsp
What can you do with this?
Gain more space for your ROP chain/Shellcode ๐
// gcc source.c -o vuln -no-pie
#include <stdio.h>
void winner(int a, int b) {
if(a == 0xdeadbeef && b == 0xdeadc0de) {
puts("Great job!");
return;
}
puts("Whelp, almost...?");
}
void vuln() {
char buffer[0x60];
printf("Try pivoting to: %p\n", buffer);
fgets(buffer, 0x80, stdin);
}
int main() {
vuln();
return 0;
}fgetscall means that there is a limited number of bytes we can overflow -> not enough for a rop chainwe also have a leak to start of buffer, but not enough to craft a full ROP chain
to pass in the right values to the
winfunction, we need to pass the values intordiandrsi
Using stack pivot, we format our payload with a
pop rsp..;retgadget which will change theripto the location we control (our buffer in this case), executing the rop chain stored in the buffer.
Example 2
The binary reads in 4096 bytes into
.bssat0x4040e0, with the first 24 bytes (0x18) copied onto the stack viamemcpyThis gives us 3 gadgets worth of space to pivot to the address
0x4040e0We can use a
leave retgadget to pivot to this address
leave retgadget is essentially just this
If we have a
pop rbpgadget, we can essentially control where the binary returns to (address of.bss)This gives us ample space for our libc leak via
putsas well as our ret2libc payload
Last updated