我已经创建了一个包含以下内容的小shell脚本:
cat /usr/bin/checksuid.sh
!/bin/bash
echo "Hello" > /etc/myfile.cnf
ls -l /usr/bin/checksuid.sh
-rwsr-xr-x 1 root root 56 Sep 9 12:56 /usr/bin/checksuid.sh我还创建了一个根账号为/etc/myfile.cnf的文件,并设置了如下权限:
-rw-r--r-- 1 root root 6 Sep 9 12:26 /etc/myfile.cnf当我从一个非超级用户帐号执行/usr/bin/checksuid.sh时,我得到以下错误:
/usr/bin/checksuid.sh: line 3: /etc/myfile.cnf: Permission denied有人能帮你解释为什么SUID不起作用吗?
发布于 2013-09-09 21:10:38
Shell脚本不能为SUID。请参阅http://www.faqs.org/faqs/unix-faq/faq/part4/section-7.html
发布于 2014-07-24 03:46:48
来自http://www.tuxation.com/setuid-on-shell-scripts.html
“事实上,setuid位在很多*nix实现中都是禁用的,因为它带来了大量的安全漏洞。”
另一种方法是将脚本包装在可以使用setuid的内容中,例如下面的示例c程序。简单地调用你的脚本和使用这样的包装器(例如忽略的退出代码)显然是有区别的,但无论如何这应该会给你一个想法。
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
setuid( 0 );
system( "/path/to/script.sh" );
return 0;
}https://stackoverflow.com/questions/18698976
复制相似问题