【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))
相关推荐
shandianchengzi6 小时前
【记录】Tailscale|部署 Tailscale 到 linux 主机或 Docker 上
linux·运维·docker·tailscale
John Song6 小时前
Linux机器怎么查看进程内存占用情况
linux·运维·chrome
肉肉心很软7 小时前
使用onlyoffice实现文件预览编辑 + Docker一键部署流程
运维·docker·容器
-大头.7 小时前
Docker实战:构建高性能MySQL主从复制集群(读写分离)
mysql·docker·容器
LuiChun7 小时前
Docker Compose 容器服务查询与文件查看操作指南(Windows Docker Desktop 版)【一】
linux·运维·windows·docker·容器
${王小剑}8 小时前
在离线ubuntu上布置深度学习环境
linux·运维·ubuntu
Java程序之猿8 小时前
Linux使用U盘安装centos及报错You might want to saue “/run/initramfs/rdsosreport.txt“ 处理
linux·运维·服务器
goodlook01239 小时前
安装最新版本docker-26.1.4
运维·docker·容器
❀͜͡傀儡师9 小时前
docker安装部署PostgreSQL带有pgvector扩展向量数据(高维数组)
docker·postgresql·容器·pgvector
CC.GG9 小时前
【Linux】进程概念(五)(虚拟地址空间----建立宏观认知)
java·linux·运维