Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit e909d58

Browse files
committed
#33 Add WIP declarative subsequent hook implementation
1 parent 104dc4f commit e909d58

File tree

16 files changed

+5548
-0
lines changed

16 files changed

+5548
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
.vscode/
23+
# Node.js files
24+
node_modules/*
25+
package.json
26+
package-lock.json
27+
src/*
28+
config/*
29+
Dockerfile
30+
.dockerignore
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies: []
2+
digest: sha256:643d5437104296e21d906ecb15b2c96ad278f20cfc4af53b12bb6069bd853726
3+
generated: "2020-05-26T16:56:03.119255+02:00"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v2
2+
name: declarative-subsequent-scans
3+
description: Starts possible subsequent security scans based on findings (e.g. open ports found by NMAP or subdomains found by AMASS).
4+
5+
type: application
6+
7+
version: 0.1.0
8+
9+
appVersion: latest
10+
11+
dependencies: []
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This image doesn't install the hooks dependencies, as it only has the @kubernetes/client-node dependencies which is already installed via the hook-sdk
2+
3+
FROM scbexperimental/hook-sdk-nodejs:latest
4+
WORKDIR /home/app/hook-wrapper/hook/
5+
COPY --chown=app:app hook.js scan-helpers.js ./
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { startSubsequentSecureCodeBoxScan } = require("./scan-helpers");
2+
const isMatch = require("lodash.ismatch");
3+
4+
async function handle({ scan, getFindings }) {
5+
const findings = await getFindings();
6+
const cascadingRules = await getCascadingRules();
7+
8+
const cascadingScans = getCascadingScans(findings, cascadingRules);
9+
10+
for (const { scanType, parameters } of cascadingScans) {
11+
await startSubsequentSecureCodeBoxScan({
12+
parentScan: scan,
13+
scanType,
14+
parameters,
15+
});
16+
}
17+
}
18+
19+
async function getCascadingRules() {
20+
// Todo: Get all CascadingRules of the current Namespace via k8s api
21+
return [];
22+
}
23+
24+
// Todo remove eslint disable
25+
// eslint-disable-next-line no-unused-vars
26+
function getCascadingScans(findings, cascadingRules) {
27+
const cascadingScans = [];
28+
29+
for (const cascadingRule of cascadingRules) {
30+
for (const finding of findings) {
31+
const matches = cascadingRule.spec.matches.some((matchesRule) =>
32+
isMatch(finding, matchesRule)
33+
);
34+
35+
if (matches) {
36+
// Todo templating
37+
cascadingScans.push(cascadingRule.spec.scanSpec);
38+
}
39+
}
40+
}
41+
42+
return cascadingScans;
43+
}
44+
45+
module.exports.getCascadingScans = getCascadingScans;
46+
module.exports.handle = handle;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const { getCascadingScans } = require("./hook");
2+
3+
test("Should create subsequent scans for open HTTPS ports (NMAP findings)", () => {
4+
const findings = [
5+
{
6+
name: "Port 443 is open",
7+
category: "Open Port",
8+
attributes: {
9+
state: "open",
10+
hostname: "foobar.com",
11+
port: 443,
12+
service: "https"
13+
}
14+
}
15+
];
16+
17+
const cascadingRules = [
18+
{
19+
apiVersion: "cascading.experimental.securecodebox.io/v1",
20+
kind: "CascadingRule",
21+
metadata: {
22+
name: "tls-scans"
23+
},
24+
spec: {
25+
matches: [
26+
{
27+
category: "Open Port",
28+
attributes: {
29+
port: 443,
30+
service: "https"
31+
}
32+
},
33+
{
34+
category: "Open Port",
35+
attributes: {
36+
service: "https"
37+
}
38+
}
39+
],
40+
scanSpec: {
41+
name: "sslyze",
42+
parameters: ["--regular", "{attributes.hostname}"]
43+
}
44+
}
45+
}
46+
];
47+
48+
const cascadedScans = getCascadingScans(findings, cascadingRules);
49+
50+
expect(cascadedScans).toMatchInlineSnapshot(`
51+
Array [
52+
Object {
53+
"name": "sslyze",
54+
"parameters": Array [
55+
"--regular",
56+
"{attributes.hostname}",
57+
],
58+
},
59+
]
60+
`);
61+
});
62+
63+
test("Should create no subsequent scans if there are no rules", () => {
64+
const findings = [
65+
{
66+
name: "Port 443 is open",
67+
category: "Open Port",
68+
attributes: {
69+
state: "open",
70+
hostname: "foobar.com",
71+
port: 443,
72+
service: "https"
73+
}
74+
}
75+
];
76+
77+
const cascadingRules = [];
78+
79+
const cascadedScans = getCascadingScans(findings, cascadingRules);
80+
81+
expect(cascadedScans).toMatchInlineSnapshot(`Array []`);
82+
});

0 commit comments

Comments
 (0)