|
| 1 | +--- |
| 2 | +title: owasp juice shop > scan container with trivy |
| 3 | +categories: owasp juice shop |
| 4 | +--- |
| 5 | + |
| 6 | +In this post, we would be using an opensource container scanning tool called Trivy, developed by |
| 7 | +Aquasecurity to scan the juice shop container image. You need to have some familiarity with jq to |
| 8 | +follow along. |
| 9 | + |
| 10 | +Let's first install Trivy and its dependencies, I am using ubuntu, so the installation instructions |
| 11 | +may vary, if you are on a non debian system. |
| 12 | + |
| 13 | +Install dependencies and update repos. |
| 14 | +``` |
| 15 | +$ sudo apt-get update -y |
| 16 | +$ sudo apt-get install wget apt-transport-https gnupg lsb-release -y |
| 17 | +$ wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add - |
| 18 | +$ echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list |
| 19 | +``` |
| 20 | + |
| 21 | +Update the system again, and install Trivy. |
| 22 | +``` |
| 23 | +$ sudo apt-get update -y |
| 24 | +$ sudo apt-get install trivy -y |
| 25 | +``` |
| 26 | + |
| 27 | +Trivy should now be installed, we can check its version. |
| 28 | +``` |
| 29 | +$ trivy -v |
| 30 | +Version: 0.19.2 |
| 31 | +``` |
| 32 | + |
| 33 | +We can now scan the image in dockerhub. |
| 34 | +``` |
| 35 | +$ trivy image bkimminich/juice-shop |
| 36 | +---TRUNCATED--- |
| 37 | +------------------------------------------+ |
| 38 | +| | CVE-2021-32804 | | | 6.1.1, 5.0.6, 4.4.14, 3.2.2 | nodejs-tar: arbitrary File | |
| 39 | +| | | | | | Creation/Overwrite vulnerability | |
| 40 | +| | | | | | via insufficient symlink protection | |
| 41 | +| | | | | | -->avd.aquasec.com/nvd/cve-2021-32804 | |
| 42 | ++---------------+---------------------+----------+-------------------+-----------------------------+----------------------------------------------+ |
| 43 | +``` |
| 44 | + |
| 45 | +We can fetch the result in JSON to filter it with jq. |
| 46 | +``` |
| 47 | +$ trivy image --format json --output /tmp/audit.json bkimminich/juice-shop |
| 48 | +2021-08-07T17:55:14.342+0530 INFO Detected OS: alpine |
| 49 | +2021-08-07T17:55:14.343+0530 INFO Detecting Alpine vulnerabilities... |
| 50 | +2021-08-07T17:55:14.343+0530 INFO Number of language-specific files: 2 |
| 51 | +2021-08-07T17:55:14.343+0530 INFO Detecting npm vulnerabilities... |
| 52 | +2021-08-07T17:55:14.378+0530 WARN DEPRECATED: the current JSON schema is deprecated, check https://github.com/aquasecurity/trivy/discussions/1050 for more information. |
| 53 | +``` |
| 54 | + |
| 55 | +The warning above w.r.t the JSON format can be overcome with an env variable TRIVY_NEW_JSON_SCHEMA. |
| 56 | +``` |
| 57 | +$ TRIVY_NEW_JSON_SCHEMA=true trivy image --format json --output /tmp/audit.json bkimminich/juice-shop |
| 58 | +2021-08-07T17:59:54.006+0530 INFO Detected OS: alpine |
| 59 | +2021-08-07T17:59:54.006+0530 INFO Detecting Alpine vulnerabilities... |
| 60 | +2021-08-07T17:59:54.007+0530 INFO Number of language-specific files: 2 |
| 61 | +2021-08-07T17:59:54.007+0530 INFO Detecting npm vulnerabilities... |
| 62 | +``` |
| 63 | + |
| 64 | +We can parse this with jq. Lets try a few commands. |
| 65 | +``` |
| 66 | +$ cat /tmp/audit.json | jq 'keys' |
| 67 | +[ |
| 68 | + "ArtifactName", |
| 69 | + "ArtifactType", |
| 70 | + "Metadata", |
| 71 | + "Results", |
| 72 | + "SchemaVersion" |
| 73 | +] |
| 74 | +
|
| 75 | +
|
| 76 | +$ cat /tmp/audit.json | jq '.Metadata' |
| 77 | +{ |
| 78 | + "OS": { |
| 79 | + "Family": "alpine", |
| 80 | + "Name": "3.11.11" |
| 81 | + }, |
| 82 | + "RepoTags": [ |
| 83 | + "bkimminich/juice-shop:latest" |
| 84 | + ], |
| 85 | + "RepoDigests": [ |
| 86 | + "bkimminich/juice-shop@sha256:8abf7e5b28b5b0e3e2a88684ecac9dc9740643b46e17a4edc9fc16141289869b" |
| 87 | + ] |
| 88 | +} |
| 89 | +
|
| 90 | +``` |
| 91 | + |
| 92 | +So, we have seen how to install Trivy and how to use it to scan the juice shop container image. Thank |
| 93 | +you for reading. |
| 94 | + |
| 95 | +--end-of-post-- |
0 commit comments