Skip to content

Instantly share code, notes, and snippets.

@torsten
Created March 25, 2009 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torsten/85539 to your computer and use it in GitHub Desktop.
Save torsten/85539 to your computer and use it in GitHub Desktop.
Testing address space layout randomization on Leopard
/*
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