camabeh
8/21/2018 - 11:32 AM

Setuid example

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