@@ -55,6 +55,23 @@ function buildScopedMatrixData() {
5555 } ;
5656}
5757
58+ function isPortHostPercentileHighlightEnabled ( ) {
59+ const toggle = document . getElementById ( "portHostPercentileToggle" ) ;
60+ return Boolean ( toggle && toggle . checked ) ;
61+ }
62+
63+ function initializePortHostMatrixControls ( ) {
64+ const toggle = document . getElementById ( "portHostPercentileToggle" ) ;
65+ if ( ! toggle || toggle . dataset . initialized === "true" ) {
66+ return ;
67+ }
68+
69+ toggle . addEventListener ( "change" , ( ) => {
70+ renderMatrixVisualizations ( ) ;
71+ } ) ;
72+ toggle . dataset . initialized = "true" ;
73+ }
74+
5875function renderPortHostMatrix ( hosts , ports , openServices , matrixConfig ) {
5976 const portHostMatrix = document . getElementById ( "portHostMatrix" ) ;
6077 if ( ! portHostMatrix ) {
@@ -67,6 +84,7 @@ function renderPortHostMatrix(hosts, ports, openServices, matrixConfig) {
6784 }
6885
6986 const fixedPercentile = 0.95 ;
87+ const highlightPercentile = isPortHostPercentileHighlightEnabled ( ) ;
7088 const sortedHosts = [ ...hosts ] . sort ( ( a , b ) => a . localeCompare ( b , undefined , {
7189 numeric : true ,
7290 sensitivity : "base"
@@ -124,8 +142,12 @@ function renderPortHostMatrix(hosts, ports, openServices, matrixConfig) {
124142 ...getPlotLayoutTheme ( )
125143 } ;
126144
127- const anomalyHostThreshold = calculatePercentile ( hostCountValues , fixedPercentile ) ;
128- const anomalyPortThreshold = calculatePercentile ( portCountValues , fixedPercentile ) ;
145+ const anomalyHostThreshold = highlightPercentile
146+ ? calculatePercentile ( hostCountValues , fixedPercentile )
147+ : 0 ;
148+ const anomalyPortThreshold = highlightPercentile
149+ ? calculatePercentile ( portCountValues , fixedPercentile )
150+ : 0 ;
129151 const z = sortedHosts . map ( host =>
130152 ports . map ( port => {
131153 const serviceName = openServices [ host ] [ port ] ;
@@ -135,7 +157,7 @@ function renderPortHostMatrix(hosts, ports, openServices, matrixConfig) {
135157
136158 const portHostCount = portHostCounts [ port ] || 0 ;
137159 const hostServiceCount = hostServiceCounts [ host ] || 0 ;
138- if ( portHostCount <= anomalyPortThreshold && hostServiceCount <= anomalyHostThreshold ) {
160+ if ( highlightPercentile && portHostCount <= anomalyPortThreshold && hostServiceCount <= anomalyHostThreshold ) {
139161 return 3 ;
140162 }
141163
@@ -152,17 +174,15 @@ function renderPortHostMatrix(hosts, ports, openServices, matrixConfig) {
152174 openServices [ host ] [ port ] || "No open service" ,
153175 openServices [ host ] [ port ] ? String ( hostServiceCounts [ host ] || 0 ) : "0" ,
154176 openServices [ host ] [ port ] ? String ( portHostCounts [ port ] || 0 ) : "0" ,
155- openServices [ host ] [ port ] ? String ( anomalyHostThreshold ) : "0" ,
156- openServices [ host ] [ port ] ? String ( anomalyPortThreshold ) : "0" ,
157177 openServices [ host ] [ port ]
158178 ? ( ( ) => {
159- const portHostCount = portHostCounts [ port ] || 0 ;
160- const hostServiceCount = hostServiceCounts [ host ] || 0 ;
161- if ( portHostCount <= anomalyPortThreshold && hostServiceCount <= anomalyHostThreshold ) {
162- return "Port anomaly " ;
163- }
164- return "Common port exposure " ;
165- } ) ( )
179+ const portHostCount = portHostCounts [ port ] || 0 ;
180+ const hostServiceCount = hostServiceCounts [ host ] || 0 ;
181+ if ( highlightPercentile && portHostCount <= anomalyPortThreshold && hostServiceCount <= anomalyHostThreshold ) {
182+ return "95th percentile uncommon port " ;
183+ }
184+ return "Open service " ;
185+ } ) ( )
166186 : "No open service"
167187 ] )
168188 ) ;
@@ -187,7 +207,7 @@ function renderPortHostMatrix(hosts, ports, openServices, matrixConfig) {
187207 xgap : 2 ,
188208 ygap : 2 ,
189209 hoverongaps : false ,
190- hovertemplate : "Host: %{customdata[0]}<br>Port: %{customdata[1]}<br>Service: %{customdata[2]}<br>Open services on host: %{customdata[3]}<br>Hosts with port: %{customdata[4]}<extra></extra>" ,
210+ hovertemplate : "Host: %{customdata[0]}<br>Port: %{customdata[1]}<br>Service: %{customdata[2]}<br>Open services on host: %{customdata[3]}<br>Hosts with port: %{customdata[4]}<br>Status: %{customdata[5]}< extra></extra>" ,
191211 text : zText
192212 } ] ;
193213
@@ -769,5 +789,6 @@ function renderMatrixVisualizations() {
769789window . renderMatrixVisualizations = renderMatrixVisualizations ;
770790
771791document . addEventListener ( "DOMContentLoaded" , function ( ) {
792+ initializePortHostMatrixControls ( ) ;
772793 renderMatrixVisualizations ( ) ;
773794} ) ;
0 commit comments