I write a simple program
我写了一个简单的程序
When you run this program, if you are not root
user, input root
password, then change uid to root
运行此程序时,如果您不是root用户,请输入root密码,然后将uid更改为root
if (getuid())
{
char *pass = getpass("");
//how to change uid to root ?
}
How to change uid to root when you got root
password?
获得root密码后如何将uid更改为root?
1 个解决方案
#1
5
There is no way to change from a non-root user to root. That's the whole point. Programs like login
, sshd
, or su
work by initially starting as root, either because of their ancestry or by having the suid bit on the executable file, and carefully restricting what you can do until you authenticate with a password or other method, then changing to an appropriate uid (either root or the user you're logging in as) and exec
'ing another program (usually, the shell).
无法从非root用户更改为root用户。这就是重点。像login,sshd或su这样的程序最初以root身份启动,要么是因为它们的祖先,要么是因为在可执行文件上有suid位,并且在使用密码或其他方法进行身份验证之前要小心限制你可以执行的操作,然后更改到适当的uid(root或你登录的用户)和exec'ing另一个程序(通常是shell)。
#1
5
There is no way to change from a non-root user to root. That's the whole point. Programs like login
, sshd
, or su
work by initially starting as root, either because of their ancestry or by having the suid bit on the executable file, and carefully restricting what you can do until you authenticate with a password or other method, then changing to an appropriate uid (either root or the user you're logging in as) and exec
'ing another program (usually, the shell).
无法从非root用户更改为root用户。这就是重点。像login,sshd或su这样的程序最初以root身份启动,要么是因为它们的祖先,要么是因为在可执行文件上有suid位,并且在使用密码或其他方法进行身份验证之前要小心限制你可以执行的操作,然后更改到适当的uid(root或你登录的用户)和exec'ing另一个程序(通常是shell)。