【问题标题】:setuid vs seteuid functionsetuid vs seteuid 函数
【发布时间】:2015-10-12 08:31:03
【问题描述】:

setuid 和 seteuid 函数有什么区别。在手册页中,这两个函数都有类似的描述。

setuid:

DESCRIPTION

   setuid()  sets  the  effective user ID of the calling process.  If the effective UID of the caller is root, the real UID and saved
   set-user-ID are also set.

seteuid:

DESCRIPTION

   seteuid()  sets  the  effective user ID of the calling process.  Unprivileged user processes may only set the effective user ID to
   the real user ID, the effective user ID or the saved set-user-ID.

在这两个描述中都包含sets the effective user ID of the calling process。那么两者有什么区别 这两个以及这些函数之间的功能有何不同。

还有一个疑问是,我们只使用 chmod(chmod u+s) 可以设置文件的set user id权限。那么只有在程序运行时,进程才有权限设置谁设置 用户身份。除了这些之外,这些函数如何为进程设置有效的用户 ID。

【问题讨论】:

标签: c linux unix setuid


【解决方案1】:

来自man page

   Thus, a set-user-ID-root program wishing to temporarily drop root
   privileges, assume the identity of an unprivileged user, and then
   regain root privileges afterward cannot use setuid().  You can
   accomplish this with seteuid(2).

【讨论】:

  • 需要什么。为什么root需要非特权用户身份。你有什么例子吗?
  • 嗯,一个可能的例子是当一个进程需要一些特权资源(例如 HTTP 服务器的 80 端口),但在进程收集了该资源之后,绝对不需要再以 root 运行(因此您可以检查,Apache 网络服务器以非特权用户身份运行,例如 _http_apache)。通常这种措施被用作安全预防措施:可能破坏未授权的服务器通常会产生较小的有害后果。
  • 我对上面的手册页参考有疑问。使用 setuid 我们可以设置进程的有效用户 id。例如:setuid(getuid());这条语句执行后,进程的有效用户标识变为当前用户。因此,要重新获得 root 权限,我只需使用 setuid(0);但是为什么手册页参考显示afterward cannot use setuid(). You can accomplish this with seteuid(2)
【解决方案2】:

在回答“为什么使用 seteuid()”的问题时:一些系统应用程序使用 seteuid(),以便他们可以尝试以“有效”用户的权限执行指令。这允许以 root 身份运行的程序确保,例如,它创建的任何文件都是使用有效用户 id 而不是 root id 创建的。

也许最引人注目的应用程序是 Unix“cron”系统,它必须以用户“root”身份运行,但有责任以任意用户身份执行任意命令。

【讨论】:

  • 那么安全预防理论是错误的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-08
  • 1970-01-01
  • 1970-01-01
  • 2020-12-05
  • 2017-05-05
  • 2013-07-05
相关资源
最近更新 更多