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

Commit 08903ca

Browse files
committed
Improved imperative scan to respect the correct identified ports for each subsequent scan.
1 parent 73e775a commit 08903ca

File tree

2 files changed

+126
-20
lines changed

2 files changed

+126
-20
lines changed

hooks/imperative-subsequent-scans/hook.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function handle({
4343
cascadeNmapNikto &&
4444
finding.attributes.service === "http"
4545
) {
46-
await startNiktoScan({
46+
await startNiktoHttpScan({
4747
parentScan: scan,
4848
hostname,
4949
port,
@@ -82,7 +82,7 @@ async function handle({
8282
(finding.attributes.service === "ssl" ||
8383
finding.attributes.service === "https")
8484
) {
85-
await startZAPBaselineScan({
85+
await startZAPBaselineHttpsScan({
8686
parentScan: scan,
8787
hostname,
8888
port,
@@ -167,14 +167,14 @@ async function startNMAPScan({ parentScan, hostname}) {
167167
* @param {string} hostname The hostname to start a new subsequent ZAP scan for.
168168
* @param {string} port The port to start a new subsequent ZAP scan for.
169169
*/
170-
async function startZAPBaselineScan({ parentScan, hostname, port }) {
170+
async function startZAPBaselineHttpsScan({ parentScan, hostname, port }) {
171171
console.log(
172172
" --> Starting async subsequent ZAP Scan for host: " + hostname + ":" + port
173173
);
174174

175175
await startSubsequentSecureCodeBoxScan({
176176
parentScan,
177-
name: `zap-${hostname.toLowerCase()}`,
177+
name: `zap-https-${hostname.toLowerCase()}`,
178178
scanType: "zap-baseline",
179179
parameters: ["-t", "https://" + hostname + ":" + port],
180180
});
@@ -194,7 +194,7 @@ async function startSSHScan({ parentScan, hostname, port }) {
194194
parentScan,
195195
name: `ssh-${hostname.toLowerCase()}`,
196196
scanType: "ssh-scan",
197-
parameters: ["-t", hostname],
197+
parameters: ["-t", hostname, "-p", port.toString()],
198198
});
199199
}
200200

@@ -203,16 +203,16 @@ async function startSSHScan({ parentScan, hostname, port }) {
203203
* @param {string} hostname The hostname to start a new subsequent Nikto scan for.
204204
* @param {string} port The port to start a new subsequent Nikto scan for.
205205
*/
206-
async function startNiktoScan({ parentScan, hostname, port }) {
206+
async function startNiktoHttpScan({ parentScan, hostname, port }) {
207207
console.log(
208208
" --> Starting async subsequent Nikto Scan for host: " + hostname + ":" + port
209209
);
210210

211211
await startSubsequentSecureCodeBoxScan({
212212
parentScan,
213-
name: `nikto-${hostname.toLowerCase()}`,
213+
name: `nikto-http-${hostname.toLowerCase()}`,
214214
scanType: "nikto",
215-
parameters: ["-h", "https://" + hostname, "-Tuning", "1,2,3,5,7,b"],
215+
parameters: ["-h", "http://" + hostname, "-p", port.toString(), "-Tuning", "1,2,3,5,7,b"],
216216
});
217217
}
218218

@@ -230,7 +230,7 @@ async function startSSLyzeScan({ parentScan, hostname, port }) {
230230
parentScan,
231231
name: `sslyze-${hostname.toLowerCase()}`,
232232
scanType: "sslyze",
233-
parameters: ["--regular", hostname],
233+
parameters: ["--regular", hostname+":"+port],
234234
});
235235
}
236236

hooks/imperative-subsequent-scans/hook.test.js

Lines changed: 117 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ test("Should create subsequent scans for open HTTPS ports (NMAP findings)", asyn
5959

6060
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(1, {
6161
name: "sslyze-foobar.com",
62-
parameters: ["--regular", "foobar.com"],
62+
parameters: ["--regular", "foobar.com:443"],
6363
parentScan: { metadata: { labels: { foo: "bar" } } },
6464
scanType: "sslyze",
6565
});
6666
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(2, {
67-
name: "zap-foobar.com",
67+
name: "zap-https-foobar.com",
6868
parameters: ["-t", "https://foobar.com:443"],
6969
parentScan: { metadata: { labels: { foo: "bar" } } },
7070
scanType: "zap-baseline",
7171
});
72-
// even if the HTTP port is not running at port 80 a corresponding Nikto scan should be created if a HTTP service is found by nmap
72+
// even if the HTTPS port is not running at port 443 a corresponding Sslyze scan should be created if a HTTP service is found by nmap
7373
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(3, {
7474
name: "sslyze-example.com",
75-
parameters: ["--regular", "example.com"],
75+
parameters: ["--regular", "example.com:8443"],
7676
parentScan: { metadata: { labels: { foo: "bar" } } },
7777
scanType: "sslyze",
7878
});
7979
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(4, {
80-
name: "zap-example.com",
80+
name: "zap-https-example.com",
8181
parameters: ["-t", "https://example.com:8443"],
8282
parentScan: { metadata: { labels: { foo: "bar" } } },
8383
scanType: "zap-baseline",
@@ -139,15 +139,15 @@ test("Should create subsequent scans for open HTTP ports (NMAP findings)", async
139139
expect(startSubsequentSecureCodeBoxScan).toHaveBeenCalledTimes(6);
140140

141141
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(5, {
142-
name: "nikto-foobar.com",
143-
parameters: ["-h", "https://foobar.com", "-Tuning", "1,2,3,5,7,b"],
142+
name: "nikto-http-foobar.com",
143+
parameters: ["-h", "http://foobar.com", "-p", "80", "-Tuning", "1,2,3,5,7,b"],
144144
parentScan: { metadata: { labels: { foo: "bar" } } },
145145
scanType: "nikto",
146146
});
147147
// even if the HTTP port is not running at port 80 a corresponding Nikto scan should be created if a HTTP service is found by nmap
148148
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(6, {
149-
name: "nikto-example.com",
150-
parameters: ["-h", "https://example.com", "-Tuning", "1,2,3,5,7,b"],
149+
name: "nikto-http-example.com",
150+
parameters: ["-h", "http://example.com", "-p", "3000", "-Tuning", "1,2,3,5,7,b"],
151151
parentScan: { metadata: { labels: { foo: "bar" } } },
152152
scanType: "nikto",
153153
});
@@ -209,14 +209,14 @@ test("Should create subsequent scans for open SSH ports (NMAP findings)", async
209209

210210
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(7, {
211211
name: "ssh-foobar.com",
212-
parameters: ["-t", "foobar.com"],
212+
parameters: ["-t", "foobar.com", "-p", "22"],
213213
parentScan: { metadata: { labels: { foo: "bar" } } },
214214
scanType: "ssh-scan",
215215
});
216216
// even if the HTTP port is not running at port 80 a corresponding Nikto scan should be created if a HTTP service is found by nmap
217217
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(8, {
218218
name: "ssh-example.com",
219-
parameters: ["-t", "example.com"],
219+
parameters: ["-t", "example.com", "-p", "23454"],
220220
parentScan: { metadata: { labels: { foo: "bar" } } },
221221
scanType: "ssh-scan",
222222
});
@@ -581,4 +581,110 @@ test("Should not create subsequent scans if no subsequent scan is activated", as
581581
});
582582

583583
expect(startSubsequentSecureCodeBoxScan).toHaveBeenCalledTimes(12);
584+
});
585+
586+
test("Should create subsequent scans for Service which are running in custom ports", async () => {
587+
const findings = [
588+
{
589+
name: "Port 22000 is open",
590+
category: "Open Port",
591+
attributes: {
592+
state: "open",
593+
hostname: "ssh.example.com",
594+
port: 22000,
595+
service: "ssh",
596+
},
597+
},
598+
{
599+
name: "Port 8000 is open",
600+
category: "Open Port",
601+
attributes: {
602+
state: "open",
603+
hostname: "http.example.com",
604+
port: 8000,
605+
service: "http",
606+
},
607+
},
608+
{
609+
name: "Port 3000 is open",
610+
category: "Open Port",
611+
attributes: {
612+
state: "open",
613+
hostname: "https.example.com",
614+
port: 3000,
615+
service: "https",
616+
},
617+
},
618+
{
619+
name: "Port 8443 is open",
620+
category: "Open Port",
621+
attributes: {
622+
state: "open",
623+
hostname: "ssl.example.com",
624+
port: 8443,
625+
service: "ssl",
626+
},
627+
}
628+
];
629+
630+
const scan = {
631+
metadata: {
632+
labels: {
633+
foo: "bar",
634+
},
635+
},
636+
};
637+
638+
const cascadeAmassNmap = true;
639+
const cascadeNmapSsl = true;
640+
const cascadeNmapSsh = true;
641+
const cascadeNmapNikto = true;
642+
const cascadeNmapSmb = true;
643+
const cascadeNmapZapBaseline = true;
644+
645+
const getFindings = async () => findings;
646+
647+
await handle({
648+
getFindings,
649+
scan,
650+
cascadeAmassNmap,
651+
cascadeNmapSsl,
652+
cascadeNmapSsh,
653+
cascadeNmapNikto,
654+
cascadeNmapSmb,
655+
cascadeNmapZapBaseline
656+
});
657+
658+
expect(startSubsequentSecureCodeBoxScan).toHaveBeenCalledTimes(18);
659+
660+
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(13, {
661+
name: "ssh-ssh.example.com",
662+
parameters: ["-t", "ssh.example.com", "-p", "22000"],
663+
parentScan: { metadata: { labels: { foo: "bar" } } },
664+
scanType: "ssh-scan",
665+
});
666+
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(14, {
667+
name: "nikto-http-http.example.com",
668+
parameters: ["-h", "http://http.example.com", "-p", "8000", "-Tuning", "1,2,3,5,7,b"],
669+
parentScan: { metadata: { labels: { foo: "bar" } } },
670+
scanType: "nikto",
671+
});
672+
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(15, {
673+
name: "sslyze-https.example.com",
674+
parameters: ["--regular", "https.example.com:3000"],
675+
parentScan: { metadata: { labels: { foo: "bar" } } },
676+
scanType: "sslyze",
677+
});
678+
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(16, {
679+
name: "zap-https-https.example.com",
680+
parameters: ["-t", "https://https.example.com:3000"],
681+
parentScan: { metadata: { labels: { foo: "bar" } } },
682+
scanType: "zap-baseline",
683+
});
684+
expect(startSubsequentSecureCodeBoxScan).toHaveBeenNthCalledWith(17, {
685+
name: "sslyze-ssl.example.com",
686+
parameters: ["--regular", "ssl.example.com:8443"],
687+
parentScan: { metadata: { labels: { foo: "bar" } } },
688+
scanType: "sslyze",
689+
});
584690
});

0 commit comments

Comments
 (0)