現在、PowerShell のプロジェクトに取り組んでいます。このプロジェクトは、NVD データベース XML をダウンロードし、Nexpose からのスキャン結果を得るために個別の CSV をループし、CVE 番号で識別された各脆弱性の CVSS スコアを取得します。
シート (文字列) の CVE 番号と XML (文字列) の CVE 番号の照合が完全に失敗しているようです。私が使用しているコードは以下のとおりです。
clear
[xml]$nvdxml = (New-Object system.Net.WebClient).DownloadString("http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-recent.xml")
$nsmgr = New-Object System.XML.XmlNamespaceManager($nvdxml.NameTable)
$nsmgr.AddNamespace('xsi','http://www.w3.org/2001/XMLSchema-instance')
$nsmgr.AddNamespace('vuln','http://scap.nist.gov/schema/vulnerability/0.4')
$nsmgr.AddNamespace('cvss','http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-recent.xml')
$nsmgr.AddNamespace('df','http://scap.nist.gov/schema/feed/vulnerability/2.0')
$nvdxml.SelectNodes('//vuln:product',$nsmgr) | out-null
$nvdxml.SelectNodes('//vuln:vulnerable-configuration',$nsmgr) | out-null
$nvdxml.SelectNodes('//vuln:vulnerable-software-list',$nsmgr) | out-null
$nvdxml.SelectNodes('//default:nvd',$nsmgr) | out-null
$nvdxml.SelectNodes('//default:entry',$nsmgr) | out-null
$x = import-csv "test-report.csv"
$items = @()
$x | where {$_."Vulnerability Test Result Code" -like "v*"} | %{
$item = @{}
$vid = $_."Vulnerability CVE IDs"
$entry = ""
$item["Vname"] = $_."Vulnerability Title"
$item["VNode"] = $_."Asset IP Address"
$item['VID'] = $vid
$entry = $nvdxml.nvd.entry | where { $_."cve-id" -eq $vid }
$item['Score'] = $entry.cvss.base_metrics.score
$items += $item
}
$items
$items 配列には CVE ID を持つ脆弱性が含まれていますが、文字列の比較は完全に失敗しています。オブジェクトのタイプを照会すると、
You cannot call a method on a null-valued expression.
At line:25 char:19
+ $entry.GetType <<<< ()
+ CategoryInfo : InvalidOperation: (GetType:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
CVE ID を文字列に割り当て、その文字列の XML から関連する脆弱性を取得しようとすると、比較結果が返されません。それでも、変数を同じ ID の引用符で囲まれた文字列に置き換えると、クエリは正しい結果を返します。したがって、これは失敗します
$cveID = "CVE-2003-1567"
$nvdxml.nvd.entry | where { $_."cve-id" -eq $cveID }
ただし、これは正常に機能します
$nvdxml.nvd.entry | where { $_."cve-id" -eq "CVE-2003-1567" }
何か案は?$_."cve-id" と $cveID の両方を String として明示的にキャストしてみましたが、結果は同じでした。