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

Commit 4b7a172

Browse files
committed
Add securityContext to nmap
1 parent 4067331 commit 4b7a172

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

scanners/nmap/README.md.gotmpl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,48 @@ Some useful example parameters listed below:
4242
- `-script` xx: Replace xx with the script name. Start the scan with the given script.
4343
- `--script` xx: Replace xx with a coma-separated list of scripts. Start the scan with the given scripts.
4444

45+
## Operating System Scans
46+
47+
:::caution
48+
Warning! This is currently not tested and might require additional testing to work 😕
49+
:::
50+
51+
If you want to use Nmap to identify operating systems of hosts you'll need to weaken the securityContext config, as Nmap requires the capability to send raw sockets to identify operating systems. See [Nmap Docs](https://secwiki.org/w/Running_nmap_as_an_unprivileged_user)
52+
53+
You can deployed the ScanType with the config like this:
54+
55+
```bash
56+
cat <<EOF | helm install nmap-privilidged ./scanners/nmap --values -
57+
scannerJob:
58+
env:
59+
- name: "NMAP_PRIVILEGED"
60+
value: "true"
61+
securityContext:
62+
capabilities:
63+
drop:
64+
- all
65+
add:
66+
- CAP_NET_RAW
67+
- CAP_NET_ADMIN
68+
- CAP_NET_BIND_SERVICE
69+
EOF
70+
```
71+
72+
You the start scans with operating system identification enabled:
73+
74+
```yaml
75+
apiVersion: "execution.experimental.securecodebox.io/v1"
76+
kind: Scan
77+
metadata:
78+
name: "nmap-os-scan"
79+
spec:
80+
scanType: "nmap-privilidged"
81+
parameters:
82+
- --privileged
83+
- "-O"
84+
- www.iteratec.de
85+
```
86+
4587
## Chart Configuration
4688

4789
{{ template "chart.valuesTable" . }}

scanners/nmap/scanner/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM alpine:3.12
22
RUN apk add --no-cache nmap=7.80-r2 nmap-scripts=7.80-r2
3-
RUN addgroup -S nmap && adduser -S -g nmap nmap
4-
USER nmap
3+
RUN addgroup --system --gid 1001 nmap && adduser nmap --system --uid 1001 --ingroup nmap
4+
USER 1001
55
CMD [nmap]

scanners/nmap/templates/nmap-scan-type.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: "execution.experimental.securecodebox.io/v1"
22
kind: ScanType
33
metadata:
4-
name: "nmap"
4+
name: {{ .Release.Name }}
55
spec:
66
extractResults:
77
type: nmap-xml
@@ -19,5 +19,9 @@ spec:
1919
- name: nmap
2020
image: scbexperimental/nmap:7.80
2121
command: ["nmap", "-oX", "/home/securecodebox/nmap-results.xml"]
22+
env:
23+
{{- toYaml .Values.scannerJob.env | nindent 16 }}
2224
resources:
2325
{{- toYaml .Values.scannerJob.resources | nindent 16 }}
26+
securityContext:
27+
{{- toYaml .Values.scannerJob.securityContext | nindent 16 }}

scanners/nmap/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ scannerJob:
3030

3131
# scannerJob.extraContainers -- Optional additional Containers started with each scanJob (see: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/)
3232
extraContainers: []
33+
34+
securityContext:
35+
# scannerJob.securityContext.runAsNonRoot -- Enforces that the scanner image is run as a non root user
36+
runAsNonRoot: true
37+
# scannerJob.securityContext.readOnlyRootFilesystem -- Prevents write access to the containers file system
38+
readOnlyRootFilesystem: true
39+
# scannerJob.securityContext.allowPrivilegeEscalation -- Ensures that users privilidges canout be escalated
40+
allowPrivilegeEscalation: false
41+
# scannerJob.securityContext.privileged -- Ensures that the scanner container is not run in privilidged mode
42+
privileged: false
43+
capabilities:
44+
drop:
45+
# scannerJob.securityContext.capabilities.drop[0] -- This drops all linux privilidges from the container.
46+
- all

0 commit comments

Comments
 (0)