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

Commit d157746

Browse files
committed
#33 Add smb cascading rule for nmap
1 parent 3e370df commit d157746

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

hooks/declarative-subsequent-scans/hook.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ interface ExtendedScanSpec extends ScanSpec {
4444
// This is the name of the scan. Its not "really" part of the scan spec
4545
// But this makes the object smaller
4646
name: string;
47+
48+
// Indicates which CascadingRule was used to generate the resulting Scan
49+
generatedBy: string;
4750
}
4851

4952
interface HandleArgs {
@@ -57,10 +60,11 @@ export async function handle({ scan, getFindings }: HandleArgs) {
5760

5861
const cascadingScans = getCascadingScans(scan, findings, cascadingRules);
5962

60-
for (const { name, scanType, parameters } of cascadingScans) {
63+
for (const { name, scanType, parameters, generatedBy } of cascadingScans) {
6164
await startSubsequentSecureCodeBoxScan({
6265
name,
6366
parentScan: scan,
67+
generatedBy,
6468
scanType,
6569
parameters,
6670
});
@@ -99,6 +103,7 @@ export function getCascadingScans(
99103
parameters: parameters.map((parameter) =>
100104
Mustache.render(parameter, finding)
101105
),
106+
generatedBy: cascadingRule.metadata.name,
102107
});
103108
}
104109
}

hooks/declarative-subsequent-scans/scan-helpers.js renamed to hooks/declarative-subsequent-scans/scan-helpers.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const k8s = require("@kubernetes/client-node");
1+
import * as k8s from "@kubernetes/client-node";
22

33
// configure k8s client
44
const kc = new k8s.KubeConfig();
@@ -11,6 +11,7 @@ async function startSubsequentSecureCodeBoxScan({
1111
parentScan,
1212
scanType,
1313
parameters,
14+
generatedBy,
1415
}) {
1516
const scanDefinition = {
1617
apiVersion: "execution.experimental.securecodebox.io/v1",
@@ -21,8 +22,9 @@ async function startSubsequentSecureCodeBoxScan({
2122
...parentScan.metadata.labels,
2223
},
2324
annotations: {
24-
"securecodebox.io/hook": "nmap-subsequent-scans",
25+
"securecodebox.io/hook": "declarative-subsequent-scans",
2526
"securecodebox.io/parent-scan": parentScan.metadata.name,
27+
"cascading.securecodebox.io/generated-by": generatedBy,
2628
},
2729
ownerReferences: [
2830
{
@@ -80,3 +82,28 @@ async function getCascadingRulesFromCluster() {
8082
}
8183
}
8284
module.exports.getCascadingRulesFromCluster = getCascadingRulesFromCluster;
85+
86+
enum LabelSelectorRequirementOperator {
87+
In,
88+
NotIn,
89+
Exists,
90+
DoesNotExist,
91+
}
92+
93+
// See: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#labelselectorrequirement-v1-meta
94+
// Re created in TS because the included types suck 😕
95+
interface LabelSelectorRequirement {
96+
key: string;
97+
values: string;
98+
99+
operator: LabelSelectorRequirementOperator;
100+
}
101+
102+
function generateLabelSelectorString(
103+
matchExpression: Array<LabelSelectorRequirement>,
104+
matchLabels: Map<string, string>
105+
): string {
106+
// Convert matchLabels to matchExpression syntax
107+
matchExpression;
108+
return "";
109+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: "cascading.experimental.securecodebox.io/v1"
2+
kind: CascadingRule
3+
metadata:
4+
name: "nmap-smb"
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+
port: 445
14+
- category: "Open Port"
15+
attributes:
16+
service: "microsoft-ds"
17+
- category: "Open Port"
18+
attributes:
19+
service: "netbios-ssn"
20+
scanSpec:
21+
scanType: "nmap"
22+
parameters:
23+
# Treat all hosts as online -- skip host discovery
24+
- "-Pn"
25+
# Target Port of the finding
26+
- "-p{{attributes.port}}"
27+
# Use SMB Script
28+
- "--script"
29+
- "smb-protocols"
30+
# Against Host
31+
- "{{attributes.hostname}}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The CascadingRules are not directly in the /templates directory as their curly bracket syntax clashes with helms templates ... :(
2+
# We import them as raw files to avoid these clashes as escaping them is even more messy
3+
{{ range $path, $_ := .Files.Glob "cascading-rules/*" }}
4+
# Include File
5+
{{ $.Files.Get $path }}
6+
# Separate multiple files
7+
---
8+
{{ end }}

0 commit comments

Comments
 (0)