You Know 0xDiablos

Initial Analysis

This challenge provides us with a single executable: vuln

Upon running the binary, we are greeted with a message, it then prompts us for an input, echos it back and exits:

└─$ ./vuln
You know who are 0xDiablos: 
no
no

Checksec shows us the following:

    Arch:     i386-32-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      No PIE (0x8048000)
    RWX:      Has RWX segments

Hmm, RWX segments, interesting....

Code analysis

Decompilation for main:

undefined4 main(void)
{
  __gid_t __rgid;
  
  setvbuf(stdout,(char *)0x0,2,0);
  __rgid = getegid();
  setresgid(__rgid,__rgid,__rgid);
  puts("You know who are 0xDiablos: ");
  vuln();
  return 0;
}

An interestingly named function vuln:

And finally a function called flag:

Since we have an unbound buffer overflow in vuln:5, and a flag function, this looks like a typical ret2win type of challenge, with a little twist. There is a check on flag:9 for the values of 2 parameters that are passed to the flag function. Since this is a 32-bit binary, function parameters are passed onto the stack, so all we will have to do, is include the values on the stack in the correct position, in our overflow. Those values in unsigned form happen to be: 0xdeadbeef and 0xc0ded00d.

After a call to a function, this is what the stack layout looks like in 32-bit:

So at the time of the flag call, we will need to have the parameters starting 4 bytes from ESP.

Exploitation

The following exploit script should do the trick:

And sure enough it does:

Last updated