As per my understanding,
- RUID: uid of the caller of the process is called real uid.
- EUID: effective uid means allowed privilege for that process.
// setuid_file.c
#include<stdio.h>
int main(void)
{
int uid;
uid=getuid();
printf("RUID : getuid() : %d\n",uid);
uid=geteuid();
printf("EUID : geteuid() : %d\n",uid);
system("whoami");
system("cat /etc/sudoers"); //only root user can access. here we can write any command which only root user can execute.
}
gcc setuid_file.c -o euid_zero
chmod ug+s euid_zero
So, on root terminal, I have set suid and guid for the euid_zero executable. Now, ff I try to run the executable using normal user, then below is the output.
ll euid_zero
-rwsr-sr-x 1 root root 16768 Dec 30 00:59 euid_zero
whoami
kali
id
uid=1000(kali) gid=1000(kali) groups=1000(kali)
./euid_zero
RUID : getuid() : 1000
EUID : geteuid() : 0
kali
cat: /etc/sudoers: Permission denied
So, here EUID is zero then also we can not gain root privilege. So, that means we have access privilege according to RUID, then what is the meaning of EUID if there is no use of EUID?