Skip to content

Commit b476cbb

Browse files
author
Paul
committed
scanner/screenshooter
1 parent ef97b15 commit b476cbb

File tree

12 files changed

+90
-96
lines changed

12 files changed

+90
-96
lines changed

.github/workflows/ci.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ jobs:
181181
tag_with_ref: true
182182
tag_with_sha: true
183183
build_args: baseImageTag=ci-local
184+
- uses: docker/build-push-action@v1
185+
name: "Build & Push Screenshooter Parser Image"
186+
with:
187+
username: ${{ secrets.DOCKER_USERNAME }}
188+
password: ${{ secrets.DOCKER_PASSWORD }}
189+
repository: securecodebox/parser-screenshooter
190+
path: ./scanners/screenshooter/parser/
191+
tag_with_ref: true
192+
tag_with_sha: true
193+
build_args: baseImageTag=ci-local
184194
- uses: docker/build-push-action@v1
185195
name: "Build & Push ssh_scan Parser Image"
186196
with:
@@ -352,6 +362,15 @@ jobs:
352362
path: ./scanners/nmap/scanner/
353363
# Note: not prefixed with a "v" as this seems to match nmap versioning standards
354364
tags: "7.80,7.80-r2,latest"
365+
- uses: docker/build-push-action@v1
366+
name: "Build & Push Screenshooter Scanner Image"
367+
with:
368+
username: ${{ secrets.DOCKER_USERNAME }}
369+
password: ${{ secrets.DOCKER_PASSWORD }}
370+
repository: securecodebox/scanner-screenshooter
371+
path: ./scanners/screenshooter/scanner/
372+
tags: "latest"
373+
tag_with_ref: true
355374
- uses: docker/build-push-action@v1
356375
name: "Build & Push kube-hunter Scanner Image"
357376
with:

parser-sdk/nodejs/parser-wrapper.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ const { parse } = require("./parser/parser");
33
const uuid = require("uuid/v4");
44
const k8s = require("@kubernetes/client-node");
55

6+
const kc = new k8s.KubeConfig();
7+
kc.loadFromCluster();
8+
const k8sApi = kc.makeApiClient(k8s.CustomObjectsApi);
9+
const scanName = process.env["SCAN_NAME"];
10+
const namespace = process.env["NAMESPACE"];
11+
612
function severityCount(findings, severity) {
713
return findings.filter(
814
({ severity: findingSeverity }) =>
@@ -11,11 +17,6 @@ function severityCount(findings, severity) {
1117
}
1218

1319
async function updateScanStatus(findings) {
14-
const kc = new k8s.KubeConfig();
15-
kc.loadFromCluster();
16-
const k8sApi = kc.makeApiClient(k8s.CustomObjectsApi);
17-
const scanName = process.env["SCAN_NAME"];
18-
const namespace = process.env["NAMESPACE"];
1920

2021
try {
2122
const findingCategories = new Map();
@@ -60,8 +61,27 @@ async function updateScanStatus(findings) {
6061
}
6162
}
6263

64+
async function extractScan() {
65+
try {
66+
const { body } = await k8sApi.getNamespacedCustomObject(
67+
"execution.securecodebox.io",
68+
"v1",
69+
namespace,
70+
"scans",
71+
scanName
72+
);
73+
return body;
74+
} catch (err) {
75+
console.error("Failed to get Scan from the kubernetes api");
76+
console.error(err);
77+
process.exit(1);
78+
}
79+
}
80+
6381
async function main() {
6482
console.log("Starting Parser");
83+
let scan = await extractScan();
84+
6585
const resultFileUrl = process.argv[2];
6686
const resultUploadUrl = process.argv[3];
6787

@@ -71,7 +91,7 @@ async function main() {
7191

7292
let findings = [];
7393
try {
74-
findings = await parse(data);
94+
findings = await parse(data, scan);
7595
} catch (error) {
7696
console.error("Parser failed with error:");
7797
console.error(error);

scanners/screenshooter/README.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +0,0 @@
1-
---
2-
title: "Screenshooter"
3-
category: "scanner"
4-
type: "Application"
5-
state: "not released"
6-
usecase: "Takes Screenshots of websites"
7-
---
8-
![firefox logo](https://3u26hb1g25wn1xwo8g186fnd-wpengine.netdna-ssl.com/files/2019/10/logo-firefox.svg)
9-
10-
This integration takes screenshots of websites. This can be extremely helpful when you are using the secureCodeBox to scan a large number of services and want to get a quick visual overview of each service.
11-
12-
<!-- end -->
13-
14-
## Deployment
15-
16-
The scanType can be deployed via helm.
17-
18-
```bash
19-
helm upgrade --install screenshooter ./scanners/screenshooter/
20-
```
21-
22-
## Examples
23-
24-
A set of examples can be found in the [examples](./examples) folder.
25-
26-
- Example _secureCodeBox.io_ [scan](./examples/secureCodeBox.io/scan.yaml) and [findings](./examples/secureCodeBox.io/findings.yaml)
27-
- Example _example.com_ [scan](./examples/secureCodeBox.io/scan.yaml) and [findings](./examples/secureCodeBox.io/findings.yaml)
28-
29-
## Development
30-
31-
### Local setup
32-
33-
1. Clone the repository `git clone git@github.com:secureCodeBox/secureCodeBox-v2-alpha.git`
34-
2. Ensure you have node.js installed
35-
- On MacOs with brew package manager: `brew install node`
36-
37-
### Parser Development
38-
39-
1. Install the dependencies `npm install`
40-
2. Update the parser function here: `./parser/parser.js`
41-
3. Update the parser tests here: `./parser/parser.test.js`
42-
4. Run the testsuite: `npm test`

scanners/screenshooter/README.md.gotmpl

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ usecase: "Takes Screenshots of websites"
99

1010
This integration takes screenshots of websites. This can be extremely helpful when you are using the secureCodeBox to scan a large number of services and want to get a quick visual overview of each service.
1111

12-
<!-- end -->
13-
1412
## Deployment
1513

1614
The scanType can be deployed via helm.
@@ -19,24 +17,8 @@ The scanType can be deployed via helm.
1917
helm upgrade --install screenshooter ./scanners/screenshooter/
2018
```
2119

22-
## Examples
23-
24-
A set of examples can be found in the [examples](./examples) folder.
25-
26-
- Example _secureCodeBox.io_ [scan](./examples/secureCodeBox.io/scan.yaml) and [findings](./examples/secureCodeBox.io/findings.yaml)
27-
- Example _example.com_ [scan](./examples/secureCodeBox.io/scan.yaml) and [findings](./examples/secureCodeBox.io/findings.yaml)
28-
29-
## Development
30-
31-
### Local setup
32-
33-
1. Clone the repository `git clone git@github.com:secureCodeBox/secureCodeBox-v2-alpha.git`
34-
2. Ensure you have node.js installed
35-
- On MacOs with brew package manager: `brew install node`
36-
37-
### Parser Development
20+
### Configuration
3821

39-
1. Install the dependencies `npm install`
40-
2. Update the parser function here: `./parser/parser.js`
41-
3. Update the parser tests here: `./parser/parser.test.js`
42-
4. Run the testsuite: `npm test`
22+
You have to provide only the URL to the screenshooter. Be careful, the protocol is mandatory:
23+
* `https://secureCodeBox.io`
24+
* **not** `secureCodeBox.io` or `www.secureCodeBox.io`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: "cascading.securecodebox.io/v1"
2+
kind: CascadingRule
3+
metadata:
4+
name: "screenshooter-http"
5+
labels:
6+
securecodebox.io/invasive: non-invasive
7+
securecodebox.io/intensive: light
8+
spec:
9+
matches:
10+
anyOf:
11+
- category: "Open Port"
12+
attributes:
13+
service: http
14+
state: open
15+
- category: "Open Port"
16+
attributes:
17+
service: https
18+
state: open
19+
scanSpec:
20+
scanType: "screenshooter"
21+
parameters: ["{{attributes.service}}://{{$.hostOrIP}}"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This scan screenshots https://github.com/secureCodeBox
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apiVersion: "execution.securecodebox.io/v1"
22
kind: Scan
33
metadata:
4-
name: "screenshot-securecodebox.io"
4+
name: "screenshot-github-securecodebox.io"
55
spec:
66
scanType: "screenshooter"
77
parameters:
8-
- "https://fjoel3.dje"
8+
- "https://github.com/secureCodeBox"

scanners/screenshooter/parser/parser.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const arg = require("arg");
2-
3-
async function parse(image) {
1+
async function parse(image, scan) {
42

53
if (image.length === 0) {
64
return []

scanners/screenshooter/parser/parser.test.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ beforeEach(() => {
1919
});
2020

2121
test("should create finding correctly", async () => {
22-
expect(await parse(undefined, { scan })).toMatchInlineSnapshot(`
22+
expect(await parse("thisisabinarystringformatedimage", scan )).toMatchInlineSnapshot(`
2323
Array [
2424
Object {
2525
"attributes": Object {
@@ -36,21 +36,7 @@ test("should create finding correctly", async () => {
3636
`);
3737
});
3838

39-
test("should also create finding correctly when using short flag '-u' instead of full '--url' flag", async () => {
39+
test("should not create finding if image is empty", async () => {
4040
(scan.spec.parameters = ["https://www.iteratec.de"]),
41-
expect(await parse(undefined, { scan })).toMatchInlineSnapshot(`
42-
Array [
43-
Object {
44-
"attributes": Object {
45-
"downloadLink": "https://s3.example.com/foobar.png",
46-
},
47-
"category": "Screenshot",
48-
"description": "Took a Screenshot for website: 'https://www.iteratec.de'",
49-
"location": "https://www.iteratec.de",
50-
"name": "Screenshot for https://www.iteratec.de",
51-
"osi_layer": "APPLICATION",
52-
"severity": "INFORMATIONAL",
53-
},
54-
]
55-
`);
41+
expect(await parse("", scan )).toMatchInlineSnapshot(`Array []`);
5642
});

scanners/screenshooter/scanner/wrapper.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Screnshooter entrypoint script to change the result file linux permission after completion.
22
# Firefox will set the permission in a way which makes it inaccessible to the lurcher otherwise
3-
timeout 60 firefox $@
4-
timeout 60 firefox $@
3+
# Gets executed two times because it happend to produce better results for long loading sites
4+
timeout 30 firefox $@
5+
timeout 30 firefox $@
56
if [ ! -f /home/securecodebox/screenshot.png ]; then
67
touch /home/securecodebox/screenshot.png
78
fi

0 commit comments

Comments
 (0)