We often need to let ordinary users do the work that requires root permissions, such as ordinary users with the date command to modify the system dates. The date command requires root permission to execute, and 2 ways to solve the problem:
Method One:
Executed by root user chmod 4755/bin/date
Note: the addition of the S-permission bit to the date command sets setuid (4000) so that ordinary users can execute the date command, and the disadvantage is obvious, which is equivalent to removing the root permission limit of the date command.
Method Two:
Shell Script Packers:
#include "stdio.h"
#include "Pwd.h"
Main (int Argc,char *argv[])
{
struct passwd *srcc_pwd;
Char *proc_name = "sh./myfile.sh");
gid_t Srcc_gid;
uid_t Srcc_uid;
int Gg,uu;
Srcc_pwd=getpwnam ("root");
srcc_gid=srcc_pwd->pw_gid;
srcc_uid=srcc_pwd->pw_uid;
Gg=setgid (Srcc_gid);
Uu=setuid (SRCC_UID);
Gg=system (Proc_name);
Return
}
The root user compiles the file to generate the executable file a.out, and chmod 4111./a.out
This allows the normal user to complete the task by executing the./a.out (the task to be completed is written in the./myfile.sh script)
Methods for ordinary users to execute commands that require root privileges