# 実行例(標準出力にTSVを出す)
.\Get-NvdCveTsv.ps1 -CveId CVE-2022-31600
# ファイル保存したい場合(UTF-8)
.\Get-NvdCveTsv.ps1 -CveId CVE-2022-31600 | Out-File -FilePath .\cve.tsv -Encoding utf8
Created
September 11, 2025 00:57
-
-
Save blacknon/a78c7cb488862f8f1aa75cf0deae9c78 to your computer and use it in GitHub Desktop.
CVE-IDから必要な情報だけ引っ張ってきてTSVにする簡易スクリプト(powershell)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param( | |
| [Parameter(Mandatory=$true)] | |
| [string]$CveId | |
| ) | |
| $uri = "https://services.nvd.nist.gov/rest/json/cves/2.0?cveId=$CveId" | |
| try { | |
| $res = Invoke-RestMethod -Uri $uri -Method GET -UseBasicParsing -TimeoutSec 60 | |
| } catch { | |
| Write-Error "NVD API 取得に失敗しました: $($_.Exception.Message)" | |
| exit 1 | |
| } | |
| if (-not $res.vulnerabilities) { | |
| Write-Error "該当する脆弱性が見つかりませんでした: $CveId" | |
| exit 1 | |
| } | |
| # ヘッダ | |
| $header = @("CVE-ID","CVSS付与機関","CVSSのバージョン","脅威度スコア","ベーススコア","情報公開日","URL") | |
| $rows = New-Object System.Collections.Generic.List[object] | |
| foreach ($v in $res.vulnerabilities) { | |
| $cve = $v.cve | |
| $id = $cve.id | |
| $published = $cve.published | |
| $url = $null | |
| if ($cve.references -and $cve.references.Count -gt 0 -and $cve.references[0].url) { | |
| $url = $cve.references[0].url | |
| } else { | |
| $url = "https://nvd.nist.gov/vuln/detail/$id" | |
| } | |
| $metrics = $cve.metrics | |
| # ------- v3.x 系(cvssMetricV31)------- | |
| $v3 = $null | |
| if ($metrics -and $metrics.cvssMetricV31) { | |
| # baseScore が最大のエントリを選択(Primary/Secondary 混在可) | |
| $v3 = $metrics.cvssMetricV31 | | |
| Sort-Object -Property { [double]$_.cvssData.baseScore } -Descending | | |
| Select-Object -First 1 | |
| } | |
| if ($v3) { | |
| $rows.Add(@( | |
| $id, | |
| ($v3.source ?? ""), | |
| ($v3.cvssData.version ?? ""), | |
| ($v3.cvssData.baseSeverity ?? $v3.baseSeverity ?? ""), | |
| ([string]$v3.cvssData.baseScore), | |
| $published, | |
| $url | |
| )) | Out-Null | |
| } | |
| # ------- v2 系(cvssMetricV2)------- | |
| $v2 = $null | |
| if ($metrics -and $metrics.cvssMetricV2) { | |
| $v2 = $metrics.cvssMetricV2 | | |
| Sort-Object -Property { [double]$_.cvssData.baseScore } -Descending | | |
| Select-Object -First 1 | |
| } | |
| if ($v2) { | |
| $rows.Add(@( | |
| $id, | |
| ($v2.source ?? ""), | |
| ($v2.cvssData.version ?? ""), | |
| ($v2.baseSeverity ?? ""), | |
| ([string]$v2.cvssData.baseScore), | |
| $published, | |
| $url | |
| )) | Out-Null | |
| } | |
| } | |
| # TSV 出力(標準出力) | |
| $header -join "`t" | |
| foreach ($r in $rows) { | |
| $r -join "`t" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment