Skip to content

Commit c95971f

Browse files
added owasp-juice-shop-scan-container-with-trivy
1 parent 005e43e commit c95971f

File tree

2 files changed

+101
-6
lines changed

2 files changed

+101
-6
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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--

_posts/owaspjuiceshop/2021-08-07-owasp-juice-shop-npm-audit.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ high and 3 critical vulnerabilites.
215215

216216
# Fix
217217

218-
In certain cases, its possible to give an automatic fix using npm with `npm audit fix` command fix
219-
vulnerabilities. Its not possible always though as in our case, we can simulate this with the
220-
--dry-run flag to foresee what really happens.
218+
In certain cases, its possible to give an automatic fix using npm with `npm audit fix` command. Its not
219+
possible always though as in our case, we can simulate this with the --dry-run flag to foresee what
220+
really happens.
221221
```
222222
networkandcode@ubuntu20:~/juice-shop$ npm audit fix --dry-run
223223
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^2.1.2 (node_modules/jest-haste-map/node_modules/fsevents):
@@ -234,11 +234,11 @@ fixed 0 of 25 vulnerabilities in 2005 scanned packages
234234
(use `npm audit fix --force` to install breaking changes; or refer to `npm audit` for steps to fix these manually)
235235
```
236236

237-
So it clearly says no vulnerabilities are fixed, and could also lead to breaking changes if the fix is
238-
forced. We have to then go through the recommendation for each vulnerability and try and fix it
237+
So it clearly says no vulnerabilities could be fixed, and could also lead to breaking changes if the
238+
fix is forced. We have to then go through the recommendation for each vulnerability and try to fix it
239239
manually after reviewing that it doesnt break other packages.
240240

241241
Thats the end of this post, we saw how to perform few commands in the npm audit family, and how the exit
242-
code can be checked to see if failed auditing or not.
242+
code can be checked to see if it failed auditing or not.
243243

244244
--end-of-post--

0 commit comments

Comments
 (0)