0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excel VBAでKEVのJSONデータを取得する

0
Posted at

1. はじめに

脆弱性対応におけるリスク評価手法のまとめ(IPA)にてリスク評価指標として

  • CVSS
  • SSVC
  • EPSS
  • KEV

が紹介されています。ここで同書によるとKEVは

KEV(Known Exploited Vulnerabilities)は、CISA(アメリカ合衆国サイバーセキュリティ・社会基盤安全保障庁)が公開している実際に悪用が確認された脆弱性を掲載したカタログ

下記の 3 要件を全て満たした脆弱性が KEV に記載される。
① CVE-ID が割り当てされている
② 悪用されていることを示す証拠がある、あるいは実際に攻撃が観測されている
③ 明確な修復措置がある

というもので、KEVに掲載されている脆弱性は緊急性が高いといえます。

KEVは米国CISAのKnown Exploited Vulnerabilities CatalogからCSV形式とJSON形式のものが提供されています。そこで脆弱性をExcelで管理していることを想定し、Excel VBAでJSON形式のデータを取得してシートへ展開します。

2. VBA-JSON

JSONのパースにVBA-JSONのJsonConverter.bas v2.3.1を使用させていただきます。Excelファイルへの組み込みは詳しくは同ページのInstallationをご覧ください。

  1. JsonConverter.basの最新版(2026/5/21時点でv2.3.1)をダウンロードする
  2. VBAの開発環境を開き、JsonConverter.basをVBA Projectへインポートする
  3. VBAの開発環境のツール→参照設定を開き、Microsoft Scripting Runtimeを有効化する

3. KEVのJSONデータを取得する

  1. Excelファイル(kevList.xlsm)に"kevList"シートをあらかじめ用意します
  2. Excel VBAで次の3つの関数を作ります
    • GetKEVData():cisa.govからKEVのJSONデータを取得しExcelのシートへ展開する
    • GetHttp():引数で与えられたURLからデータをGetし、レスポンスヘッダとレスポンステキストを取得するとともにHTTPステータスコードをリターンする
    • SaveTextData():引数で与えられたファイルパスとテキストデータをファイルへ保存する

筆者の環境は以下の通りです。

  • Windows 11 Pro 25H2
  • Microsoft Office Home and Business Premium
  • Microsoft® Excel® 2016 MSO (バージョン 2604 ビルド 16.0.19929.20172) 64 ビット
kevList.xlsm
' kevList.xlsm by ka's@pbjpkas 2026
' MIT License

Option Explicit

Sub GetKEVData()
    
    Dim url As String
    url = "https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json"
    
    Dim httpStatus As Long
    Dim allResponseHeaders As String
    Dim responseText As String
        
    httpStatus = GetHttp(url, allResponseHeaders, responseText)
    
    Call SaveTextFile(ThisWorkbook.path & "\kev_allResponseHeaders.txt", allResponseHeaders)
    Call SaveTextFile(ThisWorkbook.path & "\kev_responseText.txt", responseText)
    
    If httpStatus <> 200 Then
        MsgBox ("HTTP response is not 200 OK: " & httpStatus)
        Exit Sub
    End If
    
    Dim kevList As Object
    Set kevList = JsonConverter.ParseJson(responseText)
    If kevList.Count = 0 Then
        MsgBox ("No responseText")
        Exit Sub
    End If
    
    Sheets("kevList").Cells.Clear
    Sheets("kevList").Cells(1, "A") = "dateReleased: " & kevList("dateReleased")
    Sheets("kevList").Cells(2, "A") = "count: " & kevList("count")
    Sheets("kevList").Cells(3, "A") = "cveID"
    Sheets("kevList").Cells(3, "B") = "vendorProject"
    Sheets("kevList").Cells(3, "C") = "product"
    Sheets("kevList").Cells(3, "D") = "vulnerabilityName"
    Sheets("kevList").Cells(3, "E") = "dateAdded"
    Sheets("kevList").Cells(3, "F") = "shortDescription"
    Sheets("kevList").Cells(3, "G") = "requiredAction"
    Sheets("kevList").Cells(3, "H") = "dueDate"
    Sheets("kevList").Cells(3, "I") = "knownRansomwareCampaignUse"
    Sheets("kevList").Cells(3, "J") = "notes"
    Sheets("kevList").Cells(3, "K") = "cwes"
            
    Dim i As Long
    For i = 1 To kevList("count")
        Sheets("kevList").Cells(i + 3, "A") = kevList("vulnerabilities")(i)("cveID")
        Sheets("kevList").Cells(i + 3, "B") = kevList("vulnerabilities")(i)("vendorProject")
        Sheets("kevList").Cells(i + 3, "C") = kevList("vulnerabilities")(i)("product")
        Sheets("kevList").Cells(i + 3, "D") = kevList("vulnerabilities")(i)("vulnerabilityName")
        Sheets("kevList").Cells(i + 3, "E") = kevList("vulnerabilities")(i)("dateAdded")
        Sheets("kevList").Cells(i + 3, "F") = kevList("vulnerabilities")(i)("shortDescription")
        Sheets("kevList").Cells(i + 3, "G") = kevList("vulnerabilities")(i)("requiredAction")
        Sheets("kevList").Cells(i + 3, "H") = kevList("vulnerabilities")(i)("dueDate")
        Sheets("kevList").Cells(i + 3, "I") = kevList("vulnerabilities")(i)("knownRansomwareCampaignUse")
        Sheets("kevList").Cells(i + 3, "J") = kevList("vulnerabilities")(i)("notes")
        
        'cwesは要素の数に応じてセルに格納する文字列を生成する
        Dim cwesStr As String
        If kevList("vulnerabilities")(i)("cwes").Count = 0 Then
            cwesStr = "NONE"
        ElseIf kevList("vulnerabilities")(i)("cwes").Count = 1 Then
            cwesStr = kevList("vulnerabilities")(i)("cwes")(1)
        Else
            '要素が2個以上ある場合は2個め以降を", "で連結する
            cwesStr = kevList("vulnerabilities")(i)("cwes")(1)
            Dim j As Long
            For j = 2 To kevList("vulnerabilities")(i)("cwes").Count
                cwesStr = cwesStr & ", " & kevList("vulnerabilities")(i)("cwes")(j)
            Next j
        End If
        Sheets("kevList").Cells(i + 3, "K") = cwesStr
        
    Next i
    
End Sub

Function GetHttp(url As String, httpAllResponseHeaders As String, httpResponseText As String) As Long
    
    Dim httpObj As Object
    Set httpObj = CreateObject("MSXML2.XMLHTTP")
    
    httpObj.Open "GET", url, False
    httpObj.Send
    
    httpAllResponseHeaders = httpObj.getAllResponseHeaders()
    httpResponseText = httpObj.responseText
    
    GetHttp = httpObj.Status
    
End Function

Sub SaveTextFile(path As String, textData As String)
    
    Dim fileNum As Long
    fileNum = FreeFile()
    
    Open path For Output As #fileNum
    Print #fileNum, textData
    Close #fileNum
    
End Sub

4. おわりに

Excel VBAでWebからJSON形式のデータを取得しパースできるようになりました。KEVだけでなくNational Vulnerability Databaseが提供しているVulnerability APIsでCVE一覧を取得1するのにも応用できると思います。

  1. 参考:Pythonで始めるテストツール製作(6)NVDからcpeNameで脆弱性一覧を取得する ↩

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?