Skip to content

Instantly share code, notes, and snippets.

@jacob-faber
Created August 21, 2018 11:32
Show Gist options
  • Save jacob-faber/8d2deebb9f779f28cf32eb2edaf56d66 to your computer and use it in GitHub Desktop.
Save jacob-faber/8d2deebb9f779f28cf32eb2edaf56d66 to your computer and use it in GitHub Desktop.
Setuid example
# SUID is ignored for interpreted languages (shell scripts, etc...)
tee setuid-example.c <<EOF
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv) {
printf("%d", geteuid());
return 0;
}
EOF
echo "---------------------------------"
gcc -o setuid-example setuid-example.c
echo "Setuid with default user: $(./setuid-example)"
sudo chown root:root ./setuid-example && sudo chmod u+s ./setuid-example
echo "Setuid with root user: $(./setuid-example)"
sudo rm ./setuid-example ./setuid-example.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment