【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))
相关推荐
爱宇阳11 分钟前
离线环境下运行 Docker 容器编排指南
docker·容器·eureka
蜜蜜不吃糖25 分钟前
解决Vcenter告警datastore存储容量不足问题
linux·运维·服务器
东城绝神33 分钟前
《Linux运维总结:基于ARM64+X86_64架构CPU使用docker-compose一键离线部署redis 7.4.5容器版分片集群》
linux·运维·redis·架构·分片集群
Java陈序员1 小时前
免费开源!一款操作 MySQL 和 MariaDB 的 Web 界面工具!
mysql·docker·php·mariadb
迷路爸爸1801 小时前
解决GitHub SSH密钥冲突:一台电脑多账户配置
运维·ssh·github
梁正雄2 小时前
9、dockerfile
docker·dockerfile·dockerfile基础用法
panplan.top2 小时前
Tornado + Motor 微服务架构(Docker + 测试 + Kubernetes)
linux·python·docker·微服务·k8s·tornado
newxtc2 小时前
【浙江政务服务网-注册_登录安全分析报告】
运维·selenium·安全·政务
FJW0208142 小时前
【Linux】系统中的文件管理
linux·运维·服务器
豆是浪个2 小时前
Linux(Centos 7.6)命令详解:rpm
linux·运维·centos