OpenSCAP安装与使用

OpenSCAP安装与使用

OpenSCAP介绍

主要功能

OpenSCAP是RedHat支持的开源软件项目,主要为Linux操作系统提供安全合规检查和漏洞评估。

安全合规: 安全合规是计算机系统符合特定安全策略的状态。在不断变化的计算机安全世界中,每天都在发现和修补新的漏洞,因此强制执行安全合规性必须是一个持续的过程。它还需要包括一种对安全策略进行调整的方法,以及定期评估和风险监测。OpenSCAP 生态系统提供工具和可定制的策略,以快速、经济且灵活地实施此类流程。
漏洞评估: 漏洞评估是识别和分类系统漏洞的过程。系统存在未修补的漏洞可能会产生一系列后果,漏洞被攻击者利用可能导致严重损害。在 21 世纪,任何组织都必须及时检查识别存在漏洞的软件清单。OpenSCAP 项目提供了用于自动漏洞检查的工具,让您能够在攻击发生之前采取措施进行阻止。

什么是SCAP

SCAP(Security Content Automation Protocol:安全内容自动化协议)由NIST(National Institute of Standards and Technology:美国国家标准与技术研究院)提出,NIST期望利用SCAP解决三个棘手的问题:一是实现高层政策法规(如FISMA,ISO27000系列)等到底层实施的落地,二是将信息安全所涉及的各个要素标准化(如统一漏洞的命名及严重性度量),三是将复杂的系统配置核查工作自动化。SCAP是当前美国比较成熟的一套信息安全评估标准体系,其标准化、自动化的思想对信息安全行业产生了深远的影响。

NIST将SCAP 分为两个方面进行解释:Protocol(协议)与Content(内容)。Protocol是指SCAP由一系列现有的公开标准构成,这些公开标准被称为SCAP Element(SCAP元素)。Protocol规范了这些Element之间如何协同工作,Content指按照Protocol的约定,利用Element描述生成的应用于实际检查工作的数据。例如,FDCC(Federal Desktop CoreConfiguration:联邦桌面核心配置)、USGCB(United States Government ConfigurationBaseline:美国政府配置基线)等官方的检查单数据格式均为SCAP Content。

SCAP版本1.0包含以下六个SCAP元素:XCCDF、OVAL、CVE、CCE、CPE、CVSS。这些标准在SCAP产生之前都已经存在,并在各自的领域发挥着重要作用。其中一些标准我们可能之前有所了解,如CVE、CVSS。当SCAP将它们整合后,其整体标准化的优势变得十分明显。SCAP为安全工具实现标准化提供了解决方案:标准的输入数据格式、标准的处理方法和标准的输出数据格式,这非常有利于安全工具之间实现数据交换。

SCAPv2 FAQ: https://csrc.nist.gov/Projects/Security-Content-Automation-Protocol-v2/faqs

SCAP组件介绍

SCAP组件名称描述维护组织
通用配置列举(CCE: Common Configuration Enumeration)定义了与安全相关的系统配置项标准MITRE
通用平台列举(CPE: Common Platform Enumeration)定义了平台及版本的标准MITRE
通用脆弱性与漏洞列举(CVE: Common Vulnerabilities and Exposures)定义了与软件缺陷相关的标准MITRE
通用脆弱性评分系统(CVSS: Common Vulnerability Scoring System)定义了脆弱性对系统影响的评分FIRST
可扩展配置检查列表描述格式(XCCDF: Extensible Configuration Checklist Description Format)定义了检查列表与检查报告的XML描述格式NAS&NIST
开放脆弱性评估描述格式(OVAL: Open Vulnerability and Assessment Language)定义了用于检查列表的测试过程MITRE

其他略缩语

SSG: SCAP安全指南(SCAP Security Guide,SSG)。使用OpenSCAP执行合规检查或漏洞评估任务时,需要指定SCAP格式的安全策略,也称之为SCAP内容。有许多提供SCAP内容的供应商。SSG是由SCAP官方提供的SCAP内容,并且为许多Linux发行版以scap-security-guide包的形式提供。
PCI-DSS: 支付卡行业数据安全标准(Payment Card Industry Data Security Standard)。
USGCB: 美国政府配置基线(United States Government Configuration Baseline)。
CIS: 互联网安全中心(Center for Internet Security),一个非营利性组织。CIS Benchmark即为该组织制定发布的安全基线。
HIPAA: 健康保险流通与责任法案(Health Insurance Portability and Accountability Act),该项法案旨在保护受保护的健康信息(protected health information,PHI),以加强信息共享,提高医疗保健系统的效率和质量。HIPAA是国际公认的,一套比较完善的针对个人健康信息的隐私安全法律保护体系。
OSPP: 通用操作系统保护配置文件(Protection Profile for General Purpose Operating Systems)。
CWE: 常见缺陷列表(Common Weakness Enumeration),是MITRE公司继CVE之后的又一个安全漏洞词典。
DS: 数据流(data streams)。最常见的SCAP文件类型是SCAP源数据流。
ARF: 资产报告格式(Asset Reporting Format),一种表示关于资产以及资产和报告之间关系的信息传输格式的数据模型。

官方网站

OpenSCAP官方网站:http://www.open-scap.org/
OpenSCAP用户手册:https://static.open-scap.org/openscap-1.3/oscap_user_manual.html

OpenSCAP安装

#安装openscap-scanner
yum install -y openscap-scanner
#安装扩展工具(包含远程扫描、虚拟机扫描、容器扫描等工具,如果没有这些需求可以跳过)
yum install -y openscap-utils openscap-containers atomic python-docker-py
#安装SCAP Security Guide (SSG)
yum install -y scap-security-guide
#查看OpenSCAP版本
oscap --version
#查看SSG文件,默认路径在/usr/share/xml/scap/ssg/content/
ls -lh /usr/share/xml/scap/ssg/content/

OpenSCAP使用

查看适用的SCAP内容信息

#过滤centos7的SSG文件
ls -lh /usr/share/xml/scap/ssg/content/ |grep centos7
ls -lh /usr/share/xml/scap/ssg/content/ |grep rhel7
#查看SCAP内容信息
oscap info /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml		#Source Data Stream格式
oscap info /usr/share/xml/scap/ssg/content/ssg-centos7-xccdf.xml	#XCCDF Checklist格式
oscap info /usr/share/xml/scap/ssg/content/ssg-rhel7-oval.xml		#OVAL Definitions格式

#SCAP内容说明
- Document type: 文档类型
- Imported: 文档导入时间
- Stream: 数据流ID
- Version: SCAP标准的版本
- Checklists: 可用检查的列表
- Status: XCCDF基准状态。常用的值包括“accepted已接受”、“draft草案”、“deprecated已弃用”和“incomplete不完整”
- Profiles: 可用的配置文件
- Checks: 数据流中的OVAL检查组件
- Dictionaries: 数据流中的CPE字典组件

#查看SCAP内容中的Profile详细信息,--profile参数提供完整的配置文件ID,也可以只提供配置文件ID的后缀,以下两个命令效果相同
oscap info --profile xccdf_org.ssgproject.content_profile_pci-dss /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml
oscap info --profile pci-dss /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

常用合规检查命令用法

#创建目录并切换
mkdir /root/oscap && cd /root/oscap

#使用ssg-centos7-ds.xml的pci-dss基线标准进行合规检查(推荐)
oscap xccdf eval \
	--profile xccdf_org.ssgproject.content_profile_pci-dss \
	--results ssg-ds-results-pci-dss.xml \
	--report ssg-ds-report-pci-dss.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml
#使用ssg-centos7-ds.xml的standard基线进行合规检查
oscap xccdf eval \
	--profile xccdf_org.ssgproject.content_profile_standard \
	--results ssg-ds-results-standard.xml \
	--report ssg-ds-report-standard.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

#使用ssg-centos7-xccdf.xml的pci-dss基线标准进行合规检查
oscap xccdf eval \
	--profile pci-dss \
	--results ssg-xccdf-results-pci-dss.xml \
	--report ssg-xccdf-report-pci-dss.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-xccdf.xml
#使用ssg-centos7-xccdf.xml的standard基线标准进行合规检查
oscap xccdf eval \
	--profile standard \
	--results ssg-xccdf-results-standard.xml \
	--report ssg-xccdf-report-standard.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-xccdf.xml

常用漏洞评估命令用法

使用SSG提供的SCAP内容进行漏洞评估

#使用ssg-centos7-ds.xml进行漏洞评估
oscap oval eval \
	--results ssg-ds-results.xml \
	--report ssg-ds-report.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

下载RHEL提供的SCAP内容进行漏洞评估(仅适用于RHEL)

#红帽安全团队为影响RHEL 3、4、5、6、7和8的所有漏洞(通过CVE名称识别)提供了OVAL定义。用户可以通过漏洞扫描来判断系统是否存在漏洞。数据以三种方式提供——OVAL文件、OVAL+XCCDF和SCAP源数据流。
#下载RHEL安全团队基于CVE名称的SCAP内容,进行系统的CVE漏洞评估
mkdir -p /usr/share/xml/scap/rhel/content
wget -O /usr/share/xml/scap/rhel/content/com.redhat.rhsa-all.xccdf.xml \
	https://www.redhat.com/security/data/metrics/com.redhat.rhsa-all.xccdf.xml
wget -O /usr/share/xml/scap/rhel/content/com.redhat.rhsa-all.oval.xml \
	https://www.redhat.com/security/data/oval/com.redhat.rhsa-all.xml
wget -O /usr/share/xml/scap/rhel/content/com.redhat.rhsa-all.ds.xml \
	https://www.redhat.com/security/data/metrics/ds/com.redhat.rhsa-all.ds.xml
#查看rhel提供的SCAP内容
ls -lh /usr/share/xml/scap/rhel/content/com.redhat.rhsa-all*
#OVAL+XCCDF的评估
oscap xccdf eval \
	--results rhel-xccdf-results.xml \
	--report rhel-xccdf-report.html \
	/usr/share/xml/scap/rhel/content/com.redhat.rhsa-all.xccdf.xml
#OVAL格式的评估
oscap oval eval \
	--results rhel-oval-results.xml \
	--report rhel-oval-report.html \
	/usr/share/xml/scap/rhel/content/com.redhat.rhsa-all.oval.xml
#Source data stream格式的评估
oscap xccdf eval \
	--results rhel-ds-results.xml \
	--report rhel-ds-report.html \
	/usr/share/xml/scap/rhel/content/com.redhat.rhsa-all.ds.xml

远程主机扫描

oscap-ssh命令是一个简单的工具,用于通过网络扫描使用OpenSCAP的远程计算机并收集结果。

该工具使用SSH连接将SCAP内容复制到远程计算机,然后运行目标系统的评估并将结果下载回来。远程机器需要安装OpenSCAP。支持评估源数据流和OVAL文件。

#远程主机上安装openscap-scanner
yum install -y openscap-scanner

#远程执行合规检查任务
oscap-ssh root@192.168.64.140 22 xccdf eval \
	--profile xccdf_org.ssgproject.content_profile_pci-dss \
	--results 192.168.64.140-ssg-ds-results-pci-dss.xml \
	--report 192.168.64.140-ssg-ds-report-pci-dss.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

#远程执行漏洞评估任务
oscap-ssh root@192.168.64.140 22 oval eval \
	--results 192.168.64.140-ssg-ds-results.xml \
	--report 192.168.64.140-ssg-ds-report.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

扫描容器和images

oscap-docker用于扫描Docker容器和images。它可以评估容器或image中的漏洞,并检查它们是否符合安全策略。

oscap-docker工具使用一种称为脱机扫描的技术。这意味着容器的文件系统被挂载到主机上的一个目录。挂载的文件系统是只读的。OpenSCAP从主机评估容器。因此,容器中没有安装任何代理,容器也没有被碰触或以任何方式改变。

podman容器也有相应工具——oscap-podman,使用方法和oscap-docker类似。

#拉取镜像
docker pull centos:centos7
#查看images
docker images
#扫描image
oscap-docker image centos:centos7 xccdf eval \
	--profile xccdf_org.ssgproject.content_profile_pci-dss \
	--report docker-image-centos7.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

#运行容器
docker run -itd --name centos7  centos:centos7
#查看容器
docker ps -a
#扫描容器(支持扫描正在运行或未运行的的容器)
oscap-docker container centos7 xccdf eval \
	--profile xccdf_org.ssgproject.content_profile_pci-dss \
	--report docker-container-centos7.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

oscap-docker使用参考:https://www.open-scap.org/resources/documentation/security-compliance-of-rhel7-docker-containers/

扫描虚拟机和镜像

oscap-vm用于扫描评估虚拟机。与oscap-docker类似,也使用脱机扫描的技术。

#安装挂载虚拟机镜像的相关工具和依赖
yum install -y libguestfs libguestfs-tools libvirt
systemctl start libvirtd

#执行扫描任务--qcow2镜像
oscap-vm image CentOS-7-x86_64-GenericCloud-1811.qcow2 xccdf eval \
	--profile xccdf_org.ssgproject.content_profile_pci-dss \
	--report vm-qcow2-centos7.html \
	/usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

#上述扫描任务可能比较耗时,依赖于服务器的性能。因为实质上是将qcow2镜像挂载以kvm虚拟机运行
#查看运行中的kvm虚拟机
virsh list --all
#获取指定虚拟机的基本信息
virsh dominfo guestfs-mi3v237y3o8ricog
#查看虚拟机磁盘和其它块设备的详情
virsh domblklist guestfs-mi3v237y3o8ricog
#删除虚拟机
virsh destroy guestfs-mi3v237y3o8ricog

CentOS官方qcow2镜像下载站:https://cloud.centos.org/centos/7/images/

可能有用的链接:
https://lening.li/posts/scan
https://www.redhat.com/sysadmin/libguestfs-manage-vm
https://codeantenna.com/a/b6VFu28SO7
https://github.com/bilelmsekni/OpenStack-Grizzly-Install-Guide/issues/71
https://blog.csdn.net/qq_39965541/article/details/123727943
https://www.cnblogs.com/5201351/p/4462541.html

其他用法

#针对输出结果进行修复,并不一定能成功修复
oscap xccdf remediate --report remediation-report.html ssg-xccdf-results-pci-dss.xml
#导出基线整改或漏洞修复的ssh脚本
oscap xccdf generate fix --profile xccdf_org.ssgproject.content_profile_pci-dss /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml > fix.sh
#导出基线整改或漏洞修复的ansible playbook
oscap xccdf generate fix --fix-type ansible --profile xccdf_org.ssgproject.content_profile_pci-dss /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml > fix-playbook.yml

导出报告截图

在这里插入图片描述

在这里插入图片描述

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值