Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Commit 5283224

Browse files
authored
Merge pull request #97 from secureCodeBox/fix/nmap-host-without-port
Correctly display nmap host without port in result form
2 parents 75c1e22 + bb89446 commit 5283224

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

scb-scanprocesses/nmap-process/src/main/resources/forms/nmap/approve-port-scanner-results.html

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,33 @@
3030
camForm.on('variables-restored', function () {
3131
$scope.context = camForm.variableManager.variableValue('PROCESS_CONTEXT');
3232
$scope.targets = JSON.parse(camForm.variableManager.variableValue('PROCESS_TARGETS'));
33-
$scope.portScannerResult = JSON.parse(camForm.variableManager.variableValue('PROCESS_FINDINGS'));
33+
const portScannerResult = JSON.parse(camForm.variableManager.variableValue('PROCESS_FINDINGS'));
3434
$scope.portScannerId = camForm.variableManager.variableValue('PROCESS_SCANNER_ID');
3535

3636
$scope.firstTarget = $scope.targets[0];
3737
$scope.otherTargetsLength = $scope.targets.length - 1;
3838

39-
$scope.groupedResults = $scope.portScannerResult.reduce(
40-
function (carry, item) {
41-
if (!carry.hasOwnProperty(item.attributes.hostname)) {
42-
carry[item.attributes.hostname] = [];
43-
}
44-
carry[item.attributes.hostname].push(item);
45-
return carry;
46-
},
47-
{}
39+
const openPorts = portScannerResult.filter((finding) => finding.category === 'Open Port');
40+
const hosts = portScannerResult.filter((finding) => finding.category === 'Host');
41+
42+
$scope.groupedResults = {};
43+
44+
for(const host of hosts){
45+
$scope.groupedResults[host.attributes.ip_address] = { hostname: host.attributes.hostname, ports: [] };
46+
}
47+
48+
$scope.groupedResults = openPorts.reduce(
49+
function (carry, item) {
50+
console.log(item);
51+
if (!carry.hasOwnProperty(item.attributes.ip_address)) {
52+
carry[item.attributes.ip_address] = { hostname: item.attributes.hostname, ports: [] };
53+
}
54+
if(item.attributes.ip_address !== null){
55+
carry[item.attributes.ip_address].ports.push(item);
56+
}
57+
return carry;
58+
},
59+
$scope.groupedResults
4860
);
4961
});
5062
</script>
@@ -79,18 +91,25 @@ <h2>
7991
</p>
8092
</div>
8193

82-
<div class="well well-sm" style="color: inherit;" ng-repeat="(address, host) in groupedResults">
83-
<strong>Results for Host: {{ address }}</strong>
84-
<table class="table table-striped">
94+
<div class="well well-sm" style="color: inherit;" ng-repeat="(ip, host) in groupedResults">
95+
<strong>
96+
Results for Host:
97+
<span>{{ ip }}</span>
98+
<span ng-if="host.hostname">({{host.hostname}})</span>
99+
</strong>
100+
<span class="table table-striped" ng-if="host.ports.length === 0">
101+
No ports identified for this host.
102+
</span>
103+
<table class="table table-striped" ng-if="host.ports.length > 0">
85104
<tr>
86105
<th>Host:</th>
87106
<th>Port:</th>
88107
<th>Name:</th>
89108
<th>Protocol:</th>
90109
<th>State:</th>
91110
</tr>
92-
<tr class="danger" ng-repeat="port in host">
93-
<td>{{ address }} ({{ port.attributes.ip_address }})</td></td>
111+
<tr class="danger" ng-repeat="port in host.ports">
112+
<td>{{ port.attributes.ip_address }}</td></td>
94113
<td>{{ (port.category === 'Open Port' || port.category === 'Http Header') ? port.attributes.port : '' }}</td>
95114
<td>{{ (port.category === 'Open Port' && !port.name) ? port.attributes.service : port.name}}</td>
96115
<td>{{ (port.category === 'Open Port' || port.category === 'Http Header') ? port.attributes.protocol : '' }}</td>

0 commit comments

Comments
 (0)