【DevOps】docker 通过 sbom 获取组件版本和漏洞编号

最近做 SCA 测试,需要获取镜像的组件和漏洞,使用 docker scout 工具,通过 sbom 获取组件名称、版本和漏洞编号。

docker scout

获取组件信息

bash 复制代码
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 编号

bash 复制代码
docker scout cves --format sbom nginx:stable-perl > sbom.cve.json

按行输出 CVE 编号

python 复制代码
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))
相关推荐
Azure DevOps1 分钟前
Azure DevOps Server:使用FTP工具上传文件
运维·microsoft·azure·devops
qq_5024289909 分钟前
如何搭建战神冰雪传奇手游 从零开始学习游戏架设,玩转云服务器,如何利用云服务器搭建一款属于自己的传奇手游
运维·服务器
我言秋日胜春朝★40 分钟前
【Linux网络编程】守护进程
linux·运维·服务器
Mikhail_G1 小时前
Python初学者入门指南
大数据·运维·开发语言·python·数据分析
wanhengidc2 小时前
高性能计算服务器的主要作用都有哪些?
运维·服务器
IT 前端 张2 小时前
搭建Node.js服务器
运维·服务器·node.js
pp-周子晗(努力赶上课程进度版)2 小时前
【项目】仿muduo库one thread one loop式并发服务器前置知识准备
运维·服务器
就叫飞六吧2 小时前
VMware安装Ubuntu并实现root远程登录
linux·运维·ubuntu
陈哥聊测试2 小时前
将安全融入软件开发的每一步 | DevSecOps
安全·devops
微信公众号:AI创造财富4 小时前
run docker 失败解决办法
python·docker