【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))
相关推荐
2603_965148112 分钟前
终极清单:构建自动化选品比价系统的所有组件与资源
大数据·运维·数据库·数据挖掘·自动化
北城笑笑3 分钟前
Server 18 ,Nginx 双服务器 HTTP转HTTPS 代理实战( HTTP 地址换 HTTPS 域名 )
运维·服务器·前端·后端·nginx·http·https
程序员-Benothing5 分钟前
Linux磁盘IO性能分析:iostat、iotop、fio实战
linux·运维·服务器
十二同学啊6 分钟前
Docker 容器化技术详解:镜像、容器、网络与应用部署设计
网络·docker·eureka
I'mChloe11 分钟前
不再逐台装Docker:我用Ansible Playbook批量统一服务器环境
服务器·docker·ansible
LiaoWL12317 分钟前
从零开始学 Linux(一):目录结构、常用命令与 VIM 编辑器上手
linux·运维·服务器
分布式存储与RustFS28 分钟前
RustFS 上生产第一步:从单机到 4 节点多盘集群(MNMD)部署实操
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
江湖有缘34 分钟前
Docker实战 | 使用Docker部署Readeck书签管理工具
java·docker·eureka
极小狐1 小时前
MR 里测试摘要空白、覆盖率不显示?JUnit 与覆盖率配置 9 步排查
数据库·ci/cd·junit·单元测试·mr·devops·代码覆盖率
小白鸽i1 小时前
【Linux】已安装的软件如何重新构建deb安装包?
linux·运维·服务器