OpenSCAP 和 SCAP Security Guide 的作用
- OpenSCAP 是一个用于自动化安全合规检查的开源工具,基于 SCAP(Security Content Automation Protocol,安全内容自动化协议)。它用于扫描系统,评估是否符合特定的安全基准,并生成修复建议或自动应用修复措施。
- SCAP Security Guide(SSG) 是一套预定义的安全基准规则库,包含适用于不同操作系统(如 Ubuntu、RHEL、CentOS 等)的安全配置标准,例如 CIS(Center for Internet Security)基准、DISA STIG 及 PCI-DSS 规范。SSG 提供了 SCAP 兼容的 XML 文件,供 OpenSCAP 解析和执行安全检查。
OpenSCAP 负责执行安全扫描,SCAP Security Guide 提供具体的安全基准规则,两者配合使用,可以自动化地评估和加固系统的安全性。
1. 准备环境
确保你的系统已安装 OpenSCAP 的必要工具。如果尚未安装,可使用以下命令安装:
apt update
apt install openscap-scanner -y
安装完成后,验证 OpenSCAP 是否成功安装:
oscap --version
你应该会看到类似如下的版本信息:
OpenSCAP command line tool (oscap) 1.3.9
2. 下载并解压 SCAP Security Guide
- 下载 SCAP Security Guide:
wget https://github.com/ComplianceAsCode/content/releases/download/v0.1.76/scap-security-guide-0.1.76.zip
- 解压文件并进入目录:
unzip scap-security-guide-0.1.76.zip
cd scap-security-guide-0.1.76
解压后,你会看到多个 SCAP 配置文件。
3. 选择适合的安全基准配置文件
运行以下命令查看 Ubuntu 24.04 可用的 SCAP 配置文件:
oscap info ssg-ubuntu2404-ds.xml
Ubuntu 24.04 支持以下基准配置:
- CIS Level 1 Server(较宽松,适用于基本安全需求)
xccdf_org.ssgproject.content_profile_cis_level1_server
- CIS Level 1 Workstation
xccdf_org.ssgproject.content_profile_cis_level1_workstation
- CIS Level 2 Server(更严格,适用于高安全需求)
xccdf_org.ssgproject.content_profile_cis_level2_server
- CIS Level 2 Workstation
xccdf_org.ssgproject.content_profile_cis_level2_workstation
推荐配置:
- 服务器:
xccdf_org.ssgproject.content_profile_cis_level1_server
或xccdf_org.ssgproject.content_profile_cis_level2_server
- 工作站:
xccdf_org.ssgproject.content_profile_cis_level1_workstation
或xccdf_org.ssgproject.content_profile_cis_level2_workstation
4. 执行安全检查
使用以下命令评估系统是否符合 CIS Level 1 Server 基准:
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_level1_server \
--results scan-results.xml \
--report report.html \
ssg-ubuntu2404-ds.xml
输出说明:
scan-results.xml
:详细的扫描结果文件。report.html
:可视化的合规性报告,可用浏览器打开查看。
5. 生成并应用安全加固修复脚本
如果扫描结果显示有不合规项,可以生成修复脚本并应用加固:
- 生成修复脚本:
oscap xccdf generate fix --profile xccdf_org.ssgproject.content_profile_cis_level1_server \
--output remediation.sh \
ssg-ubuntu2404-ds.xml
- 检查修复脚本内容(确保符合预期):
cat remediation.sh
- 执行修复脚本:
bash remediation.sh
注意:修复过程可能会更改系统配置,建议在执行前备份关键数据。
- 再次检查修复效果:
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_level1_server \
--results scan-results-after.xml \
--report report-after.html \
ssg-ubuntu2404-ds.xml
6. 总结与注意事项
选择合适的安全基准
- 服务器推荐
cis_level1_server
或cis_level2_server
。 - 工作站推荐
cis_level1_workstation
或cis_level2_workstation
。
错误处理
- 如果执行
oscap
命令时遇到错误,可检查scan-results.xml
或report.html
获取详细信息。 - 部分规则可能需要手动调整,具体可参考
remediation.sh
内容。
查看合规性报告
使用浏览器打开 report.html
,详细查看系统安全状态。
完整流程示例(适用于服务器,CIS Level 1):
# 1. 运行安全合规性检查
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_level1_server \
--results scan-results.xml \
--report report.html \
ssg-ubuntu2404-ds.xml
# 2. 生成修复脚本
oscap xccdf generate fix --profile xccdf_org.ssgproject.content_profile_cis_level1_server \
--output remediation.sh \
ssg-ubuntu2404-ds.xml
# 3. 执行修复脚本
bash remediation.sh
# 4. 重新运行检查以验证修复效果
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_level1_server \
--results scan-results-after.xml \
--report report-after.html \
ssg-ubuntu2404-ds.xml
如果你有不同的系统用途(服务器/工作站)或需要更高安全级别(Level 2),可以调整 --profile
参数来适配不同基准。
发表回复