前言:Trivy 是开源的,由 Aqua Security 开发,采用 Apache License 2.0 许可证,代码托管在 GitHub 上(https://github.com/aquasecurity/trivy)。

一、安装Trivy

二进制:

https://github.com/aquasecurity/trivy/releases/download/v0.60.0/trivy_0.60.0_Linux-64bit.tar.gz

ubuntu系统

sudo apt-get install -y wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy

docker运行:

docker run aquasec/trivy:latest [COMMAND]

 

二、基本使用

1.扫描镜像

trivy image [镜像名称]
# 示例:扫描 Ubuntu 镜像
trivy image ubuntu:latest

2.扫描远程仓库地址

trivy image [仓库地址]/[镜像名称]:[标签]
# 示例:扫描 Docker Hub 的 Alpine 镜像
trivy image alpine:3.16

3.扫描文件系统

trivy fs --security-checks vuln,config,secret ./

4.扫描git仓库

trivy fs --security-checks vuln,config,secret ./

 

5.输出格式

trivy image --format json -o result.json ubuntu:latest
trivy image --format template --template "@contrib/html.tpl" -o report.html ubuntu:latest

 6.更新漏洞数据库

trivy --cache-dir /path/to/cache cleanup # 清理旧数据
trivy --cache-dir /path/to/cache update # 更新数据库

#更新镜像最新漏洞库

trivy image --download-db-only --db-repository ghcr.io/aquasecurity/trivy-db:2
trivy image --download-java-db-only --java-db-repository ghcr.nju.edu.cn/aquasecurity/trivy-java-db:1