Created
February 17, 2019 12:45
-
-
Save int0x33/78b3739cdf2b017d8b60c4c758556864 to your computer and use it in GitHub Desktop.
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
#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