サイトアイコン TakeNotes.JP

Trivyを使ってコンテナイメージの脆弱性をスキャンしてみた

コンテナイメージの脆弱性スキャンが出来るTrivyを使ってみました。

OSはUbuntu 22.04です。

インストールはCLI Installationを参考に。

sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] 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

未指定だとTABLE形式で、json形式やHTML形式にも出力できます。

例として、手元に.NET 3.1のコンテナをpullし、スキャンしてみます。(出力結果は大きすぎるので省略)

sudo docker pull mcr.microsoft.com/dotnet/sdk:3.1
sudo trivy image mcr.microsoft.com/dotnet/sdk:3.1
2022-12-14T23:03:16.814+0900    INFO    Need to update DB
2022-12-14T23:03:16.814+0900    INFO    DB Repository: ghcr.io/aquasecurity/trivy-db
2022-12-14T23:03:16.814+0900    INFO    Downloading DB...
35.59 MiB / 35.59 MiB [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 10.83 MiB p/s 3.5s
2022-12-14T23:03:21.699+0900    INFO    Vulnerability scanning is enabled
2022-12-14T23:03:21.699+0900    INFO    Secret scanning is enabled
2022-12-14T23:03:21.699+0900    INFO    If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
2022-12-14T23:03:21.699+0900    INFO    Please see also https://aquasecurity.github.io/trivy/v0.35/docs/secret/scanning/#recommendation for faster secret detection
2022-12-14T23:03:49.424+0900    INFO    Detected OS: debian
2022-12-14T23:03:49.424+0900    INFO    Detecting Debian vulnerabilities...
2022-12-14T23:03:49.471+0900    INFO    Number of language-specific files: 20
2022-12-14T23:03:49.471+0900    INFO    Detecting dotnet-core vulnerabilities...

mcr.microsoft.com/dotnet/sdk:3.1 (debian 10.13)

Total: 249 (UNKNOWN: 0, LOW: 172, MEDIUM: 28, HIGH: 37, CRITICAL: 12)

┌──────────────────────┬──────────────────┬──────────┬────────────────────────┬────────────────────┬──────────────────────────────────────────────────────────────┐
│       Library        │  Vulnerability   │ Severity │   Installed Version    │   Fixed Version    │                            Title                             │
├──────────────────────┼──────────────────┼──────────┼────────────────────────┼────────────────────┼──────────────────────────────────────────────────────────────┤
│ apt                  │ CVE-2011-3374    │ LOW      │ 1.8.2.3                │                    │ It was found that apt-key in apt, all versions, do not       │
│                      │                  │          │                        │                    │ correctly...                                                 │
│                      │                  │          │                        │                    │ https://avd.aquasec.com/nvd/cve-2011-3374                    │
├──────────────────────┼──────────────────┼──────────┼────────────────────────┼────────────────────┼──────────────────────────────────────────────────────────────┤
│ bash                 │ CVE-2022-3715    │ MEDIUM   │ 5.0-4                  │                    │ bash: a heap-buffer-overflow in valid_parameter_transform    │
│                      │                  │          │                        │                    │ https://avd.aquasec.com/nvd/cve-2022-3715                    │
│                      ├──────────────────┼──────────┤                        ├────────────────────┼──────────────────────────────────────────────────────────────┤
│                      │ CVE-2019-18276   │ LOW      │                        │                    │ bash: when effective UID is not equal to its real UID the... │
│                      │                  │          │                        │                    │ https://avd.aquasec.com/nvd/cve-2019-18276                   │
├──────────────────────┼──────────────────┤          ├────────────────────────┼────────────────────┼──────────────────────────────────────────────────────────────┤
│ 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...                │
│                      │                  │          │                        │                    │ https://avd.aquasec.com/nvd/cve-2021-37600                   │
│                      ├──────────────────┤          │                        ├────────────────────┼──────────────────────────────────────────────────────────────┤
│                      │ CVE-2022-0563    │          │                        │                    │ util-linux: partial disclosure of arbitrary files in chfn    │
│                      │                  │          │                        │                    │ and chsh when compiled...                                    │
│                      │                  │          │                        │                    │ https://avd.aquasec.com/nvd/cve-2022-0563                    │
├──────────────────────┼──────────────────┤          ├────────────────────────┼────────────────────┼──────────────────────────────────────────────────────────────┤

 

templatesディレクトリにHTML出力用のテンプレート(html.tpl)が存在します。

ls -l /usr/local/share/trivy/templates/
total 28
-rw-r--r-- 1 root root 6994 Nov 28 01:06 asff.tpl
-rw-r--r-- 1 root root 3392 Nov 28 01:06 gitlab-codequality.tpl
-rw-r--r-- 1 root root 2512 Nov 28 01:06 gitlab.tpl
-rw-r--r-- 1 root root 5044 Nov 28 01:06 html.tpl
-rw-r--r-- 1 root root 1366 Nov 28 01:06 junit.tpl

このようにtemplateを指定することで、HTMLとして出力されます。

この場合は -o report.html と指定しているので、カレントディレクトリにreport.htmlが作成されます。

sudo trivy image --format template --template "@/usr/local/share/trivy/templates/html.tpl" -o report.html mcr.microsoft.com/dotnet/sdk:3.1
2022-12-14T23:21:00.869+0900 INFO Vulnerability scanning is enabled
2022-12-14T23:21:00.869+0900 INFO Secret scanning is enabled
2022-12-14T23:21:00.869+0900 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
2022-12-14T23:21:00.869+0900 INFO Please see also https://aquasecurity.github.io/trivy/v0.35/docs/secret/scanning/#recommendation for faster secret detection
2022-12-14T23:21:00.910+0900 INFO Detected OS: debian
2022-12-14T23:21:00.910+0900 INFO Detecting Debian vulnerabilities...
2022-12-14T23:21:00.936+0900 INFO Number of language-specific files: 20
2022-12-14T23:21:00.936+0900 INFO Detecting dotnet-core vulnerabilities...

サンプルとして2つ.NET SDK 3.1、6.0のレポートファイルを作成してみました。両方とも2022年12月14日時点のものです。

 

参考:

モバイルバージョンを終了