当前位置:   article > 正文

容器镜像安全漏洞扫描-Trivy_镜像安全扫描

镜像安全扫描

一、Trivy 概述

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

Trivy 检测两种类型的安全问题 :

  • 漏洞

  • 配置错误

Trivy 可以扫描三种不同的工件:

  • 容器镜像

  • 文件系统

  • Git存储库

Trivy 可以在两种不同的模式下运行:

  • 独立

  • 客户端服务器

它旨在用于 CI。在推送到容器注册表或部署应用程序之前,您可以轻松扫描本地容器映像和其他工件。

二、Trivy 特征

  • 全面的漏洞检测

    • 操作系统包(Alpine、Red Hat Universal Base Image、Red Hat Enterprise Linux、CentOS、Oracle Linux、Debian、Ubuntu、Amazon Linux、openSUSE Leap、SUSE Enterprise Linux、Photon OS 和 Distroless)

    • 特定于语言的包(Bundler、Composer、Pipenv、Poetry、npm、yarn、Cargo、NuGet、Maven 和 Go)

  • 检测 IaC 错误配置

    • Kubernetes

    • 码头工人

    • 地形

    • 更多即将推出

    • 各种各样的内置策略提供了开箱:

    • 支持自定义策略

  • 简单的

    • 仅指定图像名称、包含 IaC 配置的目录或工件名称

  • 快速地

    • 第一次扫描将在 10 秒内完成(取决于您的网络)。随后的扫描将在几秒钟内完成。

    • 与在第一次运行时需要很长时间才能获取漏洞信息(约 10 分钟)并鼓励您维护持久漏洞数据库的其他扫描程序不同,Trivy 是无状态的,不需要维护或准备。

  • 简易安装

    • apt-get install,yum install并且brew install是可能的

    • 没有先决条件,如安装DB的,图书馆等

  • 高精确度

    • 特别是 Alpine Linux 和 RHEL/CentOS

    • 其他操作系统也高

  • 开发安全运营

    • 适用于Travis CI、CircleCI、Jenkins、GitLab CI 等 CI。

  • 支持多种格式

    • 作为守护进程运行的 Docker Engine 中的本地映像

    • Podman中暴露套接字的本地图像

    • Docker Registry 中的远程镜像,例如 Docker Hub、ECR、GCR 和 ACR

    • 存储在docker save/podman save格式文件中的 tar 存档

    • 符合OCI 图像格式的图像目录

    • 容器镜像

    • 本地文件系统

    • 远程 git 仓库

三、Trivy 安装

3.1 Yum 源方式安装

  1. $ sudo vim /etc/yum.repos.d/trivy.repo
  2. [trivy]
  3. name=Trivy repository
  4. baseurl=https://aquasecurity.github.io/trivy-repo/rpm/releases/$releasever/$basearch/
  5. gpgcheck=0
  6. enabled=1
  7. $ sudo yum -y update
  8. $ sudo yum -y install trivy

3.2 rpm 方式安装

rpm -ivh https://github.com/aquasecurity/trivy/releases/download/v0.19.2/trivy_0.19.2_Linux-64bit.rpm

3.3 二进制方式安装

  1. mkdir -p $GOPATH/src/github.com/aquasecurity
  2. cd $GOPATH/src/github.com/aquasecurity
  3. git clone --depth 1 --branch v0.19.2 https://github.com/aquasecurity/trivy
  4. cd trivy/cmd/trivy/
  5. export GO111MODULE=on
  6. go install

四、容器镜像漏洞扫描

只需指定镜像仓库(和tag)

  1. # trivy image nginx:1.16
  2. 2021-08-16T19:15:48.528+0800 INFO Detected OS: debian
  3. 2021-08-16T19:15:48.528+0800 INFO Detecting Debian vulnerabilities...
  4. 2021-08-16T19:15:48.541+0800 INFO Number of language-specific files: 1
  5. nginx:1.16 (debian 10.3)
  6. ========================
  7. Total: 207 (UNKNOWN: 0, LOW: 105, MEDIUM: 33, HIGH: 49, CRITICAL: 20)
  8. +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+
  9. | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE |
  10. +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+
  11. | apt | CVE-2020-27350 | MEDIUM | 1.8.2 | 1.8.2.2 | apt: integer overflows and underflows |
  12. | | | | | | while parsing .deb packages |
  13. | | | | | | -->avd.aquasec.com/nvd/cve-2020-27350 |
  14. + +---------------------+ + +---------------------------+------------------------------------------------------------+
  15. | | CVE-2020-3810 | | | 1.8.2.1 | Missing input validation in |
  16. | | | | | | the ar/tar implementations of |
  17. | | | | | | APT before version 2.1.2... |
  18. | | | | | | -->avd.aquasec.com/nvd/cve-2020-3810 |
  19. + +---------------------+----------+ +---------------------------+------------------------------------------------------------+
  20. | | CVE-2011-3374 | LOW | | | It was found that apt-key in apt, |
  21. | | | | | | all versions, do not correctly... |
  22. | | | | | | -->avd.aquasec.com/nvd/cve-2011-3374 |
  23. +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+
  24. | bash | CVE-2019-18276 | | 5.0-4 | | bash: when effective UID is not |
  25. | | | | | | equal to its real UID the... |
  26. | | | | | | -->avd.aquasec.com/nvd/cve-2019-18276 |
  27. + +---------------------+ + +---------------------------+------------------------------------------------------------+
  28. | | TEMP-0841856-B18BAF | | | | -->security-tracker.debian.org/tracker/TEMP-0841856-B18BAF |
  29. +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+
  30. | bsdutils | CVE-2021-37600 | | 2.33.1-0.1 | | util-linux: integer overflow |
  31. | | | | | | can lead to buffer overflow |
  32. | | | | | | in get_sem_elements() in |
  33. | | | | | | sys-utils/ipcutils.c... |
  34. | | | | | | -->avd.aquasec.com/nvd/cve-2021-37600 |
  35. +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+
  36. | coreutils | CVE-2016-2781 | | 8.30-3 | | coreutils: Non-privileged |
  37. | | | | | | session can escape to the |
  38. | | | | | | parent session in chroot |
  39. | | | | | | -->avd.aquasec.com/nvd/cve-2016-2781 |
  40. + +---------------------+ + +---------------------------+------------------------------------------------------------+
  41. | | CVE-2017-18018 | | | | coreutils: race condition |
  42. | | | | | | vulnerability in chown and chgrp |
  43. | | | | | | -->avd.aquasec.com/nvd/cve-2017-18018 |
  44. +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+
  45. | fdisk | CVE-2021-37600 | | 2.33.1-0.1 | | util-linux: integer overflow |
  46. | | | | | | can lead to buffer overflow |
  47. | | | | | | in get_sem_elements() in |
  48. | | | | | | sys-utils/ipcutils.c... |
  49. | | | | | | -->avd.aquasec.com/nvd/cve-2021-37600 |
  50. +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+
  51. | gcc-8-base | CVE-2018-12886 | HIGH | 8.3.0-6 | | gcc: spilling of stack |
  52. | | | | | | protection address in cfgexpand.c |
  53. | | | | | | and function.c leads to... |
  54. | | | | | | -->avd.aquasec.com/nvd/cve-2018-12886 |
  55. + +---------------------+ + +---------------------------+------------------------------------------------------------+
  56. | | CVE-2019-15847 | | | | gcc: POWER9 "DARN" RNG intrinsic |
  57. | | | | | | produces repeated output |
  58. | | | | | | -->avd.aquasec.com/nvd/cve-2019-15847 |
  59. +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+
  60. | gpgv | CVE-2019-14855 | LOW | 2.2.12-1+deb10u1 | | gnupg2: OpenPGP Key Certification |
  61. | | | | | | Forgeries with SHA-1 |
  62. | | | | | | -->avd.aquasec.com/nvd/cve-2019-14855 |
  63. +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+
  64. | libapt-pkg5.0 | CVE-2020-27350 | MEDIUM | 1.8.2 | 1.8.2.2 | apt: integer overflows and underflows |
  65. | | | | | | while parsing .deb packages |
  66. | | | | | | -->avd.aquasec.com/nvd/cve-2020-27350 |
  67. + +---------------------+ + +---------------------------+------------------------------------------------------------+
  68. | | CVE-2020-3810 | | | 1.8.2.1 | Missing input validation in |
  69. | | | | | | the ar/tar implementations of |
  70. | | | | | | APT before version 2.1.2... |
  71. --More--

trivy image  [IMAGE_NAME]

漏洞等级:

  • HIGH

  • MEDIUM

  • LOW

  • CRITICAL

五、文件系统漏洞扫描

扫描文件系统(例如主机、虚拟机映像或解压缩的容器映像文件系统)

  1. # trivy fs /application/zookeeper/
  2. 2021-08-16T19:23:19.322+0800 INFO Number of language-specific files: 35
  3. 2021-08-16T19:23:19.322+0800 INFO Detecting jar vulnerabilities...
  4. lib/jetty-server-9.4.39.v20210325.jar (jar)
  5. ===========================================
  6. Total: 2 (UNKNOWN: 0, LOW: 1, MEDIUM: 1, HIGH: 0, CRITICAL: 0)
  7. +--------------------------------+------------------+----------+-------------------+------------------------+---------------------------------------+
  8. | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE |
  9. +--------------------------------+------------------+----------+-------------------+------------------------+---------------------------------------+
  10. | org.eclipse.jetty:jetty-server | CVE-2019-10247 | MEDIUM | 9.4.39.v20210325 | | jetty: error path |
  11. | | | | | | information disclosure |
  12. | | | | | | -->avd.aquasec.com/nvd/cve-2019-10247 |
  13. + +------------------+----------+ +------------------------+---------------------------------------+
  14. | | CVE-2021-34428 | LOW | | 11.0.3, 10.0.3, 9.4.41 | jetty: SessionListener can |
  15. | | | | | | prevent a session from being |
  16. | | | | | | invalidated breaking logout |
  17. | | | | | | -->avd.aquasec.com/nvd/cve-2021-34428 |
  18. +--------------------------------+------------------+----------+-------------------+------------------------+---------------------------------------+
  19. lib/log4j-1.2.17.jar (jar)
  20. ==========================
  21. Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 0, CRITICAL: 1)
  22. +-------------+------------------+----------+-------------------+---------------+---------------------------------------+
  23. | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE |
  24. +-------------+------------------+----------+-------------------+---------------+---------------------------------------+
  25. | log4j:log4j | CVE-2019-17571 | CRITICAL | 1.2.17 | | log4j: deserialization of |
  26. | | | | | | untrusted data in SocketServer |
  27. | | | | | | -->avd.aquasec.com/nvd/cve-2019-17571 |
  28. +-------------+------------------+----------+-------------------+---------------+---------------------------------------+

六、Git 存储库漏洞扫描

扫描您的远程 git 存储库

  1. # trivy repo https://github.com/kubernetes/kubernetes.git
  2. Enumerating objects: 370096, done.
  3. Counting objects: 100% (370096/370096), done.
  4. Compressing objects: 100% (153736/153736), done.
  5. Total 370096 (delta 246795), reused 313878 (delta 202418), pack-reused 0
  6. 2021-08-16T19:27:54.433+0800 INFO Number of language-specific files: 31
  7. 2021-08-16T19:27:54.434+0800 INFO Detecting gomod vulnerabilities...
  8. cluster/addons/fluentd-elasticsearch/es-image/go.sum (gomod)
  9. ============================================================
  10. Total: 4 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 3, CRITICAL: 0)
  11. +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+
  12. | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE |
  13. +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+
  14. | github.com/dgrijalva/jwt-go | CVE-2020-26160 | HIGH | 3.2.0+incompatible | | jwt-go: access restriction |
  15. | | | | | | bypass vulnerability |
  16. | | | | | | -->avd.aquasec.com/nvd/cve-2020-26160 |
  17. +-----------------------------+------------------+ +-----------------------------------+------------------------------------+---------------------------------------+
  18. | github.com/gogo/protobuf | CVE-2021-3121 | | 1.3.1 | v1.3.2 | gogo/protobuf: |
  19. | | | | | | plugin/unmarshal/unmarshal.go |
  20. | | | | | | lacks certain index validation |
  21. | | | | | | -->avd.aquasec.com/nvd/cve-2021-3121 |
  22. +-----------------------------+------------------+ +-----------------------------------+------------------------------------+---------------------------------------+
  23. | golang.org/x/crypto | CVE-2020-29652 | | 0.0.0-20200622213623-75b288015ac9 | v0.0.0-20201216223049-8b5274cf687f | golang: crypto/ssh: crafted |
  24. | | | | | | authentication request can |
  25. | | | | | | lead to nil pointer dereference |
  26. | | | | | | -->avd.aquasec.com/nvd/cve-2020-29652 |
  27. +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+
  28. | k8s.io/client-go | CVE-2020-8565 | MEDIUM | 0.19.2 | v0.20.0-alpha.2 | kubernetes: Incomplete fix |
  29. | | | | | | for CVE-2019-11250 allows for |
  30. | | | | | | token leak in logs when... |
  31. | | | | | | -->avd.aquasec.com/nvd/cve-2020-8565 |
  32. +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+
  33. go.sum (gomod)
  34. ==============
  35. Total: 2 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 1, CRITICAL: 0)

七、Trivy 过滤漏洞

7.1 隐藏未修复得漏洞

默认情况下, Trivy还会检测未修补/未修复的漏洞。这意味着即使您更新所有软件包,您也无法修复这些漏洞。如果您想忽略它们,请使用该--ignore-unfixed选项。

# trivy image --ignore-unfixed nginx:1.16 

7.2 按严重程度

使用--severity选项

# trivy image --severity HIGH,CRITICAL  nginx:1.16

7.3 按漏洞ID

使用.trivyignore.

  1. # cat .trivyignore
  2. Accept the risk
  3. CVE-2018-14618
  4. No impact in our settings
  5. CVE-2019-1543
  6. # trivy image  nginx:1.16 

7.4 按类型

使用--vuln-type选项。

# trivy image --vuln-type os  nginx:1.16

八、漏洞数据库

8.1 跳过漏洞数据库得更新

Trivy开始运行时每 12 小时下载一次漏洞数据库。这通常很快,因为数据库的大小只有 10~30MB。但是,如果您甚至想跳过它,请使用该--skip-db-update选项。

# trivy image --skip-db-update nginx:1.16

8.2 只下载漏洞数据库

# trivy image --download-db-only

8.3 轻量级数据库

轻量级数据库不包含漏洞详细信息,例如描述和参考。因此,DB 的大小更小,下载速度更快。

当您不需要漏洞详细信息并且适用于 CI/CD 时,此选项很有用。要查找其他信息,您可以在 NVD 网站上搜索漏洞详细信息。https://nvd.nist.gov/vuln/search

# trivy image --light nginx:1.16

--light 选项不会像下面的例子那样显示标题。

九、Trivy 缓存

9.1 清除缓存

--clear-cache选项删除缓存。

9.2 不执行扫描

# trivy image --clear-cache

9.3 缓存目录

用 指定缓存的存储位置--cache-dir

$ trivy --cache-dir /tmp/trivy/ image nginx:1.16

9.4 缓存后端

Trivy 支持本地文件系统和 Redis 作为缓存后端。此选项特别适用于客户端/服务器模式。

两个选项:- fs - 缓存路径可以通过--cache-dir - redis:// -redis://[HOST]:[PORT]

# trivy server --cache-backend redis://localhost:6379

十、Trivy 漏洞报告格式

10.1 表格(默认)

 # trivy image -f table nginx:1.16

10.2 JSON

trivy image -f json -o results.json nginx:1.16

参考文章:https://github.com/aquasecurity/trivy

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/780711
推荐阅读
相关标签
  

闽ICP备14008679号