Problems with setuid

Asked

Viewed 21 times

0

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

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 compiling:

gcc mysu.c -o mysu

Sets Owner to root:

su
chown root:root mysu
chmod 6755 mysu
exit

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

  • This has Android as a target?

  • Yes, this program is for android and linux

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.