在文件上设置 SUID 标志?

发布于 2024-10-11 05:38:51 字数 97 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁对谁错谁最难过 2024-10-18 05:38:51

您需要一个本机映像才能让 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文