这个脚本安全吗?
我需要执行一些服务器任务。现在我多次听到这是非常不安全的。这是我的解决方案:
将此行添加到 sudoers: www-data ALL=NOPASSWD: /var/private-www/bin/webadmin
(无法通过网络访问)
创建了此脚本var/private-www/bin/webadmin
:
# Script for executing server tasks.
#
# Arguments:
# - Password Required for authentication, not all scripts may run this file
# - Action Action to execute
# Exit codes:
# 0 Failed
# 1 Success
# First of all check the password
if [ $1 = "secretpassword" ]
then
whoami
exit 1
else
echo "No access"
exit 0
fi
该文件具有以下权限: 0111
仅对一个帐户启用 SSH 访问。所以除了我(和 www-data)之外,没有人可以执行该脚本。 www-data 现在可以通过执行以下操作来访问此文件: exec('/usr/bin/sudo /var/private-www/bin/webadmin Secretpassword', $output, $status);
这足够安全吗?我怎样才能让它更安全?
I need to execute some server tasks. Now I heard many many times this is very insecure. This is my solution:
Added this line to sudoers:www-data ALL=NOPASSWD: /var/private-www/bin/webadmin
(Not accessible through web)
Created this script var/private-www/bin/webadmin
:
# Script for executing server tasks.
#
# Arguments:
# - Password Required for authentication, not all scripts may run this file
# - Action Action to execute
# Exit codes:
# 0 Failed
# 1 Success
# First of all check the password
if [ $1 = "secretpassword" ]
then
whoami
exit 1
else
echo "No access"
exit 0
fi
The file has these rights:0111
SSH access is only enabled for one account. So nobody can execute the script, except me (and www-data). www-data can now access this file by doing:exec('/usr/bin/sudo /var/private-www/bin/webadmin secretpassword', $output, $status);
Is this safe enough? How can I make it more secure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为如果你的 Apache 服务器被破解,有人可以访问该脚本并执行它,但我可能是错的。
我遇到了您可能想阅读的资源,特别是当涉及到将脚本限制到内部网络时。
http://www.linuxsecurity.com/content/view/133913/171/
我希望这能回答您的问题。
I'm thinking that if your Apache server gets cracked, someone could access that script and execute it, but I might be wrong.
I've came across a resource you might want to read about, especially when it comes to restricting your script to your internal network.
http://www.linuxsecurity.com/content/view/133913/171/
I hope this answers your question.