Problems with setuid

0

I am developing a program that changes the uid of my process to 0 allowing me to start other programs as root.

mysu.c
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **args)
{
    int myuid = getuid();
    if (setuid(0))
    {
        printf("su: permission deniedd\n");
        return 1;
    }

    system("ls /data/data");
    setuid(myuid);

    return 0;
}

Soon after compile:

gcc mysu.c -o mysu

Change owner to root:

su
chown root:root mysu
chmod 6755 mysu
exit

However when executing it, the function setuid returns a value other than 0 indicating that it was not possible to change the uid, but when running as root the code works without problems. I saw some similar questions but I could not solve this problem.

    
asked by anonymous 12.08.2018 / 17:12

0 answers