RHEL 8 - 用OpenSCAP工具对RHEL进行漏洞安全合规扫描,并修复

12 篇文章 1 订阅
本文介绍了如何在RHEL8系统上使用OpenSCAP进行安全配置合规性和漏洞扫描。讲解了SCAP、OVAL的概念,以及OpenSCAP项目及其相关工具。通过示例展示了如何扫描RHEL8系统,遵循HIPAA安全基准,并提供了手动修复和批量修复的步骤。此外,还提到了基于不同安全策略的扫描和报告生成。
摘要由CSDN通过智能技术生成

OpenShift 4.x HOL教程汇总
已在 RHEL 8.4 上验证
本文的前置条件:RHEL8 - 配置基于安装 ISO 文件的 YUM Repo

概念

什么是SCAP

Red Hat Enterprise Linux的安全审计功能是基于安全内容自动化协议(SCAP)标准。SCAP是一个多用途的规范框架,支持自动配置、漏洞和补丁检查、技术控制合规活动和安全测量。SCAP规范创建了一个生态系统,其中安全内容的格式是众所周知和标准化的。

什么是OVAL

Open Vulnerability Assessment Language (OVAL)是SCAP的基本和最古老的组成部分。与其他工具和自定义脚本不同,OVAL以声明的方式描述了资源的必要状态。OVAL代码不直接执行,而是使用一个称为scanner的OVAL解释器工具。OVAL的声明性确保了被评估系统的状态不会被意外地修改。

Red Hat创建并支持OVAL补丁定义,为我们的安全公告提供了一个机器可读的版本。这使得与OVAL兼容的工具能够测试是否存在Red Hat已经发布的安全更新的漏洞。红帽在“https://www.redhat.com/security/data/oval/v2/”更新OVAL,OVAL 定义旨在检查系统中安装的 RPM 软件包的有漏洞版本,每个 OVAL 补丁定义可将一对一映射到红帽安全公告(RHSA)。

OpenSCAP项目

OpenSCAP是Red Hat维护的开源项目,OpenSCAP工具程序与 SCAP 安全指南软件包中提供的 SCAP 1.2 和 SCAP 1.3 内容兼容。OpenSCAP项目包括:

  • OpenSCAP:包括OpenSCAP库,以及配套的oscap命令行工具,旨在对本地系统进行配置和漏洞扫描,验证配置的合规性内容,并根据这些扫描和评估结果生成报告和指南。
  • SCAP安全指南(SSG) - scap-security-guide软件包为Linux系统提供最新的安全策略集合。该指南由加固建议目录组成,可适用于治理要求。
  • SCAP Workbench - scap-workbench图形化工具被设计用来对一个本地或远程系统进行配置和漏洞扫描。可以用它来生成基于这些扫描和评估的安全报告。

用OpenSCAP扫描RHEL

SCAP Security Guide文件

  1. 列出所有带有 SCAP Security Guide 项目提供的安全合规配置集的文件
$ ll /usr/share/xml/scap/ssg/content
total 186748
-rw-r--r--. 1 root root      591 Feb 17 23:42 ssg-firefox-cpe-dictionary.xml
-rw-r--r--. 1 root root     3885 Feb 17 23:42 ssg-firefox-cpe-oval.xml
-rw-r--r--. 1 root root   281907 Feb 17 23:42 ssg-firefox-ds-1.2.xml
-rw-r--r--. 1 root root   281907 Feb 17 23:42 ssg-firefox-ds.xml
-rw-r--r--. 1 root root    39214 Feb 17 23:42 ssg-firefox-ocil.xml
-rw-r--r--. 1 root root    53469 Feb 17 23:42 ssg-firefox-oval.xml
-rw-r--r--. 1 root root   181362 Feb 17 23:42 ssg-firefox-xccdf.xml
-rw-r--r--. 1 root root     1231 Feb 17 23:42 ssg-jre-cpe-dictionary.xml
-rw-r--r--. 1 root root     5862 Feb 17 23:42 ssg-jre-cpe-oval.xml
-rw-r--r--. 1 root root   265498 Feb 17 23:42 ssg-jre-ds-1.2.xml
-rw-r--r--. 1 root root   265498 Feb 17 23:42 ssg-jre-ds.xml
-rw-r--r--. 1 root root    34732 Feb 17 23:42 ssg-jre-ocil.xml
-rw-r--r--. 1 root root    42031 Feb 17 23:42 ssg-jre-oval.xml
-rw-r--r--. 1 root root   181066 Feb 17 23:42 ssg-jre-xccdf.xml
-rw-r--r--. 1 root root     6768 Feb 17 23:46 ssg-rhel6-cpe-dictionary.xml
-rw-r--r--. 1 root root    93922 Feb 17 23:46 ssg-rhel6-cpe-oval.xml
-rw-r--r--. 1 root root 22934702 Feb 17 23:46 ssg-rhel6-ds-1.2.xml
-rw-r--r--. 1 root root 22935173 Feb 17 23:46 ssg-rhel6-ds.xml
-rw-r--r--. 1 root root   733916 Feb 17 23:46 ssg-rhel6-ocil.xml
-rw-r--r--. 1 root root  2335663 Feb 17 23:46 ssg-rhel6-oval.xml
-rw-r--r--. 1 root root  7439626 Feb 17 23:46 ssg-rhel6-xccdf.xml
-rw-r--r--. 1 root root     8141 Feb 17 23:43 ssg-rhel7-cpe-dictionary.xml
-rw-r--r--. 1 root root    88026 Feb 17 23:43 ssg-rhel7-cpe-oval.xml
-rw-r--r--. 1 root root 33638186 Feb 17 23:45 ssg-rhel7-ds-1.2.xml
-rw-r--r--. 1 root root 33638657 Feb 17 23:45 ssg-rhel7-ds.xml
-rw-r--r--. 1 root root  1444004 Feb 17 23:43 ssg-rhel7-ocil.xml
-rw-r--r--. 1 root root  3773855 Feb 17 23:43 ssg-rhel7-oval.xml
-rw-r--r--. 1 root root 10428165 Feb 17 23:43 ssg-rhel7-xccdf.xml
-rw-r--r--. 1 root root     6427 Feb 17 23:43 ssg-rhel8-cpe-dictionary.xml
-rw-r--r--. 1 root root    88026 Feb 17 23:43 ssg-rhel8-cpe-oval.xml
-rw-r--r--. 1 root root 17084129 Feb 17 23:44 ssg-rhel8-ds-1.2.xml
-rw-r--r--. 1 root root 17084455 Feb 17 23:44 ssg-rhel8-ds.xml
-rw-r--r--. 1 root root  1517008 Feb 17 23:43 ssg-rhel8-ocil.xml
-rw-r--r--. 1 root root  3877481 Feb 17 23:43 ssg-rhel8-oval.xml
-rw-r--r--. 1 root root 10366637 Feb 17 23:43 ssg-rhel8-xccdf.xml
  1. 查看
$ oscap info /usr/share/xml/scap/ssg/content/ssg-rhel8-xccdf.xml
Document type: XCCDF Checklist
Checklist version: 1.1
Imported: 2021-02-17T23:43:48
Status: draft
Generated: 2021-02-17
Resolved: true
Profiles:
        Title: ANSSI-BP-028 (enhanced)
                Id: anssi_bp28_enhanced
        Title: ANSSI-BP-028 (intermediary)
                Id: anssi_bp28_intermediary
        Title: ANSSI-BP-028 (minimal)
                Id: anssi_bp28_minimal
        Title: CIS Red Hat Enterprise Linux 8 Benchmark
                Id: cis
        Title: Unclassified Information in Non-federal Information Systems and Organizations (NIST 800-171)
                Id: cui
        Title: Australian Cyber Security Centre (ACSC) Essential Eight
                Id: e8
        Title: Health Insurance Portability and Accountability Act (HIPAA)
                Id: hipaa
        Title: Protection Profile for General Purpose Operating Systems
                Id: ospp
        Title: PCI-DSS v3.2.1 Control Baseline for Red Hat Enterprise Linux 8
                Id: pci-dss
        Title: DISA STIG for Red Hat Enterprise Linux 8
                Id: stig
Referenced check files:
        ssg-rhel8-oval.xml
                system: http://oval.mitre.org/XMLSchema/oval-definitions-5
        ssg-rhel8-ocil.xml
                system: http://scap.nist.gov/schema/ocil/2
        https://www.redhat.com/security/data/oval/com.redhat.rhsa-RHEL8.xml
                system: http://oval.mitre.org/XMLSchema/oval-definitions-5

基准合规扫描

  1. 针对“hipaa”进行基准进行合规扫描,将扫描结果保存到“/tmp/report.html“。
$ oscap xccdf eval --report /tmp/report.html --profile hipaa /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
WARNING: Datastream component 'scap_org.open-scap_cref_security-data-oval-com.redhat.rhsa-RHEL8.xml' points out to the remote 'https://www.redhat.com/security/data/oval/com.redhat.rhsa-RHEL8.xml'. Use '--fetch-remote-resources' option to download it.
WARNING: Skipping 'https://www.redhat.com/security/data/oval/com.redhat.rhsa-RHEL8.xml' file which is referenced from datastream
WARNING: Skipping ./security-data-oval-com.redhat.rhsa-RHEL8.xml file which is referenced from XCCDF content
Title   Verify File Hashes with RPM
Rule    xccdf_org.ssgproject.content_rule_rpm_verify_hashes
Ident   CCE-80857-6
Result  pass
 
Title   Verify and Correct File Permissions with RPM
Rule    xccdf_org.ssgproject.content_rule_rpm_verify_permissions
Ident   CCE-80858-4
Result  fail
 
Title   Configure System Cryptography Policy
Rule    xccdf_org.ssgproject.content_rule_configure_crypto_policy
Ident   CCE-80935-0
Result  fail
 
Title   Configure SSH to use System Crypto Policy
Rule    xccdf_org.ssgproject.content_rule_configure_ssh_crypto_policy
Ident   CCE-80939-2
Result  pass
 
Title   Ensure Red Hat GPG Key Installed
Rule    xccdf_org.ssgproject.content_rule_ensure_redhat_gpgkey_installed
Ident   CCE-80795-8
Result  fail
。。。
  1. 查看扫描生成的报告。
    在这里插入图片描述

手动逐一修复

  1. 在上图中找到”Prevent Login to Accounts With Empty Password“,进入它的链接。然后根据修复提示在系统中执行以下命令。
$ sed --follow-symlinks -i 's/\<nullok\>//g' /etc/pam.d/system-auth
$ sed --follow-symlinks -i 's/\<nullok\>//g' /etc/pam.d/password-auth
  1. 再次针对“hipaa”进行基准进行合规扫描,将扫描结果保存到“/tmp/report.html“。
$ oscap xccdf eval --report /tmp/report.html --profile hipaa /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
  1. 查看生成的报告,确认已经通过”Prevent Login to Accounts With Empty Password“合规项目检查。
    在这里插入图片描述

手动批量修复

  1. 基于“anssi_bp28_minimal”的profile扫描,扫描结果保存到“scan-xccdf-anssi-min-results.xml”,扫描报告保存到“scan-xccdf-anssi-min-results.html”文件。
$ oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_anssi_bp28_minimal --results /tmp/scan-xccdf-anssi-min-results.xml --report /tmp/scan-xccdf-anssi-min-report.html /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
  1. 查看扫描报告,如下图,确认有23项不满足。
    在这里插入图片描述
  2. 根据前面的扫描结果“scan-xccdf-anssi-min-results.xml”进行自动修复,同时生成扫描报告。注意:自动修复不一定都会成功。
$ oscap xccdf remediate --results /tmp/scan-xccdf-anssi-min-remediate.xml --report /tmp/scan-xccdf-anssi-min-remediate.html /tmp/scan-xccdf-anssi-min-results.xml
WARNING: Skipping /tmp/ssg-rhel8-oval.xml file which is referenced from XCCDF content
WARNING: Skipping /tmp/security-data-oval-com.redhat.rhsa-RHEL8.xml file which is referenced from XCCDF content
WARNING: Skipping /tmp/ssg-rhel8-oval.xml file which is referenced from XCCDF content
WARNING: Skipping /tmp/security-data-oval-com.redhat.rhsa-RHEL8.xml file which is referenced from XCCDF content
Title   Install dnf-automatic Package
Rule    xccdf_org.ssgproject.content_rule_package_dnf-automatic_installed
Ident   CCE-82985-3
Result  error
 
Title   Ensure Red Hat GPG Key Installed
Rule    xccdf_org.ssgproject.content_rule_ensure_redhat_gpgkey_installed
Ident   CCE-80795-8
Result  error
 
Title   Ensure gpgcheck Enabled for Local Packages
Rule    xccdf_org.ssgproject.content_rule_ensure_gpgcheck_local_packages
Ident   CCE-80791-7
Result  fail
 
Title   Configure dnf-automatic to Install Only Security Updates
Rule    xccdf_org.ssgproject.content_rule_dnf-automatic_security_updates_only
Ident   CCE-82267-6
Result  error
 
Title   Enable dnf-automatic Timer
Rule    xccdf_org.ssgproject.content_rule_timer_dnf-automatic_enabled
Ident   CCE-82360-9
Result  error
 
Title   Ensure gpgcheck Enabled for All yum Package Repositories
Rule    xccdf_org.ssgproject.content_rule_ensure_gpgcheck_never_disabled
Ident   CCE-80792-5
Result  error
。。。
  1. 再次查看生成的报告,确认只有17项不满足。
    在这里插入图片描述

参考

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/security_hardening/index#scanning-the-system-for-configuration-compliance-and-vulnerabilities_security-hardening
https://access.redhat.com/articles/221883
https://fatmin.com/2019/07/25/openscap-part-3-running-scans-from-the-command-line-in-rhel-7/

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在提到RHEL cp -R命令之前,需要先进行一些前置步骤。首先,我们需要解压缩rhel-server-7.5-x86_64-dvd.part1.rar和rhel-server-7.5-x86_64-dvd.part2.rar这两个文件。可以使用rar命令来解压缩这些文件。在命令行中执行以下命令: [root@server1 ~]# rar e rhel-server-7.5-x86_64-dvd.part*.rar 这个命令将解压缩这两个文件。 接下来,我们需要检查是否有rarlinux-5.6.1.tar.gz这个包。如果没有,您可以从https://www.rarlab.com/download.htm这个网站下载RAR 5.61 for Linux或RAR 5.61 for Linux x64。 一旦我们解压缩了rhel-server-7.5-x86_64-dvd.part1.rar和rhel-server-7.5-x86_64-dvd.part2.rar,并且有了rarlinux-5.6.1.tar.gz这个包,我们就可以使用cp -R命令来复制文件或目录。 RHEL cp -R命令用于递归地复制一个目录及其内容到另一个目录。其中,-R选项表示递归复制,即复制目录及其所有子目录和文件。在命令行中执行以下命令: [root@server1 ~]# cp -R /path/to/source/directory /path/to/destination/directory 将"/path/to/source/directory"替换为您要复制的源目录的路径,将"/path/to/destination/directory"替换为您要将源目录复制到的目标目录的路径。 请确保您具有足够的权限来执行复制操作,并且源目录和目标目录的路径是正确的。 总结起来,要使用RHEL cp -R命令复制文件或目录,您需要先解压缩rhel-server-7.5-x86_64-dvd.part1.rar和rhel-server-7.5-x86_64-dvd.part2.rar文件,而后检查是否有rarlinux-5.6.1.tar.gz包,最后使用cp -R命令进行复制操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [rhel-server-7.5-x86_64-dvd.iso镜像下载及rar压缩包的解压](https://blog.csdn.net/weixin_41922887/article/details/85009541)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值