WCU / Cybersecurity
~/CSC 472/Class 03/KP 08
Class 03 · KP 08 / 17

ret2win: Redirect to an Existing Function

higher addressessaved return addresshijack targetsaved RBPchar buffer[ ]local variablelower addresses (RSP)overflowwrites up
A stack frame: overflowing the buffer overwrites the saved return address.
// vuln.c  --  compiled with mitigations off for teaching
#include <stdio.h>
#include <string.h>

void win(void) {                 // the "hidden" target
    puts("You reached win(): flag unlocked.");
}

void vuln(void) {
    char buf[64];
    gets(buf);                   // UNBOUNDED read -> overflow
}

int main(void) {
    vuln();
    return 0;
}
  • win() already exists in the binary; we just need ret to land on it.
  • Payload shape: padding to reach the saved RET, then the address of win.