在文件上设置 SUID 标志?
我有一个 python 文件,我想在其上设置 SUID 标志。这样,如果任何普通用户执行它,它就会以 root 身份执行。我知道这是一个安全问题,但我仍然需要设置 SUID 标志。
I have a python file that I would like to set the SUID flag on. So that if any normal user executes it it executes as root. I know it's a security issue but I still need to set the SUID flag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个本机映像才能让 suid 位在现代 Unix 上工作。如果你确实有这个需求,我会编写一个带有嵌入式 Python 代码的 C/C++ 程序来清理环境,然后执行脚本。
一个好方法是使用 boost::python 将 Python 嵌入到 C++ 程序中,以便您可以构建安全的静态链接图像。
根据您真正想要执行的操作,另一种选择是将脚本转换为守护进程,从已知上下文启动(例如使用 daemontools),然后让用户在需要完成某些操作时与其进行通信,例如使用具有适当访问控制的命名管道。
第二个选项是否合适取决于您的真正需要。
You need a native image for the suid bit to work on modern Unixes. If you really have that requirement, I would write a C/C++ program with the embedded Python code that cleans the environment and then executes the script.
A good way to do that is to use boost::python to embed Python into a C++ program so that you can build a safe, statically linked image.
Depending on what you are really trying to do, another option would be to turn your script into a daemon process, started from a known context (eg. using daemontools), and then have users communicate with it when they need something done, for example using a named pipe with appropriate access control.
Whether the second option is appropriate depends on what you really need.