Skip to content

Commit 41fb8d9

Browse files
author
dreizehnutters
committed
added QoL features
1 parent 9719448 commit 41fb8d9

3 files changed

Lines changed: 51 additions & 15 deletions

File tree

xsl/assets/visualizations-matrix.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5875
function 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() {
769789
window.renderMatrixVisualizations = renderMatrixVisualizations;
770790

771791
document.addEventListener("DOMContentLoaded", function() {
792+
initializePortHostMatrixControls();
772793
renderMatrixVisualizations();
773794
});

xsl/assets/visualizations.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@
221221
margin-bottom: 0.55rem;
222222
}
223223

224+
.visualization-actions-split {
225+
justify-content: space-between;
226+
align-items: center;
227+
gap: 0.75rem;
228+
flex-wrap: wrap;
229+
}
230+
231+
.visualization-actions-split .form-check {
232+
margin-right: auto;
233+
}
234+
224235
.visualization-empty {
225236
margin-top: 1rem;
226237
}

xsl/visualizations.xsl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,15 @@
126126
<summary class="visualization-card-summary">
127127
<div class="visualization-card-header">
128128
<h4 class="visualization-card-title">Host-Port Matrix</h4>
129-
<p class="visualization-card-note">See which ports appear on which hosts and spot unusual exposure patterns. The 95th percentile of uncommon ports from the scan data is highlighted.</p>
129+
<p class="visualization-card-note">See which ports appear on which hosts and spot unusual exposure patterns.</p>
130130
</div>
131131
</summary>
132132
<div class="visualization-card-body">
133-
<div class="visualization-actions">
133+
<div class="visualization-actions visualization-actions-split">
134+
<div class="form-check form-switch mb-0">
135+
<input type="checkbox" class="form-check-input" id="portHostPercentileToggle"/>
136+
<label class="form-check-label small" for="portHostPercentileToggle">Mark 95th percentile uncommon ports</label>
137+
</div>
134138
<button type="button" class="btn btn-sm btn-outline-secondary" data-plot-export="portHostMatrix">Export</button>
135139
</div>
136140
<div class="visualization-scroll-x">

0 commit comments

Comments
 (0)