docker通過(guò)sbom獲取組件版本和漏洞編號(hào)的方法
最近做 SCA 測(cè)試,需要獲取鏡像的組件和漏洞,使用 docker scout 工具,通過(guò) sbom 獲取組件名稱(chēng)、版本和漏洞編號(hào)。
docker scout
獲取組件信息
docker scout sbom --format spdx --output 2025.05.25.sbom.spdx.json nginx:stable-perl
v SBOM of image already cached, 244 packages indexed
v Report written to 2025.05.25.sbom.spdx.json
使用 SCA 工具處理組件信息。
獲取 CVE 編號(hào)

docker scout cves --format sbom nginx:stable-perl > sbom.cve.json
按行輸出 CVE 編號(hào)
import json
import re
from charset_normalizer import detect
def extract_cve_ids(file_path):
"""
Extract all CVE IDs from a JSON file.
"""
cve_pattern = re.compile(r'CVE-\d{4}-\d{4,}') # Regex pattern for CVE IDs
cve_ids = []
# Detect the file encoding
with open(file_path, 'rb') as file:
raw_data = file.read()
detected = detect(raw_data)
encoding = detected['encoding']
# Read the JSON file with the detected encoding
with open(file_path, 'r', encoding=encoding) as file:
data = json.load(file)
# Recursively search for CVE IDs in the JSON structure
def search_cve(obj):
if isinstance(obj, dict):
for key, value in obj.items():
search_cve(value)
elif isinstance(obj, list):
for item in obj:
search_cve(item)
elif isinstance(obj, str):
matches = cve_pattern.findall(obj)
cve_ids.extend(matches)
search_cve(data)
return cve_ids
# File path to 1.json
file_path = "sbom.cve.json"
# Extract CVE IDs and print them
cve_ids = extract_cve_ids(file_path)
print("\n".join(cve_ids))到此這篇關(guān)于docker通過(guò)sbom獲取組件版本和漏洞編號(hào)的方法的文章就介紹到這了,更多相關(guān)docker sbom獲取組件版本和漏洞內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
k8s和Docker關(guān)系簡(jiǎn)單說(shuō)明
這篇文章主要介紹了k8s和Docker關(guān)系簡(jiǎn)單說(shuō)明,本文利于圖文講解的很透徹,有需要的同學(xué)可以研究下2021-03-03
Windows安裝docker-desktop的詳細(xì)步驟
這篇文章主要介紹了Windows安裝docker-desktop的詳細(xì)步驟,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-03-03
利用Docker搭建Nexus私有倉(cāng)庫(kù)實(shí)現(xiàn)Maven私服
Maven大家應(yīng)該都比較熟了,我這里就用安卓人狂喜的Gradle來(lái)演示一下,在build.gradle中編寫(xiě)腳本即可上傳,接下來(lái)通過(guò)本文給大家介紹下利用Docker搭建Nexus私有倉(cāng)庫(kù)實(shí)現(xiàn)Maven私服的問(wèn)題,感興趣的朋友一起看看吧2022-01-01
使用Golang玩轉(zhuǎn)Docker API的實(shí)踐
這篇文章主要介紹了使用Golang玩轉(zhuǎn)Docker API的實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
局域網(wǎng)內(nèi)部署 Docker Registry(推薦)
本文將從創(chuàng)建單機(jī)的 Docker Registry 開(kāi)始,逐步完成局域網(wǎng)內(nèi)可用的 Docker Registry 的創(chuàng)建,并重點(diǎn)解釋如何使用 IP 地址訪問(wèn) Registry 的方法2017-05-05

