3.2. 未限制的进程


无限制进程在无限制域中运行,例如,由 init 最终执行的无限制服务最终在 unconfined_service_t 域中运行,由内核执行的无限制服务最终在 kernel_t 域中运行,未限制的 Linux 用户最终在 unconfined_t 域中运行。对于不受限制的进程,会应用 SELinux 策略规则,但存在允许无限制域中运行的进程的策略规则几乎所有访问权限。在不受限制的域中运行的进程只能回退到使用 DAC 规则。如果不受限制的进程受到破坏,SELinux 不会阻止攻击者获得系统资源和数据的访问权限,当然,仍会使用 DAC 规则。SELinux 是 DAC 规则基础上的安全增强 - 它不会取代它们。
要确定启用了 SELinux 且系统已准备好执行以下示例,请完成 第 3.1 节 “受限制的进程” 所述的 过程 3.1, “如何验证 SELinux 状态”
以下示例演示了在运行 unconfined 时,Apache HTTP 服务器(httpd)如何访问 Samba 要使用的数据。请注意,在 Red Hat Enterprise Linux 中,httpd 进程默认在受限制的 httpd_t 域中运行。这是个示例,不应在生产环境中使用。它假定已安装了 httpdwgetdbusaudit 软件包,使用了 SELinux targeted 策略,并且 SELinux 处于强制模式。

过程 3.3. Unconfined 进程示例

  1. chcon 命令重新标记文件,当文件系统重新标记时,这些标签更改不会保留。对于文件系统重新标记生存的永久更改,请使用 semanage 实用程序,稍后会对此进行讨论。以 root 用户身份,输入以下命令将类型更改为 Samba 使用的类型:
    ~]# chcon -t samba_share_t /var/www/html/testfile
    查看更改:
    ~]$ ls -Z /var/www/html/testfile
    -rw-r--r--  root root unconfined_u:object_r:samba_share_t:s0 /var/www/html/testfile
  2. 输入以下命令确认 httpd 进程没有运行:
    ~]$ systemctl status httpd.service
    httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: inactive (dead)
    如果输出不同,请以 root 用户身份输入以下命令来停止 httpd 进程:
    ~]# systemctl stop httpd.service
  3. 要使 httpd 进程运行没有限制,请以 root 用户身份输入以下命令,将 /usr/sbin/httpd 文件的类型改为不转换为受限域的类型:
    ~]# chcon -t bin_t /usr/sbin/httpd
  4. 确认 /usr/sbin/httpd 已使用 bin_t 类型进行标记:
    ~]$ ls -Z /usr/sbin/httpd
    -rwxr-xr-x. root root system_u:object_r:bin_t:s0       /usr/sbin/httpd
    
  5. 以 root 用户身份,启动 httpd 进程并确认它已成功启动:
    ~]# systemctl start httpd.service
    ~]# systemctl status httpd.service
    httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: active (running) since Thu 2013-08-15 11:17:01 CEST; 5s ago
    
  6. 输入以下命令查看在 unconfined_service_t 域中运行的 httpd
    ~]$ ps -eZ | grep httpd
    system_u:system_r:unconfined_service_t:s0 11884 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11885 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11886 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11887 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11888 ? 00:00:00 httpd
    system_u:system_r:unconfined_service_t:s0 11889 ? 00:00:00 httpd
    
  7. 更改到 Linux 用户对其具有写入权限的目录,并输入以下命令。除非对默认配置进行了更改,否则这个命令会成功:
    ~]$ wget http://localhost/testfile
    --2009-05-07 01:41:10--  http://localhost/testfile
    Resolving localhost... 127.0.0.1
    Connecting to localhost|127.0.0.1|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 0 [text/plain]
    Saving to: `testfile'
    
    [ <=>                            ]--.-K/s   in 0s
    
    2009-05-07 01:41:10 (0.00 B/s) - `testfile' saved [0/0]
    虽然 httpd 进程无法访问标有 samba_share_t 类型的文件,但 httpd 在 unconfined unconfined_service_t 域中运行,并且回退到使用 DAC 规则,因此 wget 命令会成功。在受限制的 httpd _t 域中运行 httpd,wget 命令将失败。
  8. restorecon 实用程序恢复文件的默认 SELinux 上下文。以 root 用户身份,输入以下命令恢复 /usr/sbin/httpd 的默认 SELinux 上下文:
    ~]# restorecon -v /usr/sbin/httpd
    restorecon reset /usr/sbin/httpd context system_u:object_r:unconfined_exec_t:s0->system_u:object_r:httpd_exec_t:s0
    
    确认 /usr/sbin/httpd 已使用 httpd_exec_t 类型标记:
    ~]$ ls -Z /usr/sbin/httpd
    -rwxr-xr-x  root root system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd
  9. 以 root 用户身份,输入以下命令来重新启动 httpd。重启后,确认 httpd 在受限制的 httpd_t 域中运行:
    ~]# systemctl restart httpd.service
    ~]$ ps -eZ | grep httpd
    system_u:system_r:httpd_t:s0    8883 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8884 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8885 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8886 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8887 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8888 ?        00:00:00 httpd
    system_u:system_r:httpd_t:s0    8889 ?        00:00:00 httpd
    
  10. 以 root 用户身份,删除 testfile
    ~]# rm -i /var/www/html/testfile
    rm: remove regular empty file `/var/www/html/testfile'? y
    
  11. 如果您不需要 httpd 运行,请以 root 用户身份输入以下命令,请输入以下命令停止 httpd
    ~]# systemctl stop httpd.service
这些部分中的示例演示了如何保护数据不受被入侵限制进程的影响(由 SELinux 保护),以及攻击者如何更加轻松地访问数据免受损坏的非限制进程(不受 SELinux 保护)。
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.