2

我正在使用 DISA STIG xml 文件,但遇到了一些问题。他们使用 XSL 样式表文件,所以当我对其进行获取内容时,我得到的只是三个属性(基准、xml、xml-stylesheet)、零个子节点。我一直在寻找 DAYS 现在如何真正能够在原始 XML 文件中的实际节点中解析/搜索,例如查找等。

看起来

$STIG = [xml]$XmlDocument = Get-Content -Path "$Path\U_IIS_8-5_Server_STIG_V1R2_Manual-xccdf.xml"

只有

xml                            xml-stylesheet                          Benchmark
---                            --------------                          ---------
version="1.0" encoding="utf-8" type='text/xsl' href='STIG_unclass.xsl' Benchmark

而且我不知道如何将此 XML 转换为我可以实际搜索、解析等的 XML。

4

1 回答 1

0

PowerShell 将[xml]文档转换为深层/复杂对象。我下载了一个 STIG 文档并像这样加载它

PS> $xml = [xml](Get-Content .\U_A10_Networks_ADC_ALG_STIG_V1R1_Manual-xccdf.xml)

现在,您可以评估对象

PS> $xml

xml                            xml-stylesheet                          Benchmark
---                            --------------                          ---------
version="1.0" encoding="utf-8" type='text/xsl' href='STIG_unclass.xsl' Benchmark

或者遍历它的属性。

PS> $xml.Benchmark


dsig           : http://www.w3.org/2000/09/xmldsig#
xsi            : http://www.w3.org/2001/XMLSchema-instance
cpe            : http://cpe.mitre.org/language/2.0
xhtml          : http://www.w3.org/1999/xhtml
dc             : http://purl.org/dc/elements/1.1/
id             : A10_Networks_ADC_ALG_STIG
lang           : en
schemaLocation : http://checklists.nist.gov/xccdf/1.1 http://nvd.nist.gov/schema/xccdf-1.1.4.xsd
                 http://cpe.mitre.org/dictionary/2.0 http://cpe.mitre.org/files/cpe-dictionary_2.1.xsd
xmlns          : http://checklists.nist.gov/xccdf/1.1
status         : status
title          : A10 Networks ADC ALG Security Technical Implementation Guide
description    : This Security Technical Implementation Guide is published as a tool to improve the security of
                 Department of Defense (DoD) information systems. The requirements are derived from the National
                 Institute of Standards and Technology (NIST) 800-53 and related documents. Comments or proposed
                 revisions to this document should be sent via e-mail to the following address: disa.stig_spt@mail.mil.
notice         : notice
reference      : reference
plain-text     : plain-text
version        : 1
Profile        : {Profile, Profile, Profile, Profile...}
Group          : {Group, Group, Group, Group...}

看起来大部分信息都在这条路上:

$xml.Benchmark.Group.Rule
于 2020-12-15T15:49:01.287 回答