|
30 | 30 | camForm.on('variables-restored', function () { |
31 | 31 | $scope.context = camForm.variableManager.variableValue('PROCESS_CONTEXT'); |
32 | 32 | $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')); |
34 | 34 | $scope.portScannerId = camForm.variableManager.variableValue('PROCESS_SCANNER_ID'); |
35 | 35 |
|
36 | 36 | $scope.firstTarget = $scope.targets[0]; |
37 | 37 | $scope.otherTargetsLength = $scope.targets.length - 1; |
38 | 38 |
|
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 |
48 | 60 | ); |
49 | 61 | }); |
50 | 62 | </script> |
|
79 | 91 | </p> |
80 | 92 | </div> |
81 | 93 |
|
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"> |
85 | 104 | <tr> |
86 | 105 | <th>Host:</th> |
87 | 106 | <th>Port:</th> |
88 | 107 | <th>Name:</th> |
89 | 108 | <th>Protocol:</th> |
90 | 109 | <th>State:</th> |
91 | 110 | </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> |
94 | 113 | <td>{{ (port.category === 'Open Port' || port.category === 'Http Header') ? port.attributes.port : '' }}</td> |
95 | 114 | <td>{{ (port.category === 'Open Port' && !port.name) ? port.attributes.service : port.name}}</td> |
96 | 115 | <td>{{ (port.category === 'Open Port' || port.category === 'Http Header') ? port.attributes.protocol : '' }}</td> |
|
0 commit comments