Somewhere to pivot to obviously (.bss, buffer on the stack)
Stack Pivoting Gadget - something that controls RSP
leave ret
pop 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;
}
fgets call means that there is a limited number of bytes we can overflow -> not enough for a rop chain
we 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 win function, we need to pass the values into rdi and rsi
Using stack pivot, we format our payload with a pop rsp..;ret gadget which will change the rip to the location we control (our buffer in this case), executing the rop chain stored in the buffer.