cmacosbuffer-overflowfortify-source

performing simple buffer overflow on Mac os 10.6


I'm trying to learn about stack base overflow and write a simple code to exploit stack. But somehow it doesn't work at all but showing only Abort trap on my machine (mac os leopard)

I guess Mac os treats overflow differently, it won't allow me to overwrite memory through c code. for example,

strcpy(buffer, input) // lets say char buffer[6] but input is 7 bytes 

on Linux machine, this code successfully overwrite next stack, but prevented on mac os (Abort trap)

Anyone know how to perform a simple stack-base overflow on mac machine?


Solution

  • include

    int main(int argc, char **argv) {
        char buffer[4];
        puts("Hello");
        gets(buffer);
        return 0;)
    }
    

    and call it as:

    printf "0123456789abcdefghij\260\037" | ./a.out
    

    \260\037 is the address of main(0x1fb0 here) in octal and in little endian order.

    You should see hello print two times before a bus error. The trick is to use a debugger(even gdb will do) to know both where you want to end up and where is the return address. It won't be the same as in Linux!

    MacOS X for i386(most OSes for i386 in fact including Linux and Windows) and especially <=Leopard are not the most secure OS.

    EDIT: just realized I was using clang as the compiler. So you will need to adapt it to gcc but I can tell you it works with little change :p.