ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

镜像扫描工具预研

2022-06-12 12:32:28  阅读:155  来源: 互联网

标签:扫描 漏洞 开源 https 镜像 预研 debian


镜像扫描工具预研

1、背景

​ 最近给了个任务,准备接入容器镜像的漏洞扫描工具,于是需要先预研,看看接入哪一种开源工具。因为在镜像的构建过程中,镜像封装的代码、软件会有不同程度的缺陷,这些缺陷一旦被恶意的者利用,入侵到内部系统进行一系列非法的操作(破坏系统的正常运行和窃取私密的信息)。当缺陷成为漏洞,将会对镜像的安全造成很大的隐患。

2、目的

​ 寻找能够支持商用的开源扫描镜像漏洞的工具。

3、开源协议简介

​ 开源工具一般都会遵循一定的开源协议,哪些协议能够商用,哪些不能商用,在开源协议中都有一定的说明,故先对协议做一定的说明。

Apache License 2.0 :商业软件最爱, 主要条件是要求保留原始版权和许可声明。同时向贡献者明确授予专利权。使用者可以自由修改,进行商业使用,大型项目可以不同的条款分发,没有开源要求,修改源代码需要记录变更。

BSD 3-Clause "New" or "Revised" license:允许商业发布和销售。使用者可以自由的使用,修改源代码,也可以将修改后的代码作为开源或者专有软件再发布。主要条件是要求尊重代码作者的著作权,即包含原始版权和免责声明(二进制形式分发必须分发文档中包含版权申明及免责声明),且未经事先特别书面许可,不可以用开源代码的“作者/机构的名字”或“原来产品的名字”做市场推广。

BSD 2-Clause "Simplified" or "FreeBSD" license:比3-Clause少一个条目,去掉了“不可以用开源代码的“作者/机构的名字”或“原来产品的名字”做市场推广。”.

GNU General Public License: 商业软件绕开,GPL不允许修改后和衍生的代码做为闭源的商业软件发布和销售。

GNU Library or "Lesser" General Public License (LGPL):允许商业软件代码动态link到LGPL类库。注意:不可以静态链接,否则你的代码也必须用LGPL协议开源。(即:商业软件可以动态使用,但不能修改)

Mozilla Public License 2.0:修改的版本需要保持原始版权申明。编译版本需和可获得MPL协议下的源码。修改源代码需要记录变更。

Common Development and Distribution License:商业软件可用,也可以修改。可以自行发布许可,允许公共版权使用,提供专利保护,无专利费

Eclipse Public License version 2.0:商业软件可用,也可以修改,无需开源。不过将本程序包含在商业产品中的贡献者需要承担因代码而产生的侵权责任,及对所有其他贡献者的相关损失

image-20220520151252847

4、开源镜像扫描工具

4.1、Trivy 扫描器

image-20220520145911660

4.1.1、简介

官网:https://aquasecurity.github.io/trivy/v0.28.0/

github:https://github.com/aquasecurity/trivy

Trivy(tri 发音为 trigger,vy 发音为 envy)是一个简单而全面的漏洞/错误配置扫描器,用于容器和其他工件。 软件漏洞是软件或操作系统中存在的故障、缺陷或弱点。 Trivy 检测操作系统包(Alpine、RHEL、CentOS 等)和特定语言包(Bundler、Composer、npm、yarn 等)的漏洞。 此外,Trivy 会扫描基础设施即代码 (IaC) 文件,例如 Terraform 和 Kubernetes,以检测使您的部署面临攻击风险的潜在配置问题。 Trivy 易于使用。 只需安装二进制文件,您就可以开始扫描了。 扫描所需要做的就是指定一个目标,例如容器的图像名称。

4.1.2、使用协议/语言

Apache License Version 2.0/Golang

4.1.3、扫描类型

1、Container Images:容器镜像
2、Filesystem and Rootfs:文件系统/根文件系统
3、Git Repositories:代码仓库
4、Kubernetes:集群中使用到的镜像/配置

4.1.4、使用

1、安装trivy应用即可

2、不需要另外安装数据库

3、每次扫描前都会下载最新的CVE漏洞库

4.1.5、扫描镜像及扫描结果

扫描镜像:

# trivy image -f json -o results.json nginx:latest

扫描结果:

"Results": [
    {
      "Target": "nginx:latest (debian 10.10)",
      "Class": "os-pkgs",
      "Type": "debian",
      "Vulnerabilities": [
        {
          "VulnerabilityID": "CVE-2011-3374",
          "PkgName": "apt",
          "InstalledVersion": "1.8.2.3",
          "Layer": {
            "DiffID": "sha256:764055ebc9a7a290b64d17cf9ea550f1099c202d83795aa967428ebdf335c9f7"
          },
          "SeveritySource": "debian",
          "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2011-3374",
          "DataSource": {
            "ID": "debian",
            "Name": "Debian Security Tracker",
            "URL": "https://salsa.debian.org/security-tracker-team/security-tracker"
          },
          "Title": "It was found that apt-key in apt, all versions, do not correctly valid ...",
          "Description": "It was found that apt-key in apt, all versions, do not correctly validate gpg keys with the master keyring, leading to a potential man-in-the-middle attack.",
          "Severity": "LOW",
          "CweIDs": [
            "CWE-347"
          ],
          "CVSS": {
            "nvd": {
              "V2Vector": "AV:N/AC:M/Au:N/C:N/I:P/A:N",
              "V3Vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:N",
              "V2Score": 4.3,
              "V3Score": 3.7
            }
          },
          "References": [
            "https://access.redhat.com/security/cve/cve-2011-3374",
            "https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=642480",
            "https://people.canonical.com/~ubuntu-security/cve/2011/CVE-2011-3374.html",
            "https://seclists.org/fulldisclosure/2011/Sep/221",
            "https://security-tracker.debian.org/tracker/CVE-2011-3374",
            "https://snyk.io/vuln/SNYK-LINUX-APT-116518",
            "https://ubuntu.com/security/CVE-2011-3374"
          ],
          "PublishedDate": "2019-11-26T00:15:00Z",
          "LastModifiedDate": "2021-02-09T16:08:00Z"
        }]}]

4.1.6 优/劣势

​ 优势:工具功能专一,仅提供扫描漏洞功能,而且能扫描文件、代码仓库、k8s集群使用到的镜像等。并不提供其它功能。

4.2、anchore

4.2.1 简介

官网:https://engine.anchore.io/docs/general/

github:https://github.com/anchore/anchore-engine

​ Anchore Engine 是一种开源扫描工具,用于评估 Docker 镜像的安全性。Anchore 报告让您深入了解过时的包版本和依赖项中的潜在漏洞。

4.2.2 使用协议/语言

Apache License Version 2.0/Python

4.2.3 扫描类型

  • Image metadata
  • Image layers
  • Operating System Package Data (RPM, DEB, APKG)
  • File Data
  • Ruby Gems
  • Node.JS NPMs
  • Java Archives
  • Python Packages
  • .NET NuGet Packages
  • File content

4.2.4 使用

1、以往只能安装Anchore Engine,运行Anchore Engine、db实例,再使用CLI进行镜像注册,扫描、获取访问结果等交互

2、也可以使用后来的内联扫描方式,下载脚本,由脚本进行配置数据库、注册表功能,使用脚本进行直接扫描(未成功)。

3、扫描前需要启动db实例,db中postsq;,maridb有已知的漏洞库数据。

4.2.5 扫描镜像及结果

​ 使用Anchore Cli 操作Docker Compose进行镜像的添加、扫描,获取扫描结果

# 添加到Docker Compose注册表
# docker-compose exec api anchore-cli image add docker.io/library/debian:7
# 等待Docker Compose进行镜像分析完成
# docker-compose exec api anchore-cli image wait docker.io/library/debian:7
# 获取镜像扫描结果
# docker-compose exec api anchore-cli --json image vuln docker.io/library/debian:7 all

扫描结果Json:

{
    "imageDigest": "sha256:b495f952df67472c3598b260f4b2e2ba9b5a8b0af837575cf4369c95c8d8a215",
    "vulnerabilities": [
        {
            "feed": "vulnerabilities",
            "feed_group": "debian:11",
            "fix": "None",
            "nvd_data": [
                {
                    "cvss_v2": {
                        "base_score": 1.9,
                        "exploitability_score": 3.4,
                        "impact_score": 2.9
                    },
                    "cvss_v3": {
                        "base_score": 4.7,
                        "exploitability_score": 1.0,
                        "impact_score": 3.6
                    },
                    "id": "CVE-2017-14159"
                }
            ],
            "package": "libldap-2.4-2-2.4.57+dfsg-3",
            "package_cpe": "None",
            "package_cpe23": "None",
            "package_name": "libldap-2.4-2",
            "package_path": "pkgdb",
            "package_type": "dpkg",
            "package_version": "2.4.57+dfsg-3",
            "severity": "Negligible",
            "url": "https://security-tracker.debian.org/tracker/CVE-2017-14159",
            "vendor_data": [],
            "vuln": "CVE-2017-14159",
            "will_not_fix": false
        }]
}

4.2.6 优/劣势

​ 劣势:可以通过cli或者api调用。但是每次扫描前需要先将镜像添加到Docker Compose中进行分析,等待分析好了才能获取扫描结果。

4.3、Clair

4.3.1 简介

官网:https://www.redhat.com/en/topics/containers/what-is-clair

github:https://github.com/quay/quay

Clair 是一个开源项目,它提供了一个通过对 appc 和 docker 容器中的漏洞进行静态分析来监控容器安全性的工具。Clair 采用 API 驱动的分析引擎,可以逐层检查容器中是否存在已知的安全漏洞。利用 Clair,您可以轻松构建服务,对容器漏洞进行持续监控

4.2.2 使用协议/语言

Apache License Version 2.0/Python

4.2.3 扫描类型

​ 支持以下类型的关方容器镜像

  • Ubuntu
  • Debian
  • RHEL
  • Suse
  • Oracle
  • Alpine
  • AWS Linux
  • VMWare Photon
  • Python

4.2.4 使用

​ 参考集成了clair的工具进行安装使用

https://github.com/arminc/clair-scanner/tree/v13

https://www.elephdev.com/index.php/cDocker/301.html?ref=addtabs&lang=en

1、下载集成了clair的客户端工具

2、启动clair-local-scan扫描镜像

3、安装clair-db,下载漏洞库

4.2.5 扫描镜像及结果

# clair-scanner -r php-report.json --ip 172.17.0.1 php:7.2

扫描结果Json:

{
    "image": "php:7.2",
    "vulnerabilities": [
        {
            "featurename": "linux",
            "featureversion": "4.19.160-2",
            "vulnerability": "CVE-2022-0435",
            "namespace": "debian:10",
            "description": "A stack overflow flaw was found in the Linux kernel's TIPC protocol functionality in the way a user sends a packet with malicious content where the number of domain member nodes is higher than the 64 allowed. This flaw allows a remote user to crash the system or possibly escalate their privileges if they have access to the TIPC network.",
            "link": "https://security-tracker.debian.org/tracker/CVE-2022-0435",
            "severity": "Critical",
            "fixedby": "4.19.232-1"
        },
        {
            "featurename": "openssl",
            "featureversion": "1.1.1d-0+deb10u4",
            "vulnerability": "CVE-2022-1292",
            "namespace": "debian:10",
            "description": "The c_rehash script does not properly sanitise shell metacharacters to prevent command injection. This script is distributed by some operating systems in a manner where it is automatically executed. On such operating systems, an attacker could execute arbitrary commands with the privileges of the script. Use of the c_rehash script is considered obsolete and should be replaced by the OpenSSL rehash command line tool. Fixed in OpenSSL 3.0.3 (Affected 3.0.0,3.0.1,3.0.2). Fixed in OpenSSL 1.1.1o (Affected 1.1.1-1.1.1n). Fixed in OpenSSL 1.0.2ze (Affected 1.0.2-1.0.2zd).",
            "link": "https://security-tracker.debian.org/tracker/CVE-2022-1292",
            "severity": "Critical",
            "fixedby": "1.1.1n-0+deb10u2"
        }]
}

4.2.6 优/劣势

​ 劣势:针对官方文档进行操作,有许多卡点,参考了已集成了clair的开源工具进行测试,可以直接扫描指定镜像。

5、扫描能力比对

image-20220526100955131

6、总结

AnchoreClair相比较Trivy出现的时间更早,但是扫描的结果发现Trivy能发现更多的漏洞,尤其是对alphine镜像;现在大部分镜像的基础镜像都会选择alpine,因为它更加轻量级而且漏洞相对较少

​ 而AnchoreClair对一些alpine镜像是扫描不出来漏洞的,但是使用Trivy却能够找到;之前部署的Harbor版本使用的扫描器是Clair,扫描alphine镜像之后没有发现漏洞,就认为是安全的;现在Harbor2.0之后是使用Trivy作为默认扫描器,对一些alphine就能够扫描出来漏洞了

Trivy相对于其他两个来说,安装更加的简单,使用也更加的方便;并且能够支持多种类型的文件的扫描,目前也是Harbor默认的扫描器

参考:

https://boxboat.com/2020/04/24/image-scanning-tech-compared/

https://www.a10o.net/devsecops/docker-image-security-static-analysis-tool-comparison-anchore-engine-vs-clair-vs-trivy/

标签:扫描,漏洞,开源,https,镜像,预研,debian
来源: https://www.cnblogs.com/process-h/p/16367756.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有