Created
March 25, 2009 15:55
-
-
Save torsten/85539 to your computer and use it in GitHub Desktop.
Testing address space layout randomization on Leopard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A small program to test address space layout randomization (ASLR) on Leopard, | |
by Torsten Becker <torsten.becker@gmail.com>, 2009. | |
The presentation from a Apple guy at | |
http://www.slideshare.net/guest4c923d/jordan-hubbard-talk-lisa-presentation | |
suggests to compile with -pie but it doesn't work for me, I get the same | |
output every time which means it's not random, check it yourself: | |
$ gcc -fPIC -Wl,-pie aslr-test.c && ./a.out | |
*/ | |
#include <stdio.h> | |
#include <stdarg.h> | |
int main (int argc, char const *argv[]) | |
{ | |
int var = 23; | |
printf("stack: 0x%x\n" | |
"printf: 0x%x\n" | |
"ret: 0x%x " | |
"(should not be 0xc3 which is \"ret\" and enables return from libc)\n", | |
&var, &printf, | |
*((unsigned char*)0x942b2fc2) /* a ret in printf */); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment