6

我想让系统在没有setuid文件“+p”功能的情况下可用,并且通常没有在我设置PR_SET_NO_NEW_PRIVS时被禁用的东西。

使用这种方法(init集合PR_SET_NO_NEW_PRIVS和基于文件系统的能力提升不再可能)你不能“重新填充”你的能力,只需要小心不要“飞溅”它们。

如何在execve不“破坏”任何授予功能的情况下进行其他进程(例如,如果新程序的文件是setcap =ei)?只是“我相信这个新过程,就像我相信自己一样”。例如,给用户一个能力(并且用户想在他启动的任何程序中锻炼它)......

我可以永久制作整个文件系统=ei吗?我想保持文件系统不干扰方案,不能授予或撤销功能;通过父->子控制一切。

4

3 回答 3

3

如果您参考功能手册页,目前没有简单的方法可以做到这一点:

During an execve(2), the kernel calculates the new capabilities of the process
using the following algorithm:

P'(permitted) = (P(inheritable) & F(inheritable)) | (F(permitted) & cap_bset)

P'(effective) = F(effective) ? P'(permitted) : 0 

P'(inheritable) = P(inheritable)    [i.e., unchanged]

where:

P        denotes the value of a thread capability set before the execve(2)
P'       denotes the value of a capability set after the execve(2)
F        denotes a file capability set
cap_bset is the value of the capability bounding set 

如果您要执行的文件没有设置它的 fP 位,或者如果它的 fI 位没有设置,您的进程将没有被允许,因此没有有效的能力。

设置整个文件系统允许和继承位在技术上是可行的,但这没有多大意义,因为它会大大降低系统的安全性,(编辑:正如你提到的,这不适用于新的可执行文件)。

您确实可以使用 pam_cap 为用户提供一些功能,但是您不能让他们执行他们刚刚使用它编译的任何文件。功能是通过设计为程序而不是用户赋予权力的,你可以在Hallyn 的论文中阅读:

一个关键的见解是观察到程序而不是人行使特权。也就是说,在计算机中所做的一切都是通过代理程序——程序——并且只有当这些程序知道如何处理特权时,它们才能被信任使用它。

另请参见定义 POSIX 功能的POSIX 草案1003.1e,第 310 页:

为一个流程链(单个流程中的一系列程序)建立一组在该链的整个生命周期中保持固定和活跃的能力也是不合适的。[...] 这是最小权限原则的应用,它同样适用于用户和进程。

最近(2012 年 12 月)有人要求介绍你想在这个Linux 内核邮件列表中作为一个特性做什么,并且给出了一些非常有趣的答案。有些人认为,在继承规则中删除文件功能exec会引入一些安全问题,并且功能不是为这样的功能设计的,即使没有解释它会引入哪个安全问题:/

目前唯一的方法是修改 Linux 内核中继承能力的方式(要修改 2 个文件,我在 3.7 内核上成功测试过),但不清楚是否如上所述那样安全。

在旧内核(2.6.33 之前)上,可以选择在没有文件功能的情况下进行编译(CONFIG_SECURITY_FILE_CAPABILITIES),但我怀疑使用这样的旧内核是否适合您。

于 2013-05-07T22:05:13.980 回答
3

我并不是说我推荐这个用于你正在做的事情,但它就是这样。

摘自手册,有一些改动。据它说:fork不改变能力。现在在 Linux 内核 4.3 中添加了一个环境设置,这似乎是你想要做的。

   Ambient (since Linux 4.3):
          This is a set of capabilities that are preserved across an execve(2) of a program that is not privileged.  The ambient capability set obeys the invariant that no capability can ever
          be ambient if it is not both permitted and inheritable.

          The ambient capability set can be directly modified using
          prctl(2).  Ambient capabilities are automatically lowered if
          either of the corresponding permitted or inheritable
          capabilities is lowered.

          Executing a program that changes UID or GID due to the set-
          user-ID or set-group-ID bits or executing a program that has
          any file capabilities set will clear the ambient set.  Ambient
          capabilities are added to the permitted set and assigned to
          the effective set when execve(2) is called.

   A child created via fork(2) inherits copies of its parent's
   capability sets.  See below for a discussion of the treatment of
   capabilities during execve(2).

Transformation of capabilities during execve()
   During an execve(2), the kernel calculates the new capabilities of
   the process using the following algorithm:

       P'(ambient) = (file is privileged) ? 0 : P(ambient)

       P'(permitted) = (P(inheritable) & F(inheritable)) |
                       (F(permitted) & cap_bset) | P'(ambient)

       P'(effective) = F(effective) ? P'(permitted) : P'(ambient)

       P'(inheritable) = P(inheritable)    [i.e., unchanged]

   where:

       P         denotes the value of a thread capability set before the
                 execve(2)

       P'        denotes the value of a thread capability set after the
                 execve(2)

       F         denotes a file capability set

       cap_bset  is the value of the capability bounding set (described
                 below).

   A privileged file is one that has capabilities or has the set-user-ID
   or set-group-ID bit set.
于 2016-06-04T08:29:38.650 回答
0

我认为(我的理解),使用功能的最佳方式是:

  • 对于需要能力和受信任的程序,包括受信任的不泄漏能力:例如,wire-shark 的数据包嗅探部分,需要侦听端口 80 的 Web 服务器。
    • 新程序,功能感知:设置允许。
    • 遗留程序,不知道功能:设置允许和有效
  • 对于会泄漏功能的程序,并且具有可以(有时)使用功能的代码:设置继承
    • 例如,对于chmod设置继承 CAP_FOWNER,如果用户需要超级权限(通常由 root 持有),那么他们需要使用setpriv(或等效的,这可以滚动到sudo),否则它在非特权模式下工作。
  • 当一个进程需要分叉和共享一些功能时,然后并且只有在那时才使用环境。可能相同的可执行文件;如果它是不同的,那么这个新的将允许或继承文件上的集合。[编辑:我刚刚意识到,如果您不执行,则不需要环境。如果我想到一个环境的用例,在一个设置良好的系统中,那么我会在这里添加它。Ambient 可以用作一种过渡机制,当没有在可以使用它的文件上设置继承时。]

环境的用途:

  • 在文件没有正确功能的系统上。(一种过渡技术)。
  • 对于 shell 脚本,它不能具有功能(因为它们不能具有 setuid),除非在已修复然后允许脚本上的 setuid 的系统上。
  • 在这里添加更多。
于 2016-09-01T19:37:56.660 回答