首页 > 其他分享 >OpenSCAP的基础使用方法

OpenSCAP的基础使用方法

时间:2023-06-09 10:23:18浏览次数:61  
标签:xml xccdf 基础 content org scap ssg 方法 OpenSCAP

大背景

信息安全态势日趋严重,对我们网络安全工作提出了更高的要求,遵循一定的网络安全框架的同时,我们需要在各个不同的环节部署不同的安全措施形成纵深防御体系。
服务器侧的安全基线在安全管理中是一个基础性的工作,是整个体系中不可缺少的一环,但是也是一个比较麻烦的工作,一方面是因为企业中通常服务器数量较多,有各种不同版本的操作系统;
另外一方面是因为企业通常没有能力去制定适合自己的安全基线,或者大多数的安全基线都是安全人员“想当然”制定的,从各种渠道摘抄汇总,然后进行取舍而来。带来的问题是基线缺失、基线不完整等等。
在没有购买商业产品的情况下,要么我们自己写脚本,要么使用开源工具对系统进行基线设置以及进行基线核查。

OpenSCAP的介绍

官网

OpenSCAP 是一个获得SCAP认证的免费开源的自动化扫描,基线核查,报告和自动修复工具,目前主要由 Redhat 进行维护。
OpenSCAP 由 工具基线库 两个部分组成,两者没有紧密的耦合关系,比如使用http://vuls.io也可以运行部分基线库,基线库部分功能也支持使用 ansible 和 bash 来执行。

SCAP,Security Content Automation Protocol,即安全内容自动化协议。是由NIST(National Institute of Standards and Technology,美国国家标准与技术研究院)提出,而且NIST还建立了信息安全类产品的SCAP兼容性认证机制。

SCAP包含了Protocol(协议)与Content(内容),协议是指SCAP由一系列现有的公开标准构成,这些公开标准被称为SCAP Element(SCAP元素),Protocol规范了这些Element之间如何协同工作。Content指按照Protocol的约定,利用Element描述的生成应用于实际检查工作的数据。

openscap由工具集(oscap)及基线库(SSG)组成,其中工具集包括如下:

  • OpenSCAP Base 命令行工具,本地扫描
  • OpenSCAP Daemon 守护进程工具,功能同 OpenSCAP Base
  • SCAP Workbench 图形界面,功能同 SCAP Base,可视化操作

ssg 的xml默认保存目 /usr/share/xml/scap/ssg/content/

支持的扫描安全类型

  • 通用漏洞披露 (CVE)
  • 通用配置评估 (CCE)
  • 通用平台评估 (CPE)
  • 通用漏洞评分系统 (CVSS)
  • 通用弱点枚举 (CWE)
  • The Script Check Engine (SCE)

基础使用

这里主要介绍 OpenSCAP Base 的使用

安装工具

不同系统的略有区别

ubuntu

apt install libopenscap8 -y

Centos

yum install openscap-scanner -y

安装基线库

Centos

Centos的最好安装

yum install scap-security-guide -y

ubuntu

ubuntu需要下载离线包安装

下载地址

主要下载两部分

  • ssg-base
  • ssg-debderived

根据版本不同做取舍

ubuntu16.04

wget http://ftp.sjtu.edu.cn/ubuntu/pool/universe/s/scap-security-guide/ssg-base_0.1.39-2_all.deb
wget http://ftp.sjtu.edu.cn/ubuntu/pool/universe/s/scap-security-guide/ssg-debderived_0.1.39-2_all.deb
dpkg -i *.deb

ubuntu22.04

wget http://ftp.sjtu.edu.cn/ubuntu/pool/universe/s/scap-security-guide/ssg-base_0.1.65-1_all.deb
wget http://ftp.sjtu.edu.cn/ubuntu/pool/universe/s/scap-security-guide/ssg-debderived_0.1.65-1_all.deb
dpkg -i *.deb

基础使用

咱们使用这个工具的最基础需求肯定是扫描缺失,然后修复

查看相关信息

Centos

oscap info /usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml

Document type: Source Data Stream
Imported: 2023-03-07T22:52:18

Stream: scap_org.open-scap_datastream_from_xccdf_ssg-rhel7-xccdf.xml
Generated: (null)
Version: 1.3
Checklists:
	Ref-Id: scap_org.open-scap_cref_ssg-rhel7-xccdf.xml
WARNING: Datastream component 'scap_org.open-scap_cref_security-data-oval-com.redhat.rhsa-RHEL7.xml.bz2' points out to the remote 'https://access.redhat.com/security/data/oval/com.redhat.rhsa-RHEL7.xml.bz2'. Use '--fetch-remote-resources' option to download it.
WARNING: Skipping 'https://access.redhat.com/security/data/oval/com.redhat.rhsa-RHEL7.xml.bz2' file which is referenced from datastream
		Status: draft
		Generated: 2023-03-07
		Resolved: true
		Profiles:
			Title: C2S for Red Hat Enterprise Linux 7
				Id: xccdf_org.ssgproject.content_profile_C2S
			Title: ANSSI-BP-028 (enhanced)
				Id: xccdf_org.ssgproject.content_profile_anssi_nt28_enhanced
			Title: ANSSI-BP-028 (high)
				Id: xccdf_org.ssgproject.content_profile_anssi_nt28_high
			Title: ANSSI-BP-028 (intermediary)
				Id: xccdf_org.ssgproject.content_profile_anssi_nt28_intermediary
			Title: ANSSI-BP-028 (minimal)
				Id: xccdf_org.ssgproject.content_profile_anssi_nt28_minimal
			Title: CIS Red Hat Enterprise Linux 7 Benchmark for Level 2 - Server
				Id: xccdf_org.ssgproject.content_profile_cis
			Title: CIS Red Hat Enterprise Linux 7 Benchmark for Level 1 - Server
				Id: xccdf_org.ssgproject.content_profile_cis_server_l1
			Title: CIS Red Hat Enterprise Linux 7 Benchmark for Level 1 - Workstation
				Id: xccdf_org.ssgproject.content_profile_cis_workstation_l1
			Title: CIS Red Hat Enterprise Linux 7 Benchmark for Level 2 - Workstation
				Id: xccdf_org.ssgproject.content_profile_cis_workstation_l2
			Title: Criminal Justice Information Services (CJIS) Security Policy
				Id: xccdf_org.ssgproject.content_profile_cjis
			Title: Unclassified Information in Non-federal Information Systems and Organizations (NIST 800-171)
				Id: xccdf_org.ssgproject.content_profile_cui
			Title: Australian Cyber Security Centre (ACSC) Essential Eight
				Id: xccdf_org.ssgproject.content_profile_e8
			Title: Health Insurance Portability and Accountability Act (HIPAA)
				Id: xccdf_org.ssgproject.content_profile_hipaa
			Title: NIST National Checklist Program Security Guide
				Id: xccdf_org.ssgproject.content_profile_ncp
			Title: OSPP - Protection Profile for General Purpose Operating Systems v4.2.1
				Id: xccdf_org.ssgproject.content_profile_ospp
			Title: PCI-DSS v3.2.1 Control Baseline for Red Hat Enterprise Linux 7
				Id: xccdf_org.ssgproject.content_profile_pci-dss
			Title: RHV hardening based on STIG for Red Hat Enterprise Linux 7
				Id: xccdf_org.ssgproject.content_profile_rhelh-stig
			Title: VPP - Protection Profile for Virtualization v. 1.0 for Red Hat Virtualization
				Id: xccdf_org.ssgproject.content_profile_rhelh-vpp
			Title: Red Hat Corporate Profile for Certified Cloud Providers (RH CCP)
				Id: xccdf_org.ssgproject.content_profile_rht-ccp
			Title: Standard System Security Profile for Red Hat Enterprise Linux 7
				Id: xccdf_org.ssgproject.content_profile_standard
			Title: DISA STIG for Red Hat Enterprise Linux 7
				Id: xccdf_org.ssgproject.content_profile_stig
			Title: DISA STIG with GUI for Red Hat Enterprise Linux 7
				Id: xccdf_org.ssgproject.content_profile_stig_gui
		Referenced check files:
			ssg-rhel7-oval.xml
				system: http://oval.mitre.org/XMLSchema/oval-definitions-5
			ssg-rhel7-ocil.xml
				system: http://scap.nist.gov/schema/ocil/2
			security-data-oval-com.redhat.rhsa-RHEL7.xml.bz2
				system: http://oval.mitre.org/XMLSchema/oval-definitions-5
Checks:
	Ref-Id: scap_org.open-scap_cref_ssg-rhel7-oval.xml
	Ref-Id: scap_org.open-scap_cref_ssg-rhel7-ocil.xml
	Ref-Id: scap_org.open-scap_cref_ssg-rhel7-cpe-oval.xml
	Ref-Id: scap_org.open-scap_cref_security-data-oval-com.redhat.rhsa-RHEL7.xml.bz2
Dictionaries:
	Ref-Id: scap_org.open-scap_cref_ssg-rhel7-cpe-dictionary.xml

可以看到 Profiles 部分有很多项,分别有 TitleId

这里的 Id 我们就使用 标准的xccdf_org.ssgproject.content_profile_standard

ubuntu

ubuntu16.04
oscap info /usr/share/xml/scap/ssg/content/ssg-ubuntu1604-ds.xml

Document type: Source Data Stream
Imported: 2018-07-26T22:58:28

Stream: scap_org.open-scap_datastream_from_xccdf_ssg-ubuntu1604-xccdf-1.2.xml
Generated: (null)
Version: 1.2
Checklists:
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu1604-xccdf-1.2.xml
		Status: draft
		Generated: 2018-07-26
		Resolved: true
		Profiles:
			xccdf_org.ssgproject.content_profile_anssi_np_nt28_restrictive
			xccdf_org.ssgproject.content_profile_standard
			xccdf_org.ssgproject.content_profile_anssi_np_nt28_high
			xccdf_org.ssgproject.content_profile_anssi_np_nt28_minimal
			xccdf_org.ssgproject.content_profile_anssi_np_nt28_average
		Referenced check files:
			ssg-ubuntu1604-oval.xml
				system: http://oval.mitre.org/XMLSchema/oval-definitions-5
			ssg-ubuntu1604-ocil.xml
				system: http://scap.nist.gov/schema/ocil/2
Checks:
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu1604-oval.xml
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu1604-ocil.xml
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu1604-cpe-oval.xml
Dictionaries:
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu1604-cpe-dictionary.xml

这里我们也选择标准的 xccdf_org.ssgproject.content_profile_standard

ubuntu22.04
oscap info  /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml

Document type: Source Data Stream
Imported: 2022-12-20T09:54:05

Stream: scap_org.open-scap_datastream_from_xccdf_ssg-ubuntu2204-xccdf.xml
Generated: (null)
Version: 1.3
Checklists:
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu2204-xccdf.xml
		Status: draft
		Generated: 2022-12-21
		Resolved: true
		Profiles:
			Title: CIS Ubuntu 22.04 Level 1 Server Benchmark
				Id: xccdf_org.ssgproject.content_profile_cis_level1_server
			Title: CIS Ubuntu 22.04 Level 1 Workstation Benchmark
				Id: xccdf_org.ssgproject.content_profile_cis_level1_workstation
			Title: CIS Ubuntu 22.04 Level 2 Server Benchmark
				Id: xccdf_org.ssgproject.content_profile_cis_level2_server
			Title: CIS Ubuntu 22.04 Level 2 Workstation Benchmark
				Id: xccdf_org.ssgproject.content_profile_cis_level2_workstation
			Title: Standard System Security Profile for Ubuntu 22.04
				Id: xccdf_org.ssgproject.content_profile_standard
		Referenced check files:
			ssg-ubuntu2204-oval.xml
				system: http://oval.mitre.org/XMLSchema/oval-definitions-5
			ssg-ubuntu2204-ocil.xml
				system: http://scap.nist.gov/schema/ocil/2
Checks:
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu2204-oval.xml
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu2204-ocil.xml
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu2204-cpe-oval.xml
Dictionaries:
	Ref-Id: scap_org.open-scap_cref_ssg-ubuntu2204-cpe-dictionary.xml

这里选择标准的 xccdf_org.ssgproject.content_profile_standard

扫描并输出检测报告

#centos
oscap xccdf eval --profile standard --results-arf arf.xml --report report.html /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml

#ubuntu16.04
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_standard --results-arf arf.xml --report report.html /usr/share/xml/scap/ssg/content/ssg-ubuntu1604-ds.xml

#ubuntu22.04
oscap xccdf eval --profile standard --results-arf arf.xml --report report.html /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml

生成的report.html就是网页版报告

红色的表示需要修复的部分

会给出相应的处理办法以及脚本

非常方便

扫描直接生成脚本

这里需要说明的是,ubuntu16.04测试了好多方法,是无法生成的,如果有大佬知道如何生成,可以评论补充下

ubuntu22.04

#扫描生成结果
oscap xccdf eval --profile standard --results results.xml --fetch-remote-resources /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml
#生成的结果文件
ll results.xml 
-rw-r--r-- 1 root root 7433222 Jun  9 02:04 results.xml
#查看结果ID
oscap info results.xml

然后根据结果ID 生成脚本

oscap xccdf generate fix --fix-type bash --output my-remediation-script.sh --result-id xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_standard results.xml

centos

centos的也类似

oscap xccdf eval --profile standard --results results.xml --fetch-remote-resources /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml
oscap info results.xml
oscap xccdf generate fix --fix-type bash --output my-remediation-script.sh --result-id xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_standard results.xml

标签:xml,xccdf,基础,content,org,scap,ssg,方法,OpenSCAP
From: https://www.cnblogs.com/guangdelw/p/17468410.html

相关文章

  • Python爬虫基础知识点
    Python爬虫是使用Python编写的程序,可以自动抓取互联网上的数据。常用的Python爬虫框架包括Scrapy、BeautifulSoup、Requests等。Python爬虫可以应用于众多场合,如大数据分析、信息监测、数据挖掘和机器学习等领域。那么新手应该如何学习python爬虫呢?以下是Python爬虫的基础知识:1......
  • Java利用xml将大批量数据导出到excel的一个方法
    笔者在Java开发中常常会遇到将数据库数据导出到Excel的要求,比如在我的一个项目中,客户要求所有查询结果都可以导出到Excel,对于数据量不大的(几万条),这比较容易实现,但对于数据量比较大的(几十万及以上,具体要看导出内容的字段个数和长短),则在数据库查询和生成excel文件上都会有麻烦。......
  • 非线性规划——等式约束的最优化方法(四)
    对非线性规划来说,大多数情况下我们是不可能无限制求其理想情况下的最优值的,总是存在一些约束生成了一部分可行解域。从机器学习上来说,我们的可行解域就被限制住了,直接求解起来事实上是有一定困难的,我们更希望求解的是无约束的优化问题,就衍生出拉格朗日乘子法。拉格朗日乘子法主要......
  • Terraform 改善基础架构的十个最佳实践
    Terraform是一种非常流行的开源IaC(基础设施即代码)工具,用于定义和提供完整的基础设施。Terraform于2014年推出,其采用率已在全球范围内快速增长,越来越多的开发人员正在学习Terraform并尝试在其组织中部署基础设施。 如果您已经开始使用Terraform,则必须采用最佳实践来更好......
  • spring中获取属性的方法SpelExpressionParser()
    Aa=newA();Bb=newB();声明el表达式ExpressionParserpaeser=newSpelExpressionParser();设置你要通过el表达式取的字段Expressionaid=paeser.parseExpression("id");代表内置对象(b)中的id属性Expressionbid=paeser.parseExpression(b.id);如果b对象......
  • 明解STM32—GPIO应用设计篇之IO外部中断EXTI原理及使用方法
    ​一、前言        在之前针对STM32的GPIO相关API函数及配置使用进行了详细的介绍,GPIO作为输入引脚时,调用相关读信号引脚函数接口就可以在程序的循环中,轮询的对输入信号进行读取检测操作,除了轮询的方式访问输入引脚,还可以通过另外一种叫做外部中断的方式来对引脚的输入信......
  • 非线性规划——无约束求解方法(三)
    无约束最优化问题的解析法主要有:最速下降法、牛顿法、共轭梯度法(DFP法)和变尺度法(变度量法)。对于特殊的最小二乘问题,有最小二乘法。这些方法各有千秋,除了最小二乘法,后面的方法都针对前面方法的某个问题做了改进。这些方法的核心就是研究如何确定每一步迭代的方向和步长。一、无约......
  • 【Java技术专题】「Guava开发指南」手把手教你如何进行使用Guava工具箱进行开发系统实
    Guava中的Preconditions(前置条件判断)Preconditions(前置条件):让方法调用的前置条件判断更简单。Guava在Preconditions类中提供了若干前置条件判断的实用方法,我们强烈建议在Eclipse中静态导入这些方法。每个方法都有三个变种:当方法没有额外参数时,抛出的异常中不包含错误消息,这会使......
  • C# 实现保留两位小数的方法
    1、Math.Round(0.333333,2);//按照四舍五入的国际标准2、   doubledbdata=0.335333;   stringstr1=String.Format("{0:F}",dbdata);//默认为保留两位3、   floati=0.333333;   intj=(int)(i*100);   i=j/100;4、   decimal.Round(decimal.Parse("0......
  • Linux系统中GDB调试详细操作方法
    第一:启动在shell下敲gdb命令即可启动gdb,启动后会显示下述信息,出现gdb提示符。添加编译指令:gcc-ga.c-otest打开指令:gdbtest  或者gdb  然后输入:filetest➜examplegdbGNUgdb(Ubuntu8.1.1-0ubuntu1)8.1.1Copyright(C)2018F......