Trivy(tri 发音为 trigger,vy 发音为 envy)是一个简单而全面的漏洞/错误配置扫描器,用于容器和其他工件。 软件漏洞是软件或操作系统中存在的故障、缺陷或弱点。 Trivy 检测操作系统包(Alpine、RHEL、CentOS 等)和特定语言包(Bundler、Composer、npm、yarn 等)的漏洞。 此外,Trivy 会扫描基础设施即代码 (IaC) 文件,例如 Terraform 和 Kubernetes,以检测使您的部署面临攻击风险的潜在配置问题。 Trivy 易于使用。 只需安装二进制文件,您就可以开始扫描了。 扫描所需要做的就是指定一个目标,例如容器的图像名称。
Trivy 检测两种类型的安全问题 :
Trivy 可以扫描三种不同的工件:
Trivy 可以在两种不同的模式下运行:
它旨在用于 CI。在推送到容器注册表或部署应用程序之前,您可以轻松扫描本地容器映像和其他工件。
apt-get install
,yum install
并且brew install
是可能的docker save
/podman save
格式文件中的 tar 存档Yum 源方式安装
$ sudo vim /etc/yum.repos.d/trivy.repo [trivy] name=Trivy repository baseurl=https://aquasecurity.github.io/trivy-repo/rpm/releases/$releasever/$basearch/ gpgcheck=0 enabled=1 $ sudo yum -y update $ sudo yum -y install trivy
rpm 方式安装
rpm -ivh https://github.com/aquasecurity/trivy/releases/download/v0.19.2/trivy_0.19.2_Linux-64bit.rpm
二进制方式安装
mkdir -p $GOPATH/src/github.com/aquasecurity cd $GOPATH/src/github.com/aquasecurity git clone --depth 1 --branch v0.19.2 https://github.com/aquasecurity/trivy cd trivy/cmd/trivy/ export GO111MODULE=on go install
只需指定镜像仓库(和tag)
# trivy image nginx:1.16 2021-08-16T19:15:48.528+0800 INFO Detected OS: debian 2021-08-16T19:15:48.528+0800 INFO Detecting Debian vulnerabilities... 2021-08-16T19:15:48.541+0800 INFO Number of language-specific files: 1 nginx:1.16 (debian 10.3) ======================== Total: 207 (UNKNOWN: 0, LOW: 105, MEDIUM: 33, HIGH: 49, CRITICAL: 20) +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+ | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE | +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+ | apt | CVE-2020-27350 | MEDIUM | 1.8.2 | 1.8.2.2 | apt: integer overflows and underflows | | | | | | | while parsing .deb packages | | | | | | | -->avd.aquasec.com/nvd/cve-2020-27350 | + +---------------------+ + +---------------------------+------------------------------------------------------------+ | | CVE-2020-3810 | | | 1.8.2.1 | Missing input validation in | | | | | | | the ar/tar implementations of | | | | | | | APT before version 2.1.2... | | | | | | | -->avd.aquasec.com/nvd/cve-2020-3810 | + +---------------------+----------+ +---------------------------+------------------------------------------------------------+ | | CVE-2011-3374 | LOW | | | It was found that apt-key in apt, | | | | | | | all versions, do not correctly... | | | | | | | -->avd.aquasec.com/nvd/cve-2011-3374 | +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+ | bash | CVE-2019-18276 | | 5.0-4 | | bash: when effective UID is not | | | | | | | equal to its real UID the... | | | | | | | -->avd.aquasec.com/nvd/cve-2019-18276 | + +---------------------+ + +---------------------------+------------------------------------------------------------+ | | TEMP-0841856-B18BAF | | | | -->security-tracker.debian.org/tracker/TEMP-0841856-B18BAF | +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+ | bsdutils | CVE-2021-37600 | | 2.33.1-0.1 | | util-linux: integer overflow | | | | | | | can lead to buffer overflow | | | | | | | in get_sem_elements() in | | | | | | | sys-utils/ipcutils.c... | | | | | | | -->avd.aquasec.com/nvd/cve-2021-37600 | +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+ | coreutils | CVE-2016-2781 | | 8.30-3 | | coreutils: Non-privileged | | | | | | | session can escape to the | | | | | | | parent session in chroot | | | | | | | -->avd.aquasec.com/nvd/cve-2016-2781 | + +---------------------+ + +---------------------------+------------------------------------------------------------+ | | CVE-2017-18018 | | | | coreutils: race condition | | | | | | | vulnerability in chown and chgrp | | | | | | | -->avd.aquasec.com/nvd/cve-2017-18018 | +-----------------+---------------------+ +---------------------------+---------------------------+------------------------------------------------------------+ | fdisk | CVE-2021-37600 | | 2.33.1-0.1 | | util-linux: integer overflow | | | | | | | can lead to buffer overflow | | | | | | | in get_sem_elements() in | | | | | | | sys-utils/ipcutils.c... | | | | | | | -->avd.aquasec.com/nvd/cve-2021-37600 | +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+ | gcc-8-base | CVE-2018-12886 | HIGH | 8.3.0-6 | | gcc: spilling of stack | | | | | | | protection address in cfgexpand.c | | | | | | | and function.c leads to... | | | | | | | -->avd.aquasec.com/nvd/cve-2018-12886 | + +---------------------+ + +---------------------------+------------------------------------------------------------+ | | CVE-2019-15847 | | | | gcc: POWER9 "DARN" RNG intrinsic | | | | | | | produces repeated output | | | | | | | -->avd.aquasec.com/nvd/cve-2019-15847 | +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+ | gpgv | CVE-2019-14855 | LOW | 2.2.12-1+deb10u1 | | gnupg2: OpenPGP Key Certification | | | | | | | Forgeries with SHA-1 | | | | | | | -->avd.aquasec.com/nvd/cve-2019-14855 | +-----------------+---------------------+----------+---------------------------+---------------------------+------------------------------------------------------------+ | libapt-pkg5.0 | CVE-2020-27350 | MEDIUM | 1.8.2 | 1.8.2.2 | apt: integer overflows and underflows | | | | | | | while parsing .deb packages | | | | | | | -->avd.aquasec.com/nvd/cve-2020-27350 | + +---------------------+ + +---------------------------+------------------------------------------------------------+ | | CVE-2020-3810 | | | 1.8.2.1 | Missing input validation in | | | | | | | the ar/tar implementations of | | | | | | | APT before version 2.1.2... | --More--
trivy image [IMAGE_NAME]
漏洞等级:
扫描文件系统(例如主机、虚拟机映像或解压缩的容器映像文件系统)
# trivy fs /application/zookeeper/ 2021-08-16T19:23:19.322+0800 INFO Number of language-specific files: 35 2021-08-16T19:23:19.322+0800 INFO Detecting jar vulnerabilities... lib/jetty-server-9.4.39.v20210325.jar (jar) =========================================== Total: 2 (UNKNOWN: 0, LOW: 1, MEDIUM: 1, HIGH: 0, CRITICAL: 0) +--------------------------------+------------------+----------+-------------------+------------------------+---------------------------------------+ | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE | +--------------------------------+------------------+----------+-------------------+------------------------+---------------------------------------+ | org.eclipse.jetty:jetty-server | CVE-2019-10247 | MEDIUM | 9.4.39.v20210325 | | jetty: error path | | | | | | | information disclosure | | | | | | | -->avd.aquasec.com/nvd/cve-2019-10247 | + +------------------+----------+ +------------------------+---------------------------------------+ | | CVE-2021-34428 | LOW | | 11.0.3, 10.0.3, 9.4.41 | jetty: SessionListener can | | | | | | | prevent a session from being | | | | | | | invalidated breaking logout | | | | | | | -->avd.aquasec.com/nvd/cve-2021-34428 | +--------------------------------+------------------+----------+-------------------+------------------------+---------------------------------------+ lib/log4j-1.2.17.jar (jar) ========================== Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 0, CRITICAL: 1) +-------------+------------------+----------+-------------------+---------------+---------------------------------------+ | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE | +-------------+------------------+----------+-------------------+---------------+---------------------------------------+ | log4j:log4j | CVE-2019-17571 | CRITICAL | 1.2.17 | | log4j: deserialization of | | | | | | | untrusted data in SocketServer | | | | | | | -->avd.aquasec.com/nvd/cve-2019-17571 | +-------------+------------------+----------+-------------------+---------------+---------------------------------------+
扫描您的远程 git 存储库
# trivy repo https://github.com/kubernetes/kubernetes.git Enumerating objects: 370096, done. Counting objects: 100% (370096/370096), done. Compressing objects: 100% (153736/153736), done. Total 370096 (delta 246795), reused 313878 (delta 202418), pack-reused 0 2021-08-16T19:27:54.433+0800 INFO Number of language-specific files: 31 2021-08-16T19:27:54.434+0800 INFO Detecting gomod vulnerabilities... cluster/addons/fluentd-elasticsearch/es-image/go.sum (gomod) ============================================================ Total: 4 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 3, CRITICAL: 0) +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+ | LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION | TITLE | +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+ | github.com/dgrijalva/jwt-go | CVE-2020-26160 | HIGH | 3.2.0+incompatible | | jwt-go: access restriction | | | | | | | bypass vulnerability | | | | | | | -->avd.aquasec.com/nvd/cve-2020-26160 | +-----------------------------+------------------+ +-----------------------------------+------------------------------------+---------------------------------------+ | github.com/gogo/protobuf | CVE-2021-3121 | | 1.3.1 | v1.3.2 | gogo/protobuf: | | | | | | | plugin/unmarshal/unmarshal.go | | | | | | | lacks certain index validation | | | | | | | -->avd.aquasec.com/nvd/cve-2021-3121 | +-----------------------------+------------------+ +-----------------------------------+------------------------------------+---------------------------------------+ | golang.org/x/crypto | CVE-2020-29652 | | 0.0.0-20200622213623-75b288015ac9 | v0.0.0-20201216223049-8b5274cf687f | golang: crypto/ssh: crafted | | | | | | | authentication request can | | | | | | | lead to nil pointer dereference | | | | | | | -->avd.aquasec.com/nvd/cve-2020-29652 | +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+ | k8s.io/client-go | CVE-2020-8565 | MEDIUM | 0.19.2 | v0.20.0-alpha.2 | kubernetes: Incomplete fix | | | | | | | for CVE-2019-11250 allows for | | | | | | | token leak in logs when... | | | | | | | -->avd.aquasec.com/nvd/cve-2020-8565 | +-----------------------------+------------------+----------+-----------------------------------+------------------------------------+---------------------------------------+ go.sum (gomod) ============== Total: 2 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 1, CRITICAL: 0)
隐藏未修复得漏洞
默认情况下, Trivy
还会检测未修补/未修复的漏洞。这意味着即使您更新所有软件包,您也无法修复这些漏洞。如果您想忽略它们,请使用该--ignore-unfixed
选项。
# trivy image --ignore-unfixed nginx:1.16
按严重程度
使用--severity
选项
# trivy image --severity HIGH,CRITICAL nginx:1.16
按漏洞ID
使用.trivyignore
.
# cat .trivyignore # Accept the risk CVE-2018-14618 # No impact in our settings CVE-2019-1543 # trivy image nginx:1.16
按类型
使用--vuln-type
选项。
# trivy image --vuln-type os nginx:1.16
跳过漏洞数据库得更新
Trivy
开始运行时每 12 小时下载一次漏洞数据库。这通常很快,因为数据库的大小只有 10~30MB。但是,如果您甚至想跳过它,请使用该--skip-db-update
选项。
# trivy image --skip-db-update nginx:1.16
只下载漏洞数据库
# trivy image --download-db-only
轻量级数据库
轻量级数据库不包含漏洞详细信息,例如描述和参考。因此,DB 的大小更小,下载速度更快。
当您不需要漏洞详细信息并且适用于 CI/CD 时,此选项很有用。要查找其他信息,您可以在 NVD 网站上搜索漏洞详细信息。https://nvd.nist.gov/vuln/search
# trivy image --light nginx:1.16
--light
选项不会像下面的例子那样显示标题。
清除缓存
该--clear-cache
选项删除缓存。
不执行扫描。
# trivy image --clear-cache
缓存目录
用 指定缓存的存储位置--cache-dir
。
$ trivy --cache-dir /tmp/trivy/ image nginx:1.16
缓存后端
Trivy 支持本地文件系统和 Redis 作为缓存后端。此选项特别适用于客户端/服务器模式。
两个选项: - fs
- 缓存路径可以通过--cache-dir
- redis://
-redis://[HOST]:[PORT]
# trivy server --cache-backend redis://localhost:6379
表格(默认)
# trivy image -f table nginx:1.16
JSON
trivy image -f json -o results.json nginx:1.16
https://github.com/aquasecurity/trivy