【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))
相关推荐
洪晓露10 分钟前
将 rke2 集群证书延长至 10 年
运维·服务器·数据库
谢平康28 分钟前
解决用 rm 报bash: /usr/bin/rm: Argument list too long错
linux·运维·运维开发
IP老炮不瞎唠36 分钟前
Python 价格监控如何实现?思路与实用方法分享
运维·服务器·网络
GIS数据转换器39 分钟前
城市排水生命线安全运行监测平台深度解析
java·运维·人工智能·python·安全·数据挖掘·无人机
Tokai_Teio_11 小时前
第四届黄河流域 misc
运维·服务器
hj2862512 小时前
Linux 网络服务综合笔记(概念 + 命令 + 实操案例)2
linux·运维·网络
what_20182 小时前
Linux 磁盘 (查看、划分、inode)
linux·运维·服务器
ManageEngine卓豪2 小时前
从性能故障到安全风险,现代企业数字化转型下的网络丢包运维管控指南
运维·网络安全·网络故障·网络丢包
ai产品老杨3 小时前
架构师深剖:基于 Docker 容器化与边缘计算的 AI 视频管理平台——支持 GB28181/RTSP 多协议接入与全源码交付
人工智能·docker·边缘计算
Urbano3 小时前
工装 T 恤、Polo 衫全生产工序、痛点解析及多品牌自动化设备应用方案
运维·自动化