Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
104dc4f
Add CascadingRule CRD
J12934 Jun 10, 2020
e909d58
#33 Add WIP declarative subsequent hook implementation
J12934 Jun 10, 2020
9ebdd4c
#33 Update templating syntax to mustache / handlebars
J12934 Jun 10, 2020
d8bc027
#33 Regen deepCopy for cascading type
J12934 Jun 10, 2020
8a7786c
#33 Implement Declarative CascadingScans
J12934 Jun 10, 2020
79ca76f
#33 Add ci build for declarative scan hook
J12934 Jun 10, 2020
dde929c
#33 Remove compiled artifact
J12934 Jun 10, 2020
b10f7e8
#33 Compile typescript before executing the tests
J12934 Jun 10, 2020
2a5f537
#33 Ignore compiled typescript file in eslint
J12934 Jun 10, 2020
a080c8f
#33 Generate source map for better code coverage tracking
J12934 Jun 10, 2020
b2b9796
#33 Minor refactor
J12934 Jun 16, 2020
ffb03e2
#33 Introduce a operator which indicates how multiple matchers are co…
J12934 Jun 22, 2020
c4f0c57
#33 Update / Fix post install notes
J12934 Jun 22, 2020
2e2684f
#33 Enable to override the base image
J12934 Jun 22, 2020
fc2b78d
#33 #21 Truncate ending dots
J12934 Jun 22, 2020
9108281
#33 Add CascadingRules to the sslyze scanner
J12934 Jun 22, 2020
80c4dc6
#33 Fix wrong attribute `name` to `scanType`
J12934 Jun 22, 2020
e87b1ea
#33 Improve the names of the generated cascading scans
J12934 Jun 22, 2020
112b45f
#33 Improved the generation of the cascading scans name
J12934 Jun 22, 2020
3e529b3
#33 Remove duplicated dash
J12934 Jun 22, 2020
ec40827
#33 Remove confustion plural notation
J12934 Jun 22, 2020
d9e4be5
#33 Add standard labels to cascading rules
J12934 Jun 22, 2020
3e370df
#33 Add cascading rules for ssh scanner
J12934 Jun 22, 2020
d157746
#33 Add smb cascading rule for nmap
J12934 Jun 24, 2020
dcf63a7
#33 Add missing @types/node dev dependency
J12934 Jun 24, 2020
b5438b4
#33 Optimize gitignore to ignore all typescript source maps
J12934 Jun 24, 2020
37ce445
#33 Correct Docker Build to use typescript source instead of locally …
J12934 Jun 24, 2020
b4da1ee
#33 Ignore eslint for the compiled file
J12934 Jun 24, 2020
d3f24d5
#33 Add loop prevention to stop endless scan cycles
J12934 Jun 24, 2020
917763c
#33 Use actual namespace when starting the scans
J12934 Jun 24, 2020
c983c6d
#33 Ignore the correct file
J12934 Jun 24, 2020
7c27df5
#33 Fix merge conflict
J12934 Jun 25, 2020
3549e9a
#33 Exclude compiled javascript artifacts automatically
J12934 Jun 25, 2020
0b881c2
#33 Add cascading attribute to select cascading rules based on labels
J12934 Jun 25, 2020
ee456ca
#33 Restrict query for CascadingRules by the Scans selector
J12934 Jun 25, 2020
e9bd407
#33 Remove debug log
J12934 Jun 25, 2020
ac57d86
#33 Add cascading rule for zap
J12934 Jun 25, 2020
50e9998
#33 Add CascadingRule for Nikto
J12934 Jun 25, 2020
d532985
#33 Fix expected values for intermediate representation
J12934 Jun 25, 2020
7a02778
#33 Actually ignore the compiled typescript artefacts in eslint
J12934 Jun 25, 2020
8d016ae
#33 Add PrinterColumns for CascadingRules in kubectl
J12934 Jun 25, 2020
66afc7b
#33 Update CRDs included in the helm chart
J12934 Jun 25, 2020
e52d845
#33 Implement CascadingRules for nmap hostscans on amass subdomains
J12934 Jun 25, 2020
b74fd3d
#33 Add test for nmap scanning a port without a predefined port mapping
J12934 Jun 27, 2020
9849818
#33 Fix parser to handle empty service fields
J12934 Jun 27, 2020
ccf2399
#33 Add cascading rule for kube-hunter
J12934 Jun 27, 2020
4ea889b
#33 Also ensure ports are acutally open
J12934 Jun 29, 2020
fa551dd
#33 Use IP Address when Hostname is not set
J12934 Jun 29, 2020
80bbb4e
#33 Add $ attribute to hold special "helper" attributes
J12934 Jun 29, 2020
6b6e1a2
#33 Ensure ports across Cascading Rules are open
J12934 Jun 29, 2020
38eb28c
#33 Use `$.hostOrIP` across CascadingRules
J12934 Jun 29, 2020
e476530
#33 Expand declarative hook test to capture $.hostOrIP helper
J12934 Jun 29, 2020
73ff85a
#33 Throw explicit error when unkown operator was specified
J12934 Jun 29, 2020
fa5536b
#33 Added the why
J12934 Jun 30, 2020
17eef6a
#33 Link Issue in todo
J12934 Jun 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
**/node_modules
**/coverage
**/coverage
hooks/declarative-subsequent-scans/hook.js
hooks/declarative-subsequent-scans/scan-helpers.js
hooks/declarative-subsequent-scans/kubernetes-label-selector.js
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ jobs:
cd -
cd hooks/
npm ci
- name: "Compile Typescript"
run: |
cd hooks/declarative-subsequent-scans
npm run build
- name: "Run tests & publish code coverage"
uses: paambaati/codeclimate-action@v2.6.0
env:
Expand Down Expand Up @@ -248,6 +252,16 @@ jobs:
path: ./hooks/imperative-subsequent-scans/
tag_with_ref: true
build_args: baseImageTag=ci-local
- uses: docker/build-push-action@v1
name: "Build & Push DeclarativeSubsequentScans Hook Image"
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: scbexperimental/hook-declarative-subsequent-scans
path: ./hooks/declarative-subsequent-scans/
tag_with_ref: true
tag_with_sha: true
build_args: baseImageTag=ci-local
- uses: docker/build-push-action@v1
name: "Build & Push UpdateField Hook Image"
with:
Expand Down
1 change: 1 addition & 0 deletions hooks/declarative-subsequent-scans/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
4 changes: 4 additions & 0 deletions hooks/declarative-subsequent-scans/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
*.map
**.js
!**.test.js
30 changes: 30 additions & 0 deletions hooks/declarative-subsequent-scans/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
# Node.js files
node_modules/*
package.json
package-lock.json
src/*
config/*
Dockerfile
.dockerignore
3 changes: 3 additions & 0 deletions hooks/declarative-subsequent-scans/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies: []
digest: sha256:643d5437104296e21d906ecb15b2c96ad278f20cfc4af53b12bb6069bd853726
generated: "2020-05-26T16:56:03.119255+02:00"
11 changes: 11 additions & 0 deletions hooks/declarative-subsequent-scans/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: declarative-subsequent-scans
description: Starts possible subsequent security scans based on findings (e.g. open ports found by NMAP or subdomains found by AMASS).

type: application

version: 0.1.0

appVersion: latest

dependencies: []
19 changes: 19 additions & 0 deletions hooks/declarative-subsequent-scans/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG baseImageTag
FROM node:12-alpine as install
RUN mkdir -p /home/app
WORKDIR /home/app
COPY package.json package-lock.json ./
RUN npm ci --production

FROM node:12-alpine as build
RUN mkdir -p /home/app
WORKDIR /home/app
COPY package.json package-lock.json ./
RUN npm ci
COPY hook.ts scan-helpers.ts kubernetes-label-selector.ts ./
RUN npm run build

FROM scbexperimental/hook-sdk-nodejs:${baseImageTag:-latest}
WORKDIR /home/app/hook-wrapper/hook/
COPY --from=install --chown=app:app /home/app/node_modules/ ./node_modules/
COPY --from=build --chown=app:app /home/app/hook.js /home/app/scan-helpers.js /home/app/kubernetes-label-selector.js ./
175 changes: 175 additions & 0 deletions hooks/declarative-subsequent-scans/hook.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
const { getCascadingScans } = require("./hook");

let parentScan = undefined;
let sslyzeCascadingRules = undefined;

beforeEach(() => {
parentScan = {
apiVersion: "execution.experimental.securecodebox.io/v1",
kind: "Scan",
metadata: {
name: "nmap-foobar.com",
annotations: {}
},
spec: {
scanType: "nmap",
parameters: "foobar.com",
cascades: {}
}
};

sslyzeCascadingRules = [
{
apiVersion: "cascading.experimental.securecodebox.io/v1",
kind: "CascadingRule",
metadata: {
name: "tls-scans"
},
spec: {
matches: {
anyOf: [
{
category: "Open Port",
attributes: {
port: 443,
service: "https"
}
},
{
category: "Open Port",
attributes: {
service: "https"
}
}
]
},
scanSpec: {
scanType: "sslyze",
parameters: ["--regular", "{{$.hostOrIP}}:{{attributes.port}}"]
}
}
}
];
});

test("should create subsequent scans for open HTTPS ports (NMAP findings)", () => {
const findings = [
{
name: "Port 443 is open",
category: "Open Port",
attributes: {
state: "open",
hostname: "foobar.com",
port: 443,
service: "https"
}
}
];

const cascadedScans = getCascadingScans(
parentScan,
findings,
sslyzeCascadingRules
);

expect(cascadedScans).toMatchInlineSnapshot(`
Array [
Object {
"cascades": null,
"generatedBy": "tls-scans",
"name": "sslyze-foobar.com-tls-scans",
"parameters": Array [
"--regular",
"foobar.com:443",
],
"scanType": "sslyze",
},
]
`);
});

test("Should create no subsequent scans if there are no rules", () => {
const findings = [
{
name: "Port 443 is open",
category: "Open Port",
attributes: {
state: "open",
hostname: "foobar.com",
port: 443,
service: "https"
}
}
];

const cascadingRules = [];

const cascadedScans = getCascadingScans(parentScan, findings, cascadingRules);

expect(cascadedScans).toMatchInlineSnapshot(`Array []`);
});

test("should not try to do magic to the scan name if its something random", () => {
parentScan.metadata.name = "foobar.com";

const findings = [
{
name: "Port 443 is open",
category: "Open Port",
attributes: {
state: "open",
hostname: undefined,
ip_address: "10.42.42.42",
port: 443,
service: "https"
}
}
];

const cascadedScans = getCascadingScans(
parentScan,
findings,
sslyzeCascadingRules
);

expect(cascadedScans).toMatchInlineSnapshot(`
Array [
Object {
"cascades": null,
"generatedBy": "tls-scans",
"name": "foobar.com-tls-scans",
"parameters": Array [
"--regular",
"10.42.42.42:443",
],
"scanType": "sslyze",
},
]
`);
});

test("should not start scan when the cascadingrule for it is already in the chain", () => {
parentScan.metadata.annotations["cascading.securecodebox.io/chain"] =
sslyzeCascadingRules[0].metadata.name;

const findings = [
{
name: "Port 443 is open",
category: "Open Port",
attributes: {
state: "open",
hostname: "foobar.com",
port: 443,
service: "https"
}
}
];

const cascadedScans = getCascadingScans(
parentScan,
findings,
sslyzeCascadingRules
);

expect(cascadedScans).toMatchInlineSnapshot(`Array []`);
});
Loading