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

Commit cd2b61c

Browse files
authored
Merge pull request #34 from secureCodeBox/declarative-combined-scans
Add Declarative Combined Scans Implementation
2 parents dde6ed1 + 17eef6a commit cd2b61c

File tree

60 files changed

+7348
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+7348
-9
lines changed

.eslintignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
**/node_modules
2-
**/coverage
2+
**/coverage
3+
hooks/declarative-subsequent-scans/hook.js
4+
hooks/declarative-subsequent-scans/scan-helpers.js
5+
hooks/declarative-subsequent-scans/kubernetes-label-selector.js

.github/workflows/ci.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ jobs:
4040
cd -
4141
cd hooks/
4242
npm ci
43+
- name: "Compile Typescript"
44+
run: |
45+
cd hooks/declarative-subsequent-scans
46+
npm run build
4347
- name: "Run tests & publish code coverage"
4448
uses: paambaati/codeclimate-action@v2.6.0
4549
env:
@@ -248,6 +252,16 @@ jobs:
248252
path: ./hooks/imperative-subsequent-scans/
249253
tag_with_ref: true
250254
build_args: baseImageTag=ci-local
255+
- uses: docker/build-push-action@v1
256+
name: "Build & Push DeclarativeSubsequentScans Hook Image"
257+
with:
258+
username: ${{ secrets.DOCKER_USERNAME }}
259+
password: ${{ secrets.DOCKER_PASSWORD }}
260+
repository: scbexperimental/hook-declarative-subsequent-scans
261+
path: ./hooks/declarative-subsequent-scans/
262+
tag_with_ref: true
263+
tag_with_sha: true
264+
build_args: baseImageTag=ci-local
251265
- uses: docker/build-push-action@v1
252266
name: "Build & Push UpdateField Hook Image"
253267
with:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
*.map
3+
**.js
4+
!**.test.js
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ARG baseImageTag
2+
FROM node:12-alpine as install
3+
RUN mkdir -p /home/app
4+
WORKDIR /home/app
5+
COPY package.json package-lock.json ./
6+
RUN npm ci --production
7+
8+
FROM node:12-alpine as build
9+
RUN mkdir -p /home/app
10+
WORKDIR /home/app
11+
COPY package.json package-lock.json ./
12+
RUN npm ci
13+
COPY hook.ts scan-helpers.ts kubernetes-label-selector.ts ./
14+
RUN npm run build
15+
16+
FROM scbexperimental/hook-sdk-nodejs:${baseImageTag:-latest}
17+
WORKDIR /home/app/hook-wrapper/hook/
18+
COPY --from=install --chown=app:app /home/app/node_modules/ ./node_modules/
19+
COPY --from=build --chown=app:app /home/app/hook.js /home/app/scan-helpers.js /home/app/kubernetes-label-selector.js ./
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
const { getCascadingScans } = require("./hook");
2+
3+
let parentScan = undefined;
4+
let sslyzeCascadingRules = undefined;
5+
6+
beforeEach(() => {
7+
parentScan = {
8+
apiVersion: "execution.experimental.securecodebox.io/v1",
9+
kind: "Scan",
10+
metadata: {
11+
name: "nmap-foobar.com",
12+
annotations: {}
13+
},
14+
spec: {
15+
scanType: "nmap",
16+
parameters: "foobar.com",
17+
cascades: {}
18+
}
19+
};
20+
21+
sslyzeCascadingRules = [
22+
{
23+
apiVersion: "cascading.experimental.securecodebox.io/v1",
24+
kind: "CascadingRule",
25+
metadata: {
26+
name: "tls-scans"
27+
},
28+
spec: {
29+
matches: {
30+
anyOf: [
31+
{
32+
category: "Open Port",
33+
attributes: {
34+
port: 443,
35+
service: "https"
36+
}
37+
},
38+
{
39+
category: "Open Port",
40+
attributes: {
41+
service: "https"
42+
}
43+
}
44+
]
45+
},
46+
scanSpec: {
47+
scanType: "sslyze",
48+
parameters: ["--regular", "{{$.hostOrIP}}:{{attributes.port}}"]
49+
}
50+
}
51+
}
52+
];
53+
});
54+
55+
test("should create subsequent scans for open HTTPS ports (NMAP findings)", () => {
56+
const findings = [
57+
{
58+
name: "Port 443 is open",
59+
category: "Open Port",
60+
attributes: {
61+
state: "open",
62+
hostname: "foobar.com",
63+
port: 443,
64+
service: "https"
65+
}
66+
}
67+
];
68+
69+
const cascadedScans = getCascadingScans(
70+
parentScan,
71+
findings,
72+
sslyzeCascadingRules
73+
);
74+
75+
expect(cascadedScans).toMatchInlineSnapshot(`
76+
Array [
77+
Object {
78+
"cascades": null,
79+
"generatedBy": "tls-scans",
80+
"name": "sslyze-foobar.com-tls-scans",
81+
"parameters": Array [
82+
"--regular",
83+
"foobar.com:443",
84+
],
85+
"scanType": "sslyze",
86+
},
87+
]
88+
`);
89+
});
90+
91+
test("Should create no subsequent scans if there are no rules", () => {
92+
const findings = [
93+
{
94+
name: "Port 443 is open",
95+
category: "Open Port",
96+
attributes: {
97+
state: "open",
98+
hostname: "foobar.com",
99+
port: 443,
100+
service: "https"
101+
}
102+
}
103+
];
104+
105+
const cascadingRules = [];
106+
107+
const cascadedScans = getCascadingScans(parentScan, findings, cascadingRules);
108+
109+
expect(cascadedScans).toMatchInlineSnapshot(`Array []`);
110+
});
111+
112+
test("should not try to do magic to the scan name if its something random", () => {
113+
parentScan.metadata.name = "foobar.com";
114+
115+
const findings = [
116+
{
117+
name: "Port 443 is open",
118+
category: "Open Port",
119+
attributes: {
120+
state: "open",
121+
hostname: undefined,
122+
ip_address: "10.42.42.42",
123+
port: 443,
124+
service: "https"
125+
}
126+
}
127+
];
128+
129+
const cascadedScans = getCascadingScans(
130+
parentScan,
131+
findings,
132+
sslyzeCascadingRules
133+
);
134+
135+
expect(cascadedScans).toMatchInlineSnapshot(`
136+
Array [
137+
Object {
138+
"cascades": null,
139+
"generatedBy": "tls-scans",
140+
"name": "foobar.com-tls-scans",
141+
"parameters": Array [
142+
"--regular",
143+
"10.42.42.42:443",
144+
],
145+
"scanType": "sslyze",
146+
},
147+
]
148+
`);
149+
});
150+
151+
test("should not start scan when the cascadingrule for it is already in the chain", () => {
152+
parentScan.metadata.annotations["cascading.securecodebox.io/chain"] =
153+
sslyzeCascadingRules[0].metadata.name;
154+
155+
const findings = [
156+
{
157+
name: "Port 443 is open",
158+
category: "Open Port",
159+
attributes: {
160+
state: "open",
161+
hostname: "foobar.com",
162+
port: 443,
163+
service: "https"
164+
}
165+
}
166+
];
167+
168+
const cascadedScans = getCascadingScans(
169+
parentScan,
170+
findings,
171+
sslyzeCascadingRules
172+
);
173+
174+
expect(cascadedScans).toMatchInlineSnapshot(`Array []`);
175+
});

0 commit comments

Comments
 (0)