【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))
相关推荐
kjl5365661 小时前
docker命令
运维·docker·容器
野熊佩骑2 小时前
CentOS7二进制安装包方式部署K8S集群之ETCD集群部署
运维·数据库·云原生·容器·kubernetes·centos·etcd
小白银子5 小时前
零基础从头教学Linux(Day 45)
linux·运维·junit·openresty
半梦半醒*7 小时前
nginx反向代理和负载均衡
linux·运维·nginx·centos·tomcat·负载均衡
喜欢你,还有大家7 小时前
集群的概述和分类和负载均衡集群
运维·负载均衡
liu****7 小时前
负载均衡式的在线OJ项目编写(六)
运维·c++·负载均衡·个人开发
Elastic 中国社区官方博客9 小时前
CI/CD 流水线与 agentic AI:如何创建自我纠正的 monorepos
大数据·运维·数据库·人工智能·搜索引擎·ci/cd·全文检索
Insist7539 小时前
基于OpenEuler--docker容器化部署ceph集群
ceph·docker·容器
A-刘晨阳9 小时前
Linux安装centos8及基础配置
linux·运维·服务器·操作系统·centos8
恒雨田9 小时前
解决 jenkins 用户 SSH 连接目标服务器时的 Permission denied 问题
运维·ssh·jenkins