Skip to content

Instantly share code, notes, and snippets.

@markgodiy
Created June 27, 2024 20:36
Show Gist options
  • Select an option

  • Save markgodiy/a7ad996f0b8bc7913cffe665aa8af302 to your computer and use it in GitHub Desktop.

Select an option

Save markgodiy/a7ad996f0b8bc7913cffe665aa8af302 to your computer and use it in GitHub Desktop.
Get-CVEInfo from CISA Vulnrichment repo
function Get-CVEInfo {
<#
.DESCRIPTION
Get-CVEInfo from CISA Vulnrichment repo. MarkGo2024.
.EXAMPLE
Get-CVEInfo -cveId "CVE-2024-39466"
#>
param (
[string]$cveId
)
$owner,$repo,$branch = "cisagov","vulnrichment","develop"
# Parse CVE ID, extract values
$cveId = $cveId.ToUpper()
$yr = $cveId.Substring(4, 4)
$number = $cveId.Substring(9)
# if number is 4 digits, extract first digit to use as directory name
if ($number.Length -eq 4) {$numberprefix = $number.Substring(0, 1),$strFolder = $numberprefix + "xxx"}
# if number is 5 digits, extract first 2 digits to use as directory name
if ($number.Length -eq 5) {$numberprefix = $number.Substring(0, 2);$strFolder = $numberprefix + "xxx"}
# GitHub Raw content API URL
$apiUrl = "https://raw.githubusercontent.com/$owner/$repo/$branch/$yr/$strFolder/$cveId.json"
try {
# Fetch the Raw content from the API URL
$cveContent = Invoke-RestMethod -Uri $apiUrl -Headers @{ "User-Agent" = "PowerShell" }
return $cveContent.containers.cna
}
catch {
Write-Output "CVE ID not found or error accessing the repository.`n$apiUr`nError: $_"
}
}
# Example usage
Get-CVEInfo -cveId "CVE-2024-39466"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment