Skip to content

Instantly share code, notes, and snippets.

@int0x33
Created February 17, 2019 12:45
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 int0x33/78b3739cdf2b017d8b60c4c758556864 to your computer and use it in GitHub Desktop.
Save int0x33/78b3739cdf2b017d8b60c4c758556864 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MY_TMP_FILE "/tmp/file.tmp"
int main(int argc, char* argv[])
{
FILE * f;
if (!access(MY_TMP_FILE, F_OK)) {
printf external link("File exists!\n");
return EXIT_FAILURE;
}
/* At this point the attacker creates a symlink from /tmp/file.tmp to /etc/passwd */
tmpFile = fopen(MY_TMP_FILE, "w");
if (tmpFile == NULL) {
return EXIT_FAILURE;
}
fputs("Some text...\n", tmpFile);
fclose(tmpFile);
/* You successfully overwrote /etc/passwd (if you ran this as root/or SUID etc) */
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment