Repository navigation
Expand file tree
/
Copy pathheader.html
More file actions
1469 lines (1431 loc) · 68.4 KB
/
Copy pathheader.html
File metadata and controls
1469 lines (1431 loc) · 68.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>External Attack Surface Analysis</title>
<!-- Chart.js for charts -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
/* Root CSS variables for theme colors and font sizes */
:root {
/* Light theme colors */
--light-bg-color: #f9f9f9;
--light-text-color: #333;
--light-header-bg: #fff;
--light-header-text: #333;
--light-table-bg: #fff;
--light-table-header-bg: #eee;
--light-table-border: #ddd;
--light-toggle-bg: #757574;
--light-toggle-btn: #fff;
/* Dark theme colors */
--dark-bg-color: #1f1f1f;
--dark-text-color: #f0f0f0;
--dark-header-bg: #2a2a2a;
--dark-header-text: #ffffff;
--dark-table-bg: #2a2a2a;
--dark-table-header-bg: #3a3a3a;
--dark-table-border: #444;
--dark-toggle-bg: #555;
--dark-toggle-btn: #ffffff;
/* Active theme variables (default to light) */
--bg-color: var(--light-bg-color);
--text-color: var(--light-text-color);
--header-bg: var(--light-header-bg);
--header-text: var(--light-header-text);
--table-bg: var(--light-table-bg);
--table-header-bg: var(--light-table-header-bg);
--table-border: var(--light-table-border);
--toggle-bg: var(--light-toggle-bg);
--toggle-btn: var(--light-toggle-btn);
/* Font sizing variables */
--font-size-sm: 12px;
--font-size-base: 13px;
--font-size-md: 14px;
--font-size-lg: 16px;
--heading-font-size: 22px;
}
/* Dark theme override */
body.dark {
--bg-color: var(--dark-bg-color);
--text-color: var(--dark-text-color);
--header-bg: var(--dark-header-bg);
--header-text: var(--dark-header-text);
--table-bg: var(--dark-table-bg);
--table-header-bg: var(--dark-table-header-bg);
--table-border: var(--dark-table-border);
--toggle-bg: var(--dark-toggle-bg);
--toggle-btn: var(--dark-toggle-btn);
}
/* Basic styles for body and fonts */
body {
margin: 0;
background-color: var(--bg-color);
color: var(--text-color);
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
font-size: var(--font-size-base);
line-height: 1.4;
}
/* HEADER styles */
.header {
position: relative;
background-color: var(--header-bg);
color: var(--header-text);
text-align: center;
padding: 12px 20px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.table-container {
width: 100%;
max-height: 500px;
overflow-x: auto;
overflow-y: auto;
margin-top: 10px;
}
.header h1 {
margin: 0;
}
.toggle-btn, .csv-btn {
position: absolute;
background-color: var(--toggle-bg);
border: none;
color: var(--toggle-btn);
cursor: pointer;
border-radius: 4px;
font-size: var(--font-size-md);
}
.toggle-btn {
right: 20px;
top: 12px;
transition: background-color 0.2s, color 0.2s;
}
.csv-btn {
right: 20px;
top: 35px;
transition: background-color 0.5s, color 0.2s;
}
.toggle-btn:hover {
opacity: 0.9;
}
/* Top controls for table filters and pagination */
.table-top-controls {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
/* Container for the entire report */
.container {
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
/* Scoreboard styles for summary cards */
.scoreboard {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 20px;
}
.score-card {
background-color: var(--table-bg);
border: 1px solid var(--table-border);
border-radius: 5px;
flex: 1 1 200px;
padding: 10px;
text-align: center;
}
.score-card h2 {
margin: 0;
font-size: 1.6em;
font-weight: 500;
}
.score-card p {
margin: 5px 0 0;
font-size: var(--font-size-sm);
color: var(--text-color);
}
.hint {
color: red;
}
/* Grid layout for charts */
.charts-grid {
display: grid;
gap: 10px;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
margin-bottom: 20px;
}
.chart-container {
position: relative;
background-color: var(--table-bg);
border: 1px solid var(--table-border);
border-radius: 5px;
padding: 10px;
box-sizing: border-box;
}
.chart-container canvas {
display: block;
width: 100% !important;
height: 100% !important;
}
/* Search box styling */
#searchBox {
margin: 0;
padding: 6px 10px;
width: 250px;
font-size: var(--font-size-sm);
border: 1px solid var(--table-border);
border-radius: 4px;
}
/* Table controls styling */
.table-controls {
margin: 0;
display: flex;
justify-content: flex-end;
align-items: center;
}
.table-controls label {
margin-right: 6px;
font-size: var(--font-size-sm);
}
.table-controls select {
font-size: var(--font-size-sm);
padding: 4px 8px;
border: 1px solid var(--table-border);
border-radius: 4px;
background-color: var(--table-bg);
color: var(--text-color);
}
/* Main table styling */
table {
border-collapse: separate;
border-spacing: 0;
width: 100%;
background-color: var(--table-bg);
font-size: var(--font-size-sm);
}
table thead tr {
position: sticky;
z-index: 10;
background-color: var(--table-header-bg);
}
table thead tr:first-child {
top: 0;
}
table thead tr:nth-child(2) {
top: 61px;
}
th, td {
border: 1px solid var(--table-border);
padding: 8px;
text-align: left;
vertical-align: top;
color: inherit;
}
th {
background-color: var(--table-header-bg);
font-weight: 600;
}
/* Filter dropdown styling in table header */
#filter-row select {
width: 100%;
font-size: var(--font-size-sm);
padding: 2px 4px;
border: 1px solid var(--table-border);
border-radius: 3px;
background-color: var(--table-bg);
color: var(--text-color);
}
/* Pagination controls styling */
#paginationControls {
margin-top: 10px;
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}
#paginationControls button {
padding: 6px 12px;
cursor: pointer;
font-size: var(--font-size-sm);
border-radius: 4px;
border: 1px solid var(--table-border);
background-color: var(--toggle-bg);
color: var(--toggle-btn);
transition: background-color 0.2s, color 0.2s;
}
#paginationControls button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
/* Ensure proper display for the last header column */
th:nth-child(33) {
white-space: nowrap;
}
/* Thumbnail styling for screenshots */
.thumbnail {
width: 150px;
height: 150px;
cursor: pointer;
border: 1px solid #ccc;
border-radius: 4px;
}
/* Modal styling */
#screenshotModal {
display: none;
position: fixed;
z-index: 9999;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.75);
}
#screenshotModalContent {
position: relative;
margin: 5% auto;
width: 80%;
max-width: 900px;
background-color: #fff;
padding: 10px;
border-radius: 4px;
}
#screenshotModalImg {
width: 100%;
height: auto;
display: block;
}
#closeModalBtn {
position: absolute;
top: 5px;
right: 10px;
background: #444;
color: #fff;
border: none;
border-radius: 3px;
padding: 5px 8px;
cursor: pointer;
}
</style>
<!-- Global screenshot map definition -->
<!-- Screenshot map placeholder; the actual data will be inserted by the build_html_report function -->
<script>
// The screenshot map data will be injected below:
const screenshotMap =
%%SCREENSHOT_MAP%%
;
</script>
</head>
<body>
<!-- Header section with title and theme toggle button -->
<div class="header">
<h1>External Attack Surface Analysis Report</h1>
<button id="themeToggle" class="toggle-btn">DARK THEME</button>
<button id="exportCsvButton" class="csv-btn">EXPORT CSV</button>
</div>
<div class="container">
<!-- Scoreboard section for summary metrics -->
<div class="scoreboard" id="scoreboard"></div>
<!-- Grid of charts -->
<div class="charts-grid">
<div class="chart-container"><canvas id="priorityChart"></canvas></div>
<div class="chart-container"><canvas id="domainCountChart"></canvas></div>
<div class="chart-container"><canvas id="colleagueEndpointChart"></canvas></div>
<div class="chart-container"><canvas id="loginBarChart"></canvas></div>
<div class="chart-container"><canvas id="statusCodeChart"></canvas></div>
<div class="chart-container"><canvas id="portChart"></canvas></div>
<div class="chart-container"><canvas id="serviceChart"></canvas></div>
<div class="chart-container"><canvas id="techChart"></canvas></div>
<div class="chart-container"><canvas id="tlsUsageChart"></canvas></div>
<div class="chart-container"><canvas id="certExpiryChart"></canvas></div>
<div class="chart-container"><canvas id="headersChart"></canvas></div>
<div class="chart-container"><canvas id="emailSecChart"></canvas></div>
<div class="chart-container"><canvas id="cdnStackedChart"></canvas></div>
<div class="chart-container"><canvas id="nsChart"></canvas></div>
</div>
<!-- Controls above the table: search box and rows per page selector -->
<div class="table-top-controls">
<input type="text" id="searchBox" placeholder="Filter table (e.g. domain, status code, tech)..." />
<div class="hint">
<h4>Mouseover to Risk Score to Evaluate Reasons for Scoring</h4>
</div>
<div class="table-controls">
<label for="rowsPerPageSelect">Rows per page:</label>
<select id="rowsPerPageSelect">
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="all">ALL</option>
</select>
</div>
</div>
<!-- Main report table with dynamic filters in header -->
<div class="table-container">
<table id="report-table">
<thead>
<tr>
<th id="riskScoreHeader">Attack Surface Score<span id="riskSortToggle" style="cursor:pointer; user-select:none; margin-left:5px;">▼</span></th>
<th>Domain</th>
<th>Purpose</th>
<th>Resolvers</th>
<th>A Records</th>
<th>NS Records</th>
<th>MX Records</th>
<th>PTR Records</th>
<th>DNS Status</th>
<th>CDN Name</th>
<th>CDN Type</th>
<th>Port</th>
<th>URL</th>
<th>Screenshot</th>
<th>Redirect Location</th>
<th>Homepage Title</th>
<th>Web Server</th>
<th>Login Found</th>
<th>API Endpoint</th>
<th>Technology Stack</th>
<th>Status Code</th>
<th>Content Length</th>
<th>CDN</th>
<th>SPF Record</th>
<th>DKIM Record</th>
<th>DMARC Record</th>
<th>DNSSEC Record</th>
<th>SSL/TLS Version</th>
<th>Cert Expiry Date</th>
<th>SSL/TLS Issuer</th>
<th>Strict-Transport-Security</th>
<th>X-Frame-Options</th>
<th>Content-Security-Policy</th>
<th>X-XSS-Protection</th>
<th>Referrer Policy</th>
<th>Permissions Policy</th>
<th>Open Ports / Services</th>
</tr>
<!-- Second header row for filter dropdowns per column -->
<tr id="filter-row">
<th><select id="priority-filter"><option value="">All</option></select></th>
<th><select id="domain-filter"><option value="">All</option></select></th>
<th><select id="purpose-filter"><option value="">All</option></select></th>
<th><select id="resolvers-filter"><option value="">All</option></select></th>
<th><select id="arecords-filter"><option value="">All</option></select></th>
<th><select id="ns-filter"><option value="">All</option></select></th>
<th><select id="mx-filter"><option value="">All</option></select></th>
<th><select id="ptr-filter"><option value="">All</option></select></th>
<th><select id="dnsstatus-filter"><option value="">All</option></select></th>
<th><select id="cdnname-filter"><option value="">All</option></select></th>
<th><select id="cdntype-filter"><option value="">All</option></select></th>
<th><select id="port-filter"><option value="">All</option></select></th>
<th><select id="url-filter"><option value="">All</option></select></th>
<th>
<select id="screenshot-filter">
<option value="">All</option>
<option value="has screenshot">Has screenshot</option>
<option value="no screenshot">No screenshot</option>
</select>
</th>
<th><select id="redirect-filter"><option value="">All</option></select></th>
<th><select id="title-filter"><option value="">All</option></select></th>
<th><select id="webserver-filter"><option value="">All</option></select></th>
<th><select id="login-filter"><option value="">All</option></select></th>
<th><select id="api-endpoint-filter"><option value="">All</option></select></th>
<th><select id="tech-filter"><option value="">All</option></select></th>
<th><select id="statuscode-filter"><option value="">All</option></select></th>
<th><select id="contentlength-filter"><option value="">All</option></select></th>
<th><select id="cdn-filter"><option value="">All</option></select></th>
<th><select id="spf-filter"><option value="">All</option></select></th>
<th><select id="dkim-filter"><option value="">All</option></select></th>
<th><select id="dmarc-filter"><option value="">All</option></select></th>
<th><select id="dnssec-filter"><option value="">All</option></select></th>
<th><select id="sslversion-filter"><option value="">All</option></select></th>
<th><select id="certexpiry-filter"><option value="">All</option></select></th>
<th><select id="sslissuer-filter"><option value="">All</option></select></th>
<th><select id="sts-filter"><option value="">All</option></select></th>
<th><select id="xfo-filter"><option value="">All</option></select></th>
<th><select id="csp-filter"><option value="">All</option></select></th>
<th><select id="xss-filter"><option value="">All</option></select></th>
<th><select id="rp-filter"><option value="">All</option></select></th>
<th><select id="pp-filter"><option value="">All</option></select></th>
<th><select id="ports-services-filter"><option value="">All</option></select></th>
</tr>
</thead>
<tbody id="report-table-body"></tbody>
</table>
</div>
<!-- Container for pagination controls -->
<div id="paginationControls"></div>
</div>
<!-- Modal HTML -->
<div id="screenshotModal">
<div id="screenshotModalContent">
<button id="closeModalBtn" onclick="closeModal()">Close</button>
<img id="screenshotModalImg" src="" alt="Full Screenshot" />
</div>
</div>
<script>
// Plugin for displaying labels on bars in charts
const barLabelPlugin = {
id: 'barLabelPlugin',
afterDatasetsDraw(chart, args, options) {
const { ctx } = chart;
const metaSets = chart.getSortedVisibleDatasetMetas().filter(m => m.type === 'bar');
metaSets.forEach(meta => {
meta.data.forEach((element, index) => {
const value = meta._parsed[index][meta.vScale.axis];
if (value === 0) return;
const { x, y } = element.tooltipPosition();
ctx.save();
ctx.fillStyle = Chart.defaults.color;
ctx.font = options.font || '9px sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
ctx.fillText(value, x, y - 2);
ctx.restore();
});
});
}
};
Chart.register(barLabelPlugin);
// Global variables for charts and table data.
let priorityChart, domainCountChart, statusCodeChart, loginChart, portChart, techChart, certExpiryChart, tlsUsageChart, headersChart, emailSecChart, cdnChart, serviceChart, colleagueChart, cdnTypeChart, cdnStackedChart;
let allTableRows = [];
let currentPage = 1;
let rowsPerPage = 20;
let riskScores = {};
let minRiskScore = Infinity;
let maxRiskScore = -Infinity;
let riskSortOrder = "desc";
// CSV Export Functions
function downloadCSV(csv, filename) {
const csvFile = new Blob([csv], { type: "text/csv" });
const downloadLink = document.createElement("a");
downloadLink.download = filename;
downloadLink.href = window.URL.createObjectURL(csvFile);
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
function exportAllTableRowsToCSV(filename) {
const csv = [];
const headerRow = document.querySelectorAll("#report-table thead tr")[0];
const headers = [];
headerRow.querySelectorAll("th").forEach(th => {
headers.push('"' + th.innerText.trim().replace(/"/g, '""') + '"');
});
csv.push(headers.join(","));
allTableRows.forEach(row => {
const cols = row.querySelectorAll("td");
const rowData = [];
cols.forEach(td => {
rowData.push('"' + td.innerText.trim().replace(/"/g, '""') + '"');
});
csv.push(rowData.join(","));
});
downloadCSV(csv.join("\n"), filename);
}
document.getElementById("exportCsvButton").addEventListener("click", function() {
exportAllTableRowsToCSV("report.csv");
});
// Theme toggle
document.getElementById("themeToggle").addEventListener("click", () => {
document.body.classList.toggle("dark");
updateChartTheme();
});
function updateChartTheme() {
const newColor = getComputedStyle(document.body).getPropertyValue('--text-color').trim();
Chart.defaults.color = newColor;
const charts = [
priorityChart, domainCountChart, statusCodeChart, loginChart,
portChart, techChart, certExpiryChart, tlsUsageChart,
headersChart, emailSecChart, cdnChart, serviceChart, colleagueChart, cdnTypeChart, cdnStackedChart
];
charts.forEach(chart => {
if (chart) {
if (chart.options.scales) {
if (chart.options.scales.x && chart.options.scales.x.ticks) {
chart.options.scales.x.ticks.color = newColor;
}
if (chart.options.scales.y && chart.options.scales.y.ticks) {
chart.options.scales.y.ticks.color = newColor;
}
}
if (chart.options.plugins && chart.options.plugins.legend && chart.options.plugins.legend.labels) {
chart.options.plugins.legend.labels.color = newColor;
}
if (chart.options.plugins && chart.options.plugins.title) {
chart.options.plugins.title.color = newColor;
}
chart.update();
}
});
}
// Utility function
function formatCell(arr) {
return (arr && arr.length) ? arr.join("<br>") : "N/A";
}
// Compute risk score
function computePriority({
purpose, url, loginFound, statusCode, sslVersion, certExpiry,
sts, xfo, csp, xss, rp, pp, openPortsCount, dbPortsCount, managementPortsCount, techCount
}) {
let score = 0;
const reasons = [];
if (purpose && purpose.toLowerCase().includes("employee")) {
score += 1;
reasons.push("+1 (Potential employee-intended domain found)");
}
if (url && url !== "N/A") {
score += 1;
reasons.push("+1 (Domain has live application)");
}
if (loginFound === "Yes") {
score += 1;
reasons.push("+1 (Login interface found on application)");
}
if (statusCode === 200) {
score += 1;
reasons.push("+1 (Application has 200 status code)");
}
if (sslVersion) {
const cleanVersion = sslVersion.replace(/\s+/g, '');
if (/^TLSv(1\.2|1\.3)$/i.test(cleanVersion)) {
reasons.push("+0 (Version of TLS is latest)");
} else if (/^TLSv(1\.0|1\.1)$/i.test(cleanVersion)) {
score += 2;
reasons.push("+1 (TLSv1.0 or TLSv1.1)");
} else if (/^SSLv(1\.0|2\.0|3\.0)$/i.test(cleanVersion)) {
score += 5;
reasons.push("+5 (SSLv1/2/3)");
}
} else {
score += 1;
reasons.push("+1 (no sslVersion reported)");
}
if (certExpiry && certExpiry !== "N/A") {
const expiryDate = new Date(certExpiry);
const now = new Date();
const diffDays = (expiryDate - now) / (1000 * 60 * 60 * 24);
if (!isNaN(diffDays)) {
if (diffDays < 0) {
score += 20;
reasons.push("+20 (certificate expired)");
} else if (diffDays <= 7) {
score += 10;
reasons.push("+10 (cert expires in ≤7 days)");
} else if (diffDays <= 14) {
score += 5;
reasons.push("+5 (cert expires in ≤14 days)");
} else if (diffDays <= 30) {
score += 2;
reasons.push("+2 (cert expires in ≤30 days)");
}
}
}
function missingHeader(val) {
return !val || val.trim() === "" || val.trim().toLowerCase() === "false";
}
if (missingHeader(sts)) { score += 1; reasons.push("+1 (Missing HSTS)"); }
if (missingHeader(xfo)) { score += 1; reasons.push("+1 (Missing X-Frame-Options)"); }
if (missingHeader(csp)) { score += 1; reasons.push("+1 (missing CSP)"); }
if (missingHeader(xss)) { score += 1; reasons.push("+1 (Missing X-XSS-Protection)"); }
if (missingHeader(rp)) { score += 1; reasons.push("+1 (Missing Referrer-Policy)"); }
if (missingHeader(pp)) { score += 1; reasons.push("+1 (Missing Permissions-Policy)"); }
if (openPortsCount && Number.isFinite(openPortsCount)) {
score += openPortsCount;
reasons.push(`+${openPortsCount} (Each Open ports)`);
}
if (dbPortsCount && Number.isFinite(dbPortsCount)) {
score += dbPortsCount;
reasons.push(`+${dbPortsCount} (Database ports)`);
}
if (managementPortsCount && Number.isFinite(managementPortsCount)) {
score += managementPortsCount;
reasons.push(`+${managementPortsCount} (Management ports)`);
}
if (techCount && Number.isFinite(techCount)) {
score += techCount;
reasons.push(`+${techCount} (Tech stack count)`);
}
return { score, debug: reasons };
}
function getDynamicColor(score, minScore, maxScore) {
if (maxScore === minScore) return "rgb(46, 204, 113)";
const fraction = (score - minScore) / (maxScore - minScore);
const start = { r: 46, g: 204, b: 113 };
const end = { r: 231, g: 76, b: 60 };
const r = Math.round(start.r + fraction * (end.r - start.r));
const g = Math.round(start.g + fraction * (end.g - start.g));
const b = Math.round(start.b + fraction * (end.b - start.b));
return `rgb(${r}, ${g}, ${b})`;
}
function buildScoreboard({ totalSubdomains, liveSubs, totalHttpx, loginFoundCount }) {
const sb = document.getElementById("scoreboard");
sb.innerHTML = `
<div class="score-card">
<h2>${totalSubdomains}</h2>
<p>Total Unique Assets</p>
</div>
<div class="score-card">
<h2>${liveSubs}</h2>
<p>Total Live Assets</p>
</div>
<div class="score-card">
<h2>${totalHttpx}</h2>
<p>Application Endpoints</p>
</div>
<div class="score-card">
<h2>${loginFoundCount}</h2>
<p>Login Interface Found</p>
</div>
`;
}
// The following functions build various charts...
function buildCharts({ statusCount, priorityCount, portCount, techCount, totalSubdomains, liveSubs, endpointsCount }) {
const scCanvas = document.getElementById("statusCodeChart");
const prCanvas = document.getElementById("priorityChart");
const portCanvas = document.getElementById("portChart");
const techCanvas = document.getElementById("techChart");
if (prCanvas) {
const funnelLabels = ["Total Assets", "Live Assets", "Applications"];
const funnelValues = [totalSubdomains, liveSubs, endpointsCount];
if (priorityChart) priorityChart.destroy();
priorityChart = new Chart(prCanvas, {
type: "bar",
data: {
labels: funnelLabels,
datasets: [{
label: "Assets Overview",
data: funnelValues,
backgroundColor: ["#2980b9", "#8e44ad", "#16a085"]
}]
},
options: {
responsive: true,
indexAxis: "x",
plugins: { legend: { display: false }, title: { display: true, text: "Assets Overview" } },
scales: { x: { beginAtZero: true, title: { display: true, text: "Count" } } }
}
});
}
if (scCanvas) {
const sortedKeys = Object.keys(statusCount).sort((a, b) => +a - +b);
statusCodeChart = new Chart(scCanvas, {
type: "bar",
data: {
labels: sortedKeys,
datasets: [{
label: "HTTP Status Codes",
data: sortedKeys.map(l => statusCount[l]),
backgroundColor: ["#3498db","#1abc9c","#9b59b6","#f1c40f","#e74c3c","#34495e","#95a5a6"]
}]
},
options: { responsive: true, plugins: { legend: { display: false }, title: { display: true, text: "HTTP Status Codes" } }, scales: { y: { beginAtZero: true } } }
});
}
if (portCanvas) {
const sortedPorts = Object.keys(portCount).sort((a, b) => portCount[b] - portCount[a]);
const top10Ports = sortedPorts.slice(0, 10);
portChart = new Chart(portCanvas, {
type: "bar",
data: {
labels: top10Ports,
datasets: [{
label: "Open Ports",
data: top10Ports.map(p => portCount[p]),
backgroundColor: "#f39c12"
}]
},
options: { responsive: true, plugins: { legend: { display: false }, title: { display: true, text: "Top 10 Ports" } }, scales: { y: { beginAtZero: true } } }
});
}
if (techCanvas) {
const sortedTech = Object.keys(techCount).sort((a, b) => techCount[b] - techCount[a]);
const top10 = sortedTech.slice(0, 10);
techChart = new Chart(techCanvas, {
type: "bar",
data: {
labels: top10,
datasets: [{
label: "Tech Usage (Top 10)",
data: top10.map(t => techCount[t]),
backgroundColor: "#9b59b6"
}]
},
options: {
responsive: true,
indexAxis: "x",
plugins: { legend: { display: false }, title: { display: true, text: "Top 10 Technologies" } },
scales: { x: { beginAtZero: true, ticks: { maxRotation: 60, minRotation: 70 } } }
}
});
}
}
function buildCDNStackedChart(httpxData) {
const cdnMap = {};
httpxData.forEach(record => {
let cdnName = record.cdn_name && record.cdn_name.trim();
let cdnType = record.cdn_type && record.cdn_type.trim();
if (!cdnName || cdnName === "N/A") return;
if (!cdnType || cdnType === "N/A") cdnType = "Unknown";
if (!cdnMap[cdnName]) cdnMap[cdnName] = {};
cdnMap[cdnName][cdnType] = (cdnMap[cdnName][cdnType] || 0) + 1;
});
const cdnNames = Object.keys(cdnMap);
const cdnTypesSet = new Set();
cdnNames.forEach(name => { Object.keys(cdnMap[name]).forEach(type => cdnTypesSet.add(type)); });
const cdnTypes = Array.from(cdnTypesSet);
const palette = ["#3498db","#1abc9c","#9b59b6","#f1c40f","#e74c3c","#34495e","#95a5a6","#e67e22","#2ecc71","#8e44ad","#7f8c8d"];
const datasets = cdnTypes.map((type, idx) => ({
label: type,
data: cdnNames.map(name => cdnMap[name][type] || 0),
backgroundColor: palette[idx % palette.length]
}));
const ctx = document.getElementById("cdnStackedChart").getContext("2d");
cdnStackedChart = new Chart(ctx, {
type: "bar",
data: { labels: cdnNames, datasets: datasets },
options: {
responsive: true,
plugins: { title: { display: true, text: "CDN Type vs. CDN Name" }, tooltip: { mode: "index", intersect: false } },
scales: { x: { stacked: true }, y: { stacked: true, beginAtZero: true } }
}
});
}
function buildDomainCountChart(httpxData) {
const domainCount = {};
httpxData.forEach(h => {
if (h.url && h.url !== "N/A") {
const domain = (h.input || "").split(":")[0];
domainCount[domain] = (domainCount[domain] || 0) + 1;
}
});
const sortedDomains = Object.keys(domainCount).sort((a, b) => domainCount[b] - domainCount[a]);
const top10 = sortedDomains.slice(0, 10);
const data = top10.map(d => domainCount[d]);
const ctx = document.getElementById("domainCountChart").getContext("2d");
domainCountChart = new Chart(ctx, {
type: "bar",
data: {
labels: top10,
datasets: [{ label: "Top 10 Domains (Active URLs)", data, backgroundColor: "#2980b9" }]
},
options: {
responsive: true,
indexAxis: "x",
plugins: { legend: { display: false }, title: { display: true, text: "Top 10 Domains by Active URLs" } },
scales: { x: { beginAtZero: true, ticks: { stepSize: 1, maxRotation: 100, minRotation: 70 } } }
}
});
}
function buildLoginBarChart(endpointsCount, loginFoundCount) {
const canvas = document.getElementById("loginBarChart");
if (!canvas) return;
loginChart = new Chart(canvas, {
type: "bar",
data: {
labels: ["Found", "Not Found"],
datasets: [{ data: [loginFoundCount, endpointsCount - loginFoundCount], backgroundColor: ["#e74c3c", "#2ecc71"] }]
},
options: { responsive: true, plugins: { title: { display: true, text: "Login Interfaces Identified" }, legend: { display: false } } }
});
}
function buildCertExpiryChart(secData) {
let now = new Date(), expired = 0, exp7 = 0, exp14 = 0, exp30 = 0;
secData.forEach(item => {
const expiryStr = item["Cert Expiry Date"];
if (expiryStr && expiryStr !== "N/A") {
let expiryDate = new Date(expiryStr);
if (!isNaN(expiryDate)) {
let diffDays = (expiryDate - now) / (1000 * 60 * 60 * 24);
if (diffDays < 0) expired++;
else if (diffDays <= 7) exp7++;
else if (diffDays <= 14) exp14++;
else if (diffDays <= 30) exp30++;
}
}
});
const ctx = document.getElementById("certExpiryChart").getContext("2d");
certExpiryChart = new Chart(ctx, {
type: "bar",
data: {
labels: ["Expired", "Next 7 Days", "Next 14 Days", "Next 30 Days"],
datasets: [{ label: "Certs Expiring", data: [expired, exp7, exp14, exp30], backgroundColor: ["#FF0000", "#e74c3c", "#e67e22", "#3498db"] }]
},
options: { responsive: true, plugins: { title: { display: true, text: "Certificate Expiry" }, legend: { display: false } }, scales: { y: { beginAtZero: true } } }
});
}
function buildTLSUsageChart(secData) {
const tlsCounts = {};
secData.forEach(item => {
let ver = item["SSL/TLS Version"];
ver = ver ? ver.trim() : "Unknown";
tlsCounts[ver] = (tlsCounts[ver] || 0) + 1;
});
const labels = Object.keys(tlsCounts);
const data = labels.map(l => tlsCounts[l]);
const ctx = document.getElementById("tlsUsageChart").getContext("2d");
tlsUsageChart = new Chart(ctx, {
type: "bar",
data: { labels, datasets: [{ label: "TLS Version Usage", data, backgroundColor: "#2ecc71" }] },
options: { responsive: true, plugins: { title: { display: true, text: "SSL/TLS Usage" }, legend: { display: false } }, scales: { y: { beginAtZero: true } } }
});
}
function buildHeadersChart(httpxData, secMapUrlParam) {
let hstsPresent = 0, hstsMissing = 0, xfoPresent = 0, xfoMissing = 0,
cspPresent = 0, cspMissing = 0, xssPresent = 0, xssMissing = 0,
rpPresent = 0, rpMissing = 0, ppPresent = 0, ppMissing = 0;
httpxData.forEach(record => {
const sec = secMapUrlParam[record.url] || {};
const hsts = (sec["Strict-Transport-Security"] || "").trim();
hsts && hsts.toLowerCase() !== "n/a" && hsts.toLowerCase() !== "false" ? hstsPresent++ : hstsMissing++;
const xfo = (sec["X-Frame-Options"] || "").trim();
xfo && xfo.toLowerCase() !== "n/a" && xfo.toLowerCase() !== "false" ? xfoPresent++ : xfoMissing++;
const csp = (sec["Content-Security-Policy"] || "").trim();
csp && csp.toLowerCase() !== "n/a" && csp.toLowerCase() !== "false" ? cspPresent++ : cspMissing++;
const xss = (sec["X-XSS-Protection"] || "").trim();
xss && xss.toLowerCase() !== "n/a" && xss.toLowerCase() !== "false" ? xssPresent++ : xssMissing++;
const rp = (sec["Referrer-Policy"] || "").trim();
rp && rp.toLowerCase() !== "n/a" && rp.toLowerCase() !== "false" ? rpPresent++ : rpMissing++;
const pp = (sec["Permissions-Policy"] || "").trim();
pp && pp.toLowerCase() !== "n/a" && pp.toLowerCase() !== "false" ? ppPresent++ : ppMissing++;
});
const ctx = document.getElementById("headersChart").getContext("2d");
headersChart = new Chart(ctx, {
type: "bar",
data: {
labels: ["HSTS", "X-Frame-Options", "CSP", "X-XSS-Protection", "Referrer-Policy", "Permissions-Policy"],
datasets: [
{ label: "Present", data: [hstsPresent, xfoPresent, cspPresent, xssPresent, rpPresent, ppPresent], backgroundColor: "#2ecc71" },
{ label: "Missing", data: [hstsMissing, xfoMissing, cspMissing, xssMissing, rpMissing, ppMissing], backgroundColor: "#e74c3c" }
]
},
options: {
responsive: true,
indexAxis: "x",
plugins: { title: { display: true, text: "Security Headers" }, tooltip: { mode: "index", intersect: false } },
scales: { x: { stacked: true }, y: { stacked: true, beginAtZero: true } }
}
});
}
function buildEmailSecChart(secData) {
let spfSet = 0, spfMissing = 0, dkimSet = 0, dkimMissing = 0, dmarcSet = 0, dmarcMissing = 0;
secData.forEach(item => {
const spf = item["SPF Record"] || "";
const dkim = item["DKIM Record"] || "";
const dmarc = item["DMARC Record"] || "";
spf.toLowerCase().includes("spf1") ? spfSet++ : spfMissing++;
dkim.toLowerCase().includes("dkim1") ? dkimSet++ : dkimMissing++;
dmarc.toLowerCase().includes("dmarc1") ? dmarcSet++ : dmarcMissing++;
});
const ctx = document.getElementById("emailSecChart").getContext("2d");
emailSecChart = new Chart(ctx, {
type: "bar",
data: {
labels: ["SPF", "DKIM", "DMARC"],
datasets: [
{ label: "Present", data: [spfSet, dkimSet, dmarcSet], backgroundColor: "#2ecc71" },
{ label: "Missing", data: [spfMissing, dkimMissing, dmarcMissing], backgroundColor: "#e74c3c" }
]
},
options: {
responsive: true,
plugins: { title: { display: true, text: "Email Security Records" }, tooltip: { mode: "index", intersect: false } },
scales: { x: { stacked: true }, y: { stacked: true, beginAtZero: true } }
}
});
}
function buildServiceChart(naabuData) {
const naabuMap = {};
const serviceCount = {};
naabuData.forEach(n => {
const domain = n.host;
const port = n.port;
let service = "Unknown";
const portServiceDB = {"7":"Echo","9":"Discard","13":"Daytime","21":"FTP","22":"SSH","23":"Telnet","25":"Simple Mail Transfer","26":"Unassigned","37":"Time","53":"Domain Name Server","66":"Oracle SQL*NET","79":"Finger","80":"HTTP","81":"Unassigned","88":"Kerberos","92":"Network Printing Protocol","99":"Metagram Relay","106":"3COM-TSMUX","110":"Post Office Protocol - Version 3","111":"SUN Remote Procedure Call","113":"Authentication Service","119":"Network News Transfer Protocol","135":"DCE endpoint resolution","139":"NETBIOS Session Service","143":"Reserved","144":"Universal Management Architecture","179":"BGP","199":"SMUX","443":"HTTPS","444":"Simple Network Paging Protocol","445":"Microsoft-DS","457":"scohelp","465":"IGMP over UDP for SSM","513":"maintains data bases showing who's logged in to machines on a local net and the load average of the machine","514":"rsh","515":"spooler","543":"Klogin","544":"krcmd","548":"AFP over TCP","554":"Real Time Streaming Protocol (RTSP)","587":"Message Submission","631":"Internet Printing Protocol over HTTPS","646":"LDP","6646":"IRC","873":"rsync","8880":"CDDBP","8888":"NewsEDGE server UDP (UDP 1)","990":"ftp protocol, control, over TLS/SSL","992":"telnet protocol over TLS/SSL","993":"Reserved","995":"pop3 protocol over TLS/SSL (was spop3)","1024":"Reserved","1025":"network blackjack","1026":"Calendar Access Protocol","1027":"Reserved","1028":"Deprecated","1029":"Solid Mux Server","1080":"Socks","1100":"MCTP","1110":"Client status info","1194":"OpenVPN","1241":"nessus","1352":"Lotus Note","1433":"Microsoft-SQL-Server","1434":"Microsoft-SQL-Monitor","1521":"nCube License Manager","1522":"Ricardo North America License Manager","15672":"RabbitMQ Mgmt","1720":"H.323 Call Control","1723":"pptp","1755":"ms-streaming","1900":"SSDP","1944":"close-combat","2000":"Cisco SCCp","2001":"curry","2049":"Network File System","2121":"SCIENTIA-SSDB","2222":"EtherNet/IP I/O","2301":"Compaq HTTP","2323":"3d-nfsd","2483":"Oracle TTC","2484":"Oracle TTC SSL","2638":"Sybase Anywhere","27017":"Reserved","27018":"MongoDB","27019":"MongoDB","2717":"PN REQUESTER","28015":"RethinkDB","3000":"RemoteWare Client","3050":"gds_db","3128":"Active API Server Port","32768":"Filenet TMS","3306":"MySQL","3389":"MS WBT Server","3986":"MAPPER workstation server","4000":"Terabase","4001":"NewOak","4002":"pxc-spvr-ft","4100":"IGo Incognito Data Port","4567":"TRAM","4899":"RAdmin Port","49152":"N/A","49153":"N/A","49154":"N/A","49155":"N/A","49156":"N/A","49157":"N/A","5000":"UPnP","5001":"N/A","5009":"Microsoft Windows Filesystem","5051":"ITA Agent","5060":"SIP","5101":"Talarian_UDP","5190":"America-Online","5357":"Web Services for Devices","5432":"PostgreSQL Database","5631":"pcANYWHEREdata","5666":"Reserved","5800":"VNC","5801":"VNC","5802":"VNC","5803":"VNC","5804":"VNC","5805":"VNC","5806":"VNC","5807":"VNC","5809":"VNC","5900":"Remote Framebuffer","5984":"CouchDB","5985":"WBEM WS-Management HTTP","5986":"WBEM WS-Management HTTP over TLS/SSL","6000":"X11","6001":"X11","6346":"gnutella-svc","6347":"gnutella-rtr","6379":"Reserved","6513":"Reserved","7000":"file server itself","7001":"callbacks to cache managers","7002":"users & groups database","7070":"ARCP","7170":"Adaptive Name/Service Resolution","7199":"Cassandra","7474":"Reserved","7647":"N/A","7687":"Reserved","7777":"cbt","8000":"iRDMI","8001":"VCOM Tunnel","8008":"HTTP Alternate","8009":"Reserved","8080":"HTTP Alternate (see port 80)","8081":"Sun Proxy Admin Service","8083":"Utilistor (Server)","8085":"Unassigned","8089":"Unassigned","8090":"Reserved","8181":"Reserved","8291":"MikroTik","8443":"PCsync HTTPS","9000":"CSlistener","9080":"Groove GLRPC","9090":"WebSM","9091":"xmltec-xmlmail","9092":"Xml-Ipc Server Reg","9100":"Printer PDL Data Stream","9200":"WAP connectionless session service","9443":"WSO2 Tungsten HTTPS","9990":"OSM Applet Server","9999":"distinct","10000":"Network Data Management Protocol","10080":"Amanda","10443":"Reserved","11211":"Memory cache service","20000":"Distributed Network Protocol","54321":"N/A","30821":"N/A","9042":"Cassandra CQL","9160":"apani1"};
if (portServiceDB[port]) service = portServiceDB[port];
if (!naabuMap[domain]) naabuMap[domain] = [];
naabuMap[domain].push({ port, service });
serviceCount[service] = (serviceCount[service] || 0) + 1;
});
window.naabuMap = naabuMap;
const ctx = document.getElementById("serviceChart").getContext("2d");
const sortedServices = Object.keys(serviceCount).sort((a, b) => serviceCount[b] - serviceCount[a]);
const top10Services = sortedServices.slice(0, 10);
const data = top10Services.map(service => serviceCount[service]);
serviceChart = new Chart(ctx, {
type: "bar",
data: {
labels: top10Services,
datasets: [{
label: "Open Services",
data,
backgroundColor: "#9b59b6"
}]
},
options: { responsive: true, plugins: { legend: { display: false }, title: { display: true, text: "Top 10 Services" } },
scales: { x: { beginAtZero: true, ticks: { maxRotation: 60, minRotation: 70 } } } }
});
}
function buildColleagueChart(colleagueData) {
const countEmployee = colleagueData.filter(x => x.colleague_endpoint === "Yes").length;
const countCustomer = colleagueData.length - countEmployee;
const ctx = document.getElementById("colleagueEndpointChart").getContext("2d");
colleagueChart = new Chart(ctx, {
type: "bar",
data: {
labels: ["Employee Intended", "Customer Intended"],
datasets: [{
label: "Purpose Count",
data: [countEmployee, countCustomer],
backgroundColor: ["#e74c3c", "#2ecc71"]