Skip to content

Instantly share code, notes, and snippets.

@syntactician
Last active February 7, 2017 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save syntactician/75b11c76c7aa46be4dd8fa65a01c496b to your computer and use it in GitHub Desktop.
Save syntactician/75b11c76c7aa46be4dd8fa65a01c496b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#define LS "/bin/ls"
#define FILEPATH "./lusers"
#define MESSAGE "\
WARNING! You have put my binary directory ahead of the system's in your $PATH. \
While flattering, this is considered unsafe. This will execute my \
binaries rather than the system's in the case of name collisions. Please, \
append it to the end of your $PATH, instead. This incident will be reported."
int
main(const int argc, char *const *argv)
{
FILE *fp;
(void) argc;
printf("%s\n\n", MESSAGE);
if ((fp = fopen(FILEPATH, "a")))
fprintf(fp, "%s\n", getlogin());
fclose(fp);
execv(LS, argv);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment