docker通過sbom獲取組件版本和漏洞編號的方法
最近做 SCA 測試,需要獲取鏡像的組件和漏洞,使用 docker scout 工具,通過 sbom 獲取組件名稱、版本和漏洞編號。
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 編號

docker scout cves --format sbom nginx:stable-perl > sbom.cve.json
按行輸出 CVE 編號
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通過sbom獲取組件版本和漏洞編號的方法的文章就介紹到這了,更多相關(guān)docker sbom獲取組件版本和漏洞內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Docker?Compose資源配額管理實現(xiàn)限制容器CPU與內(nèi)存使用
在容器化部署中,資源競爭是最常見的穩(wěn)定性隱患,當一個服務異常占用CPU或內(nèi)存時,可能導致整個應用集群異常,本文將系統(tǒng)講解Docker?Compose的資源配額管理方案,感興趣的可以了解一下2026-04-04
Docker中處理持久化存儲(如數(shù)據(jù)庫)的方法詳解
在使用Docker容器時,容器的生命周期通常是短暫的,當容器被刪除后,其內(nèi)部的數(shù)據(jù)也會隨之丟失,然而,對于像數(shù)據(jù)庫這樣需要持久化存儲數(shù)據(jù)的應用來說,這是不可接受的,所以本文給大家介紹了Docker中處理持久化存儲(如數(shù)據(jù)庫)的方法,需要的朋友可以參考下2025-06-06
docker環(huán)境變量配置不生效/ect/profile的解決方法
docker在使用過程中,有時候自定義容器實例中的某些配置文件,本文主要介紹了docker環(huán)境變量配置不生效/ect/profile的解決方法,感興趣的可以了解一下2023-08-08
一文教你如何通過 Docker 快速搭建各種測試環(huán)境
這篇文章主要介紹了一文教你如何通過 Docker 快速搭建各種測試環(huán)境,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07

