10

5.4k Star!简单又全面的容器漏洞扫描工具:Trivy

 3 years ago
source link: http://dockone.io/article/58868
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【编者的话】Trivy是一个面向容器和其他组件的,兼具综合性和简洁性的脆弱性扫面器。

简介

软件的脆弱性是存在于软件或者操作系统中的缺陷。Trivy,tri发音像trigger,vy发音像envy,主要用来探测操作系统(Alpine,RHEL,CentOS等)和应用依赖(Bundler,Composer,npm,yarn等)的脆弱性,简单易用。

只需要安装二进制文件,就能开始使用,你需要做的就是确定扫描目标。扫描目标可以是容器的镜像名。

扫描器也可以在持续集成中的使用。在push容器注册或者发布应用之前,可以扫描本地的容器镜像和其他组件。

Ubaaquy.gif!mobile

安装

RHEL/CentOS下安装:

添加库设置到/etc/yum.repos.d

$ 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 -ivh https://github.com/aquasecurity/trivy/releases/download/{TRIVY_VERSION}/trivy_{TRIVY_VERSION}_Linux-64bit.rpm

Debian/Ubuntu下安装:

添加库文件到/etc/apt/sources.list.d.

$ sudo apt-get install 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

或者是

$ sudo apt-get install rpm

$ wget https://github.com/aquasecurity/trivy/releases/download/{TRIVY_VERSION}/trivy_{TRIVY_VERSION}_Linux-64bit.deb

$ sudo dpkg -i trivy_{TRIVY_VERSION}_Linux-64bit.deb

你也可以在macOS和Linux下使用homebrew安装:

$ brew install aquasecurity/trivy/trivy

安装脚本

下面这个脚本基于你的操作系统和架构来下载Trivy二进制文件:

$ curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/master/contrib/install.sh | sh -s -- -b /usr/local/bin

如果以上安装方式不能满足你的实际要求,本工具还支持其他的安装方式,详情可在项目中查找,项目地址见本文结尾。

通过Docker启动

用[YOUR_CACHE_DIR]替换你机器上的缓存目录:

Linux下:

$ docker run --rm -v [YOUR_CACHE_DIR]:/root/.cache/ aquasec/trivy [YOUR_IMAGE_NAME] 

MacOS下:

$ docker run --rm -v $HOME/Library/Caches:/root/.cache/ aquasec/trivy python:3.4-alpin

如果你想要扫描你主机上的镜像,还需要挂载docker.sock.

$ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \

-v $HOME/Library/Caches:/root/.cache/ aquasec/trivy python:3.4-alpine

如果报错,可尝试重新拉取最新的aquasec/trivy来解决。

扫描文件系统

扫描文件系统(比如主机,虚拟机镜像,或者解压的容器镜像文件),Trivy将会选择lock文件的脆弱性,比如Gemfile.lock和package-lock.json。

$ trivy fs /path/to/project

扫描容器中的容器:

$ docker run --rm -it alpine:3.11

/ # curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/master/contrib/install.sh | sh -s -- -b /usr/local/bin

/ # trivy fs /

使用示例

扫描镜像:

$ trivy image knqyf263/vuln-image:1.2.3

扫描结果保存为json:

$ trivy image -f json -o results.json golang:1.12-alpine

本工具功能十分强大,如果你想了解更多更详细的使用,可访问如下地址: https://github.com/aquasecurity/trivy

原文链接: https://mp.weixin.qq.com/s/Hr0u1s76USxB46419Adn4A


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK