【问题标题】:run bash script with suid set on file在文件中设置 suid 运行 bash 脚本
【发布时间】:2012-07-10 16:54:27
【问题描述】:

我写了一个小bash脚本来测试suid权限

$ cat phone.sh
#!/bin/sh
echo "abc" >> out.txt

$ ls -l out.txt phone.sh
-rw-r--r-- root wzj      ...         out.txt
-rwsr-xr-x root wzj      ...         phone.sh

$ ./phone.sh
./phone.sh: 2: cannot create out.txt: Permission denied

为什么?我以为我已经设置了suid权限,所以我可以以root权限运行phone.sh来修改out.txt文件,但我失败了。谁能告诉我哪里做错了?

【问题讨论】:

  • 请参阅 stackoverflow.com/q/397612/929437 了解为什么 suiding 脚本是一个坏主意以及如何绕过它
  • aland:非常感谢,我想我只是做错了事情,我对 bash 脚本真的很陌生

标签: bash suid


【解决方案1】:

大多数 *nix 操作系统不允许脚本使用 SUID。在这个主题上查看Vidar's blog entry。 Perl 脚本可以使用 SUID,但正如 Vidar 解释的那样,这是由于 Perl 是如何实现的。看来 Bash 脚本根本无法使用 SUID 运行。抱歉,我没有对您更有用的答案,看起来这只是“情况如何”。

【讨论】:

  • Fls'Zen:谢谢你的文章,我明天去读,现在是日本凌晨 2:30 ^^
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-01
  • 1970-01-01
  • 2012-06-18
  • 2015-07-05
  • 2017-03-08
  • 1970-01-01
相关资源
最近更新 更多