forked from CSMurray1/VulnDashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1743 lines (1695 loc) · 80.2 KB
/
index.html
File metadata and controls
1743 lines (1695 loc) · 80.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Vulnerability Dashboard</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🪲</text></svg>'" />
<!-- ===== Global Styles ===== -->
<style>
:root {
--bg-light: #f8f9fa;
--text-light: #212529;
--panel-light: #ffffff;
--border-light: #dee2e6;
--link-light: #0d6efd;
--bg-dark: #121212;
--text-dark: #e9ecef;
--panel-dark: #1e1e1e;
--border-dark: #343a40;
--link-dark: #8ab4f8;
--input-bg-dark: #2d2d2d;
--input-text-dark: #e9ecef;
--heat-bar: #0d6efd;
}
/* Base */
body {
font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
margin: 0;
background: var(--bg-light);
color: var(--text-light);
line-height: 1.6;
}
body.dark {
background: var(--bg-dark);
color: var(--text-dark);
}
a {
color: var(--link-light);
text-decoration: none;
}
body.dark a { color: var(--link-dark); }
a:hover { text-decoration: underline; }
/* Top nav tabs */
nav {
display: flex;
justify-content: center;
background: #444;
color: white;
}
nav button {
flex: 1;
padding: 14px;
font-size: 16px;
color: white;
background: #444;
border: none;
cursor: pointer;
outline: none;
transition: background 0.3s;
}
nav button.active { background: #0074d9; }
nav button:hover { background: #555; }
/* Tabs container limits show/hide scope */
.tabs > section { display: none; padding: 20px; }
.tabs > section.active { display: block; }
/* Mode Toggle Button (floating) */
.mode {
position: fixed;
top: 14px;
right: 14px;
padding: 8px 16px;
font-size: 14px;
color: #333;
background: #ddd;
border: 1px solid #ccc;
border-radius: 5px;
cursor: pointer;
z-index: 1000;
}
body.dark .mode {
background: #444;
color: #f4f4f9;
border-color: #666;
}
/* Dashboard 1 (CVE) Header */
header.cve-header {
padding: 20px;
background: inherit;
border-bottom: 1px solid var(--border-light);
display: flex;
gap: 12px;
align-items: center;
flex-wrap: wrap;
position: sticky;
top: 0;
z-index: 10;
}
body.dark header.cve-header { border-color: var(--border-dark); }
header.cve-header h1 {
margin: 0;
font-size: 22px;
font-weight: 600;
display: flex;
align-items: center;
gap: 12px;
}
header.cve-header h1::before {
content: "";
display: block;
width: 36px;
height: 36px;
background: url('data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🪲</text></svg>') center/cover no-repeat;
}
#cve {
flex: 1;
min-width: 300px;
padding: 12px 16px;
font-size: 16px;
border: 1px solid var(--border-light);
border-radius: 8px;
background: var(--panel-light);
}
body.dark #cve {
background: var(--input-bg-dark);
border-color: var(--border-dark);
color: var(--input-text-dark);
}
.btn {
padding: 10px 18px;
border: 1px solid var(--border-light);
background: var(--panel-light);
color: var(--text-light);
border-radius: 8px;
cursor: pointer;
font-weight: 500;
}
body.dark .btn {
background: var(--input-bg-dark);
border-color: var(--border-dark);
color: var(--text-dark);
}
/* Dashboard 1 Layout */
main.cve-main {
padding: 24px;
display: grid;
grid-template-columns: 1fr 1fr 320px;
grid-template-areas:
"details details watch"
"sources relevant vulncheck";
gap: 20px;
}
@media (max-width:1400px) {
main.cve-main {
grid-template-columns: 1fr 1fr;
grid-template-areas:
"details details"
"watch watch"
"vulncheck vulncheck"
"sources relevant";
}
}
@media (max-width:1000px) {
main.cve-main {
grid-template-columns: 1fr;
grid-template-areas:
"details"
"watch"
"vulncheck"
"sources"
"relevant";
}
}
#cveDetails { grid-area: details; }
#exploitationWatch { grid-area: watch; }
#vulncheckMonitor { grid-area: vulncheck; }
#notableSources { grid-area: sources; }
#relevantSearches { grid-area: relevant; }
/* Panels */
.panel {
background: var(--panel-light);
border: 1px solid var(--border-light);
border-radius: 12px;
overflow: hidden;
}
body.dark .panel {
background: var(--panel-dark);
border-color: var(--border-dark);
}
.panel > header {
padding: 14px 18px;
border-bottom: 1px solid var(--border-light);
background: rgba(0,0,0,0.03);
}
body.dark .panel > header {
border-color: var(--border-dark);
background: rgba(255,255,255,0.03);
}
.panel > header h2 {
margin: 0;
font-size: 16px;
font-weight: 600;
}
.content { padding: 16px 18px; }
.item {
padding: 12px 0;
border-bottom: 1px dashed var(--border-light);
}
body.dark .item { border-color: #444; }
.item:last-child { border: none; }
.title { font-weight: 600; margin-bottom: 6px; }
.meta { font-size: 14px; opacity: .9; }
/* Chips & badges */
.chip {
display: inline-block;
padding: 4px 10px;
border-radius: 999px;
font-size: 12px;
font-weight: 700;
color: white;
margin-left: 8px;
}
.low{background:#2d7f3a;}
.medium{background:#b57f00;}
.high{background:#cc4a00;}
.critical{background:#a60000;}
.badge {
display: inline-block;
padding: 5px 10px;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
}
.yes{background:#d4edda;color:#155724;}
.no{background:#f8d7da;color:#721c24;}
body.dark .yes{background:#1e3f2a;color:#a7f3c0;}
body.dark .no{background:#4a1e20;color:#f5b5bb;}
/* Link row + Copy */
.link-row {
margin:6px 0;
display:flex;
align-items:center;
gap:8px;
}
.link-row a { word-break:break-all; }
.copy-link {
font-size:12px;
padding:4px 8px;
border:1px solid var(--border-light);
background: var(--panel-light);
border-radius:4px;
cursor:pointer;
}
body.dark .copy-link {
border-color: var(--border-dark);
background: var(--input-bg-dark);
color: var(--text-dark);
}
/* EPSS/SSVC layout */
.metrics-row {
display:flex;
gap:16px;
flex-wrap:wrap;
align-items:flex-start;
margin-top:12px;
}
.metrics-col { flex: 1 1 360px; min-width: 280px; }
.metrics-box {
padding: 12px;
background: rgba(13,110,253,0.1);
border-radius: 8px;
margin-top: 4px;
font-size: 14px;
}
body.dark .metrics-box { background: rgba(13,110,253,0.2); }
.metrics-box .title {
font-weight: 600;
margin-bottom: 8px;
color: #0d6efd;
}
.metrics-box table {
width: 100%;
border-collapse: collapse;
background: transparent;
color: inherit;
}
.metrics-box th, .metrics-box td {
padding: 8px;
text-align: left;
border-bottom: 1px solid rgba(13,110,253,0.3);
}
.metrics-box th {
font-weight: 600;
color: #0d6efd;
}
/* Toast + Loading */
#toast {
position:fixed;
bottom:30px;
left:50%;
transform:translateX(-50%);
background:#333;
color:#fff;
padding:12px 24px;
border-radius:8px;
display:none;
z-index:1000;
}
#loading {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
background: rgba(0,0,0,0.7);
color:#fff;
font-size:24px;
display:none;
align-items:center;
justify-content:center;
z-index:1200;
}
/* Modal (Attack Visualizer) */
#attackModal {
display:none;
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
background: var(--bg-light);
z-index:1100;
}
body.dark #attackModal { background: var(--bg-dark); }
#attackGraph { width:100%; height: calc(100% - 60px); }
#closeModal {
position:absolute;
top:10px;
right:10px;
z-index:1110;
}
.settings-content {
background: var(--panel-light);
padding:30px;
border-radius:12px;
width:90%;
max-width:520px;
color:inherit;
}
body.dark .settings-content { background: var(--panel-dark); }
.settings-content input, .settings-content textarea {
width:100%;
padding:10px;
margin-top:6px;
border-radius:6px;
border:1px solid var(--border-light);
background: var(--panel-light);
color: var(--text-light);
}
body.dark .settings-content input, body.dark .settings-content textarea {
background: var(--input-bg-dark);
border-color: var(--border-dark);
color: var(--input-text-dark);
}
.settings-content label {
display:block;
margin-bottom:16px;
font-weight:600;
}
/* Prevalence modal */
#prevalenceModal {
display:none;
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
background: rgba(0,0,0,0.65);
z-index:1250;
align-items:center;
justify-content:center;
padding:20px;
}
.prev-content {
background: var(--panel-light);
color:inherit;
border:1px solid var(--border-light);
border-radius:12px;
max-width:920px;
width:95%;
max-height:85vh;
overflow:auto;
padding:20px 24px;
}
body.dark .prev-content {
background: var(--panel-dark);
border-color: var(--border-dark);
}
.prev-header {
display:flex;
justify-content:space-between;
align-items:center;
margin-bottom:12px;
}
/* Dark mode fix for AI Analysis modal */
body.dark #analysisModal > div {
background: var(--panel-dark);
color: var(--text-dark);
border-color: var(--border-dark);
}
body.dark #analysisBody {
background: var(--input-bg-dark);
color: var(--input-text-dark);
border-color: var(--border-dark);
}
body.dark #analysisStatus {
color: var(--text-dark);
}
/* Dark mode fix for AI Analysis modal outer container */
body.dark #analysisModal > div {
background: var(--panel-dark);
color: var(--text-dark);
border-color: var(--border-dark);
}
/* Ensure headings and buttons inside modal adapt */
body.dark #analysisModal h3 {
color: var(--text-dark);
}
body.dark #analysisModal .btn {
background: var(--input-bg-dark);
color: var(--text-dark);
border-color: var(--border-dark);
}
/* Analysis body box (where text streams) */
body.dark #analysisBody {
background: var(--input-bg-dark);
color: var(--input-text-dark);
border-color: var(--border-dark);
}
/* Dashboard 2 (Feeds) */
.feeds-header { text-align:center; }
.feed-container { display:flex; flex-wrap:wrap; gap:1rem; justify-content:center; }
.feed {
background-color: white;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 15px;
width: 300px;
}
body.dark .feed {
background-color: #2e2e50;
border-color: #444;
box-shadow: none;
}
.feed h2 { font-size: 18px; color: inherit; margin-bottom: 5px; }
.feed ul { list-style:none; padding:0; margin:0; }
.feed ul li { margin-bottom:10px; }
.feed ul li a { color: #0074d9; text-decoration: none; }
body.dark .feed ul li a { color: #5caeff; }
/* Watcher notify panel */
#watcherNotify {
position: fixed;
bottom: 24px;
right: 24px;
max-width: 520px;
z-index: 1400;
display: none;
}
/* Dark mode fix for Watcher textarea placeholder */
body.dark #watcherList::placeholder { color: #bbb; }
/* Force dark mode for AI Analysis modal outer container */
body.dark #analysisModal > div {
background: var(--panel-dark) !important;
color: var(--text-dark) !important;
border-color: var(--border-dark) !important;
}
/* Exploitation Watcher Scrollbar */
#watchContent {
max-height: 320px;
overflow-y: auto;
border-radius: 6px;
padding: 12px;
background: #fafafa;
}
body.dark #watchContent {
background: #1e1e1e;
}
#watchContent::-webkit-scrollbar {
width: 8px;
}
#watchContent::-webkit-scrollbar-thumb {
background: #aaa;
border-radius: 4px;
}
body.dark #watchContent::-webkit-scrollbar-thumb {
background: #666;
}
</style>
</head>
<body class="light">
<button class="mode" onclick="toggleMode()">Dark Mode</button>
<nav>
<button onclick="switchTab(0)" class="active">CVE Dashboard</button>
<button onclick="switchTab(1)">CyberWatch Dashboard</button>
</nav>
<div class="tabs">
<section id="tab1" class="active">
<header class="cve-header">
<h1>Vulnerability Analysis Dashboard</h1>
<input id="cve" type="text" placeholder="Enter CVE (e.g., CVE-2021-44228) or Vendor/Product" />
<button id="go" class="btn">Run</button>
<button id="clearCve" class="btn">Clear</button>
<button id="aiAnalysis" class="btn">AI Analysis</button>
</header>
<main class="cve-main">
<!-- panels unchanged -->
<div id="cveDetails" class="panel"><header><h2>CVE Details & Exploitation Signals</h2></header><div class="content" id="cveContent"><div class="meta">Enter a CVE or Vendor/Product and click Run.</div></div></div>
<div id="exploitationWatch" class="panel"><header><h2>CVE & Exploitation Watcher</h2></header><div class="content" id="watchContent"><div class="meta">Loading feeds…</div></div></div>
<div id="vulncheckMonitor" class="panel"><header><h2>Recent VulnCheck KEV (last 10 days)</h2></header><div class="content" id="vulncheckContent"><div class="meta">Loading...</div></div></div>
<div id="notableSources" class="panel"><header><h2>Notable Sources & References</h2></header><div class="content" id="sourcesContent"><div class="meta">Will appear after running a CVE.</div></div></div>
<div id="relevantSearches" class="panel"><header><h2>Relevant Searches & Monitoring</h2></header><div class="content" id="searchLinks"><div class="meta">Enter a term above and click Run to populate links.</div></div></div>
</main>
<div id="toast"></div>
<div id="loading">Loading data...</div>
<!-- Attack Visualizer Modal -->
<div id="attackModal"><div class="prev-content"><div id="attackGraph"></div><button id="closeModal" class="btn">Close Visualizer</button></div></div>
<!-- Prevalence Modal -->
<div id="prevalenceModal"><div class="prev-content"><div class="prev-header"><h3 id="prevTitle">Prevalence</h3><button class="btn" onclick="document.getElementById('prevalenceModal').style.display='none'">Close</button></div><div id="prevBody"></div></div></div>
<!-- AI Analysis Results Modal -->
<div id="analysisModal" role="dialog" aria-modal="true" aria-labelledby="analysisTitle" style="display:none; position:fixed; inset:0; background: rgba(0,0,0,0.6); z-index:1450; align-items:center; justify-content:center;">
<div style="background: var(--panel-light); color: inherit; border:1px solid var(--border-light); border-radius:12px; width:92%; max-width:860px; max-height:85vh; overflow:auto; padding:18px;">
<h3 id="analysisTitle" style="margin-top:0">AI Analysis</h3>
<div id="analysisStatus" class="meta" style="margin-bottom:12px">Preparing analysis…</div>
<div id="analysisBody" style="white-space:pre-wrap; font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, Arial; border:1px solid var(--border-light); border-radius:8px; padding:12px; min-height:160px;"></div>
<div style="display:flex; gap:12px; margin-top:12px; flex-wrap:wrap;">
<button id="analysisCopy" class="btn">Copy</button>
<button id="analysisSave" class="btn">Download .md</button>
<button id="analysisCancel" class="btn">Cancel</button>
<button id="analysisClose" class="btn">Close</button>
</div>
</div>
</div>
</section>
<section id="tab2">
<div class="feeds-header">
<h1>Live Cybersecurity Exploits Monitor</h1>
<div style="margin: 12px 0;"><button class="btn" onclick="displayFeeds()">Refresh Feeds</button></div>
</div>
<div id="feed-container" class="feed-container"></div>
</section>
</div>
<script>
/* ---------- Origins & Endpoints ---------- */
const IS_FILE_ORIGIN = location.protocol === 'file:';
/* ---------- UI Utilities ---------- */
function toast(msg) {
const t = document.getElementById("toast");
t.textContent = msg;
t.style.display = "block";
setTimeout(() => t.style.display = "none", 3000);
}
function linkRow(url, label) {
const safeLabel = label || url;
// Return an <a> tag with a proper `href`
return `
<a href="${url}" target="_blank" rel="noopener noreferrer">${safeLabel}</a>
`;
}
function toggleMode() {
document.body.classList.toggle('dark');
const modeBtn = document.querySelector(".mode");
if (modeBtn) modeBtn.textContent = document.body.classList.contains("dark") ? "Light Mode" : "Dark Mode";
const themeBtn = document.getElementById("theme");
if (themeBtn) themeBtn.textContent = document.body.classList.contains("dark") ? "Light Mode" : "Dark Mode";
localStorage.setItem("theme", document.body.classList.contains("dark") ? "dark" : "light");
}
function initTheme() {
const saved = localStorage.getItem("theme");
if (saved === "dark") {
document.body.classList.add("dark");
const modeBtn = document.querySelector(".mode"); if (modeBtn) modeBtn.textContent = "Light Mode";
const themeBtn = document.getElementById("theme"); if (themeBtn) themeBtn.textContent = "Light Mode";
}
document.getElementById("theme")?.addEventListener("click", toggleMode);
}
/* ---------- CWE Builder ---------- */
function buildCweHtml(cveJson, nvdJson) {
const rows = [];
const cna = cveJson?.containers?.cna;
const cnaAssigner = cna?.providerMetadata?.shortName || 'CNA';
const cnaPts = Array.isArray(cna?.problemTypes) ? cna.problemTypes : [];
cnaPts.forEach(pt => { (pt.descriptions || []).forEach(d => { rows.push({ source: cnaAssigner, cweId: d?.cweId || d?.id || null, description: d?.description || d?.value || '' }); }); });
const adps = Array.isArray(cveJson?.containers?.adp) ? cveJson.containers.adp : [];
adps.forEach(p => {
const src = p?.providerMetadata?.shortName || 'ADP';
const pts = Array.isArray(p?.problemTypes) ? p.problemTypes : [];
pts.forEach(pt => { (pt.descriptions || []).forEach(d => { rows.push({ source: src, cweId: d?.cweId || d?.id || null, description: d?.description || d?.value || '' }); }); });
});
const nvdCve = nvdJson?.vulnerabilities?.[0]?.cve;
const weaknesses = Array.isArray(nvdCve?.weaknesses) ? nvdCve.weaknesses : [];
weaknesses.forEach(w => {
const src = 'NVD - NIST';
const descs = w?.description || w?.descriptions || [];
(descs || []).forEach(d => {
const text = d?.value || d?.description || '';
const idMatch = text?.match(/\bCWE-\d{1,5}\b/);
rows.push({ source: src, cweId: idMatch ? idMatch[0] : (w?.type || null), description: text });
});
});
const seen = new Set();
const uniq = rows.filter(r => { const key = `${r.source}|${r.cweId || ''}|${r.description || ''}`; if (seen.has(key)) return false; seen.add(key); return true; });
if (!uniq.length) return '<div class="meta">No CWE data available.</div>';
return uniq.map(r => `<div class="item"><div class="title">CWE ID: ${r.cweId || 'Unknown'} - ${r.description || 'No Description'}</div><div class="meta">Assigner: ${r.source}</div></div>`).join('');
}
/* ---------- Prompt Builder ---------- */
let __lastAnalysisContext = null;
let __lastVulncheckRecent = [];
function buildAnalysisPrompt(ctx) {
if (!ctx) {
return [
'You are a security analyst. Provide a concise, technically rigorous vulnerability analysis.',
'',
'Deliverables:',
'1) Executive summary.',
'2) Root cause & vulnerable components/conditions.',
'3) Exploitability (pre-/post-auth, network exposure).',
'4) Impact & blast radius; relevant MITRE ATT&CK techniques.',
'5) Detection ideas (logs, artifacts, controls).',
'6) Mitigation/patch priorities & safe workarounds.',
'7) Risk scoring rationale (tie to KEV/EPSS/CVSS).',
'',
'State unknowns explicitly; do not guess.'
].join('\n');
}
const { input, isCVE, cnaName, description, kevYes, ransomwareTag, epss, cvss = [], cwes = [], referencesGrouped = [] } = ctx;
const cvssLines = cvss.length ? cvss.map(m => `- CVSS v${m.version}: ${m.score} (${m.source})${m.vector ? ` | ${m.vector}` : ''}`).join('\n') : '- CVSS: (none)';
const cweLines = cwes.length ? cwes.map(c => `- ${c.id || 'Unknown'} — ${c.desc || 'No description'} (Assigner: ${c.assigner || 'Unknown'})`).join('\n') : '- CWE: (none)';
const refLines = referencesGrouped.length ? referencesGrouped.map(g => { const links = (g.links || []).slice(0, 4).map(r => ` • ${r.name || r.url}: ${r.url}`).join('\n'); return `- ${g.host}\n${links}`; }).join('\n') : '- References: (none)';
const epssLine = (epss && typeof epss.score === 'number') ? `EPSS: ${epss.score.toFixed(4)} (~${(epss.score * 100).toFixed(2)}% 30-day), Percentile: ${(epss.percentile * 100).toFixed(1)}%` : `EPSS: (no data)`;
const kevLine = kevYes ? `CISA KEV: Yes (Ransomware: ${String(ransomwareTag || 'Unknown')})` : `CISA KEV: No`;
return [
`Provide a concise, technically rigorous analysis for ${isCVE ? 'CVE' : 'product'}: ${input}.`,
``,
`Context from dashboard:`,
`CNA: ${cnaName || 'Unknown'}`,
`Description: ${description || 'No description found'}`,
`${kevLine}`,
`${epssLine}`,
``,
`CVSS metrics:`,
`${cvssLines}`,
``,
`CWE(s):`,
`${cweLines}`,
``,
`References (top sources):`,
`${refLines}`,
``,
`Deliverables:`,
`1) Executive summary.`,
`2) Root cause & vulnerable components/conditions.`,
`3) Exploitability (pre-/post-auth, network exposure).`,
`4) Impact & blast radius; key ATT&CK techniques.`,
`5) Detection ideas (logs, artifacts, controls).`,
`6) Mitigation/patch priorities & safe workarounds.`,
`7) Risk scoring rationale (tie to KEV/EPSS/CVSS).`,
``,
`State unknowns explicitly; do not guess.`
].join('\n');
}
/* ---------- Static Analysis ---------- */
function generateStaticAnalysis(ctx) {
const { input, isCVE, cnaName, description, kevYes, ransomwareTag, epss, cvss = [], cwes = [] } = ctx || {};
const cvssText = cvss.length ? cvss.map(m => `- **CVSS v${m.version}**: ${m.score} _(source: ${m.source}; vector: ${m.vector || 'N/A'})_`).join('\n') : '- **CVSS**: No metrics available';
const cweText = cwes.length ? cwes.map(c => `- **${c.id || 'Unknown'}** — ${c.desc || 'No description'} _(Assigner: ${c.assigner || 'Unknown'})_`).join('\n') : '- **CWE**: No data';
const epssText = epss ? `- **EPSS**: ${epss.score?.toFixed(4)} (~${(epss.score * 100).toFixed(2)}% 30-day) — Percentile ${(epss.percentile * 100).toFixed(1)}%` : '- **EPSS**: No data';
const kevText = kevYes ? `- **CISA KEV**: Yes${String(ransomwareTag).toLowerCase() === 'known' ? ' (Known ransomware campaign use)' : ''}` : '- **CISA KEV**: No';
return [
`# ${isCVE ? input : `Analysis: ${input}`}`,
``,
`## Executive Summary`,
`${description || 'No CNA description available.'}`,
``,
`## Root Cause & Vulnerable Components`,
`- Derived from CNA/ADP/NVD records. (If not explicitly stated in the record, root cause details remain **unknown**.)`,
`${cweText}`,
``,
`## Exploitability`,
`- Authentication requirements: **unknown**`,
`- Network exposure: **unknown** (review service exposure, ingress rules, and public endpoints)`,
`- PoC/weaponization: Consult Exploit-DB, PacketStorm, GitHub code searches in *Relevant Searches* panel.`,
``,
`## Impact & Blast Radius`,
`- Impact level per CVSS:`,
`${cvssText}`,
`- Key ATT&CK techniques: **Txxx (unknown)** — map actual artifacts from detections once logs are available.`,
``,
`## Detection Ideas`,
`- Review application/server logs around suspected vulnerable components.`,
`- Look for anomalous inputs aligned to CWE patterns (e.g., injection, deserialization).`,
`- Enable verbose logging/telemetry for exposed services; monitor for IOCs from advisories.`,
``,
`## Mitigation & Patch Priorities`,
`- Apply vendor patches or mitigations referenced in CNA/NVD links.`,
`- If patch unavailable: implement temporary compensating controls (WAF rules, service isolation).`,
`- Prioritize based on KEV/EPSS:`,
`${kevText}`,
`${epssText}`,
``,
`## Risk Scoring Rationale`,
`- Based on the presence/absence of KEV, EPSS percentile, and CVSS base score.`,
`- Adjust per asset exposure, business criticality, and observed exploitation in your environment.`,
``,
`> Generated via static analysis mode (no external AI calls).`
].join('\n');
}
/* ---------- AI Analysis (Edge → Gemini → Enterprise → Static) ---------- */
let __aiSession = null;
let __aiAbort = null;
function openAnalysisModal() { const m = document.getElementById('analysisModal'); const b = document.getElementById('analysisBody'); const s = document.getElementById('analysisStatus'); if (!m || !b || !s) return; b.textContent = ''; s.textContent = 'Preparing analysis…'; m.style.display = 'flex'; }
function closeAnalysisModal() { const m = document.getElementById('analysisModal'); if (m) m.style.display = 'none'; cancelAnalysis(); }
function cancelAnalysis() { try { if (__aiAbort) { __aiAbort.abort(); __aiAbort = null; } if (__aiSession?.destroy) { __aiSession.destroy(); } } catch {} __aiSession = null; }
function downloadAnalysis() { const text = document.getElementById('analysisBody')?.textContent || ''; const blob = new Blob([text], { type: 'text/markdown;charset=utf-8' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'analysis.md'; a.click(); URL.revokeObjectURL(a.href); }
async function runLocalAnalysis(prompt) {
const body = document.getElementById('analysisBody'); const status = document.getElementById('analysisStatus');
if (!('ai' in window) || !window.ai?.createTextSession) { throw new Error('Edge Prompt API unavailable'); }
__aiSession = await window.ai.createTextSession({ systemPrompt: 'You are a security analyst. Be concise, technical, and explicitly note unknowns.', temperature: 0.2, topK: 40 });
status.textContent = 'Generating locally (Edge)…';
const supportsStreaming = !!__aiSession.promptStreaming;
__aiAbort = new AbortController();
if (supportsStreaming) { for await (const chunk of __aiSession.promptStreaming(prompt, { signal: __aiAbort.signal })) { body.textContent += chunk; } }
else { body.textContent = await __aiSession.prompt(prompt); }
status.textContent = 'Complete';
}
async function runAiAnalysis() {
try {
openAnalysisModal();
const inputField = document.getElementById('cve')?.value || '';
const ctx = __lastAnalysisContext || {
input: inputField || 'unknown target',
isCVE: /^CVE-\d{4}-\d{4,}$/i.test(inputField),
cnaName: null,
description: 'No description available yet',
kevYes: false,
ransomwareTag: 'Unknown',
epss: null,
cvss: [],
cwes: [],
referencesGrouped: []
};
const prompt = buildAnalysisPrompt(ctx);
const body = document.getElementById('analysisBody');
const status = document.getElementById('analysisStatus');
// Only attempt browser-native window.ai (Edge/Copilot)
if ('ai' in window && window.ai?.createTextSession) {
try {
status.textContent = 'Generating locally (browser AI)...';
const session = await window.ai.createTextSession({
systemPrompt: 'You are a security analyst. Be concise, technical, and explicitly note unknowns.',
temperature: 0.2,
topK: 40
});
const supportsStreaming = !!session.promptStreaming;
if (supportsStreaming) {
body.textContent = '';
for await (const chunk of session.promptStreaming(prompt)) {
body.textContent += chunk;
}
} else {
body.textContent = await session.prompt(prompt);
}
status.textContent = 'Complete (local browser AI)';
return;
} catch (aiErr) {
console.warn('Browser AI failed:', aiErr);
}
}
// Fallback: static analysis
body.textContent = generateStaticAnalysis(ctx);
status.textContent = 'Static analysis (browser AI not available)';
} catch (e) {
console.error('AI Analysis error:', e);
const status = document.getElementById('analysisStatus');
const body = document.getElementById('analysisBody');
if (status) status.textContent = 'Failed';
if (body) body.textContent = `Error: ${e.message || 'Unexpected error'}`;
toast('Analysis failed. Browser AI may not be supported in this browser.');
}
}
function initInlineAnalysis() {
const btn = document.getElementById('aiAnalysis'); const copyBtn = document.getElementById('analysisCopy');
const saveBtn = document.getElementById('analysisSave'); const cancelBtn= document.getElementById('analysisCancel');
const closeBtn = document.getElementById('analysisClose'); const modal = document.getElementById('analysisModal');
if (btn) btn.onclick = runAiAnalysis;
copyBtn?.addEventListener('click', async () => { try { const text = document.getElementById('analysisBody')?.textContent || ''; await navigator.clipboard.writeText(text); toast('Analysis copied to clipboard'); } catch { toast('Copy failed — select and press Ctrl+C'); } });
saveBtn?.addEventListener('click', downloadAnalysis);
cancelBtn?.addEventListener('click', () => { cancelAnalysis(); toast('Analysis cancelled'); });
closeBtn?.addEventListener('click', closeAnalysisModal);
modal?.addEventListener('click', (e) => { if (e.target.id === 'analysisModal') closeAnalysisModal(); });
}
/* ---------- VulnCheck ---------- */
async function loadVulnCheck() {
try {
const res = await fetch('https://jakewarren.github.io/vulncheck-kev-rss/rss.xml');
const text = await res.text(); const doc = new DOMParser().parseFromString(text, 'application/xml'); const items = doc.querySelectorAll('item');
const now = Date.now(); let html = ""; __lastVulncheckRecent = [];
items.forEach(item => {
const pubDate = new Date(item.querySelector('pubDate')?.textContent || 0).getTime();
if ((now - pubDate) < 10 * 24 * 60 * 60 * 1000) {
const title = item.querySelector('title')?.textContent || ''; const link = item.querySelector('link')?.textContent || '#';
const cveMatch = title.match(/CVE-\d{4}-\d{4,}/); const cve = cveMatch ? cveMatch[0] : 'Unknown CVE';
const product = title.replace(cve, '').replace(/^\s*-\s*/, '').replace(/\s*Vulnerability.*$/i, '').trim() || 'Unknown Product';
html += `<div class="item"><div class="title">${linkRow(link, cve + ' - ' + product)}</div></div>`;
if (cveMatch) __lastVulncheckRecent.push(cve);
}
});
document.getElementById("vulncheckContent").innerHTML = html || '<div class="meta">No recent additions in last 10 days.</div>';
} catch { document.getElementById("vulncheckContent").innerHTML = '<div class="meta">Failed to load VulnCheck data.</div>'; }
}
/* ---------- KEV ---------- */
const KEV_JSON_URLS = [
'https://raw.githubusercontent.com/cisagov/kev-data/develop/known_exploited_vulnerabilities.json',
'https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json'
];
let kevCache = { loaded:false, data:null, ts:0 };
async function loadKEV() {
if (kevCache.loaded && kevCache.data && (Date.now() - kevCache.ts) < 60*60*1000) return kevCache.data;
for (const url of KEV_JSON_URLS) {
try { const res = await fetch(url, { cache:'no-store' }); if (!res.ok) continue; const json = await res.json(); kevCache.data = Array.isArray(json) ? json : (json.vulnerabilities || json); kevCache.loaded = true; kevCache.ts = Date.now(); return kevCache.data; } catch {}
}
throw new Error('Unable to load CISA KEV data');
}
async function getKevEntry(cveId) { const kev = await loadKEV(); const up = cveId.toUpperCase(); return kev.find(e => (e.cveID || e.cveId) === up) || null; }
/* ---------- SSVC helpers ---------- */
/* [unchanged helpers: normalizeSsvcValue, capFirst, extractSsvcDeep] */
function normalizeSsvcValue(val) { return (val || 'N/A').toLowerCase().replace(/^(active|none|proof-of-concept|sporadic)$/i, m => m.toLowerCase()); }
function capFirst(str) { return (str || '').charAt(0).toUpperCase() + str.slice(1); }
function extractSsvcDeep(obj) {
const decisionPoints = { exploitation: 'N/A', automatable: 'N/A', technicalImpact: 'N/A', decision: 'N/A' };
const traverse = (o) => {
if (typeof o !== 'object' || !o) return;
for (const key in o) {
if (key === 'exploitation') decisionPoints.exploitation = normalizeSsvcValue(o[key]);
if (key === 'automatable') decisionPoints.automatable = normalizeSsvcValue(o[key]);
if (key === 'technical_impact') decisionPoints.technicalImpact = normalizeSsvcValue(o[key]);
if (key === 'decision') decisionPoints.decision = normalizeSsvcValue(o[key]);
traverse(o[key]);
}
};
traverse(obj);
return decisionPoints;
}
/* ---------- Vendor/Product helpers ---------- */
/* [unchanged helpers: severityFromScore, classFromScore, tokensFromQuery, cpeTokensMatch, vulnMatchesTokens, fetchNvdCvesByKeyword, renderVendorProductResults, runVendorProductSearch] */
function severityFromScore(score) { return score < 4 ? 'Low' : score < 7 ? 'Medium' : score < 9 ? 'High' : 'Critical'; }
function classFromScore(score) { return score < 4 ? 'low' : score < 7 ? 'medium' : score < 9 ? 'high' : 'critical'; }
function tokensFromQuery(query) { return query.toLowerCase().split(/\s+/).filter(t => t.length > 1); }
function cpeTokensMatch(cpe, tokens) { if (!cpe) return false; const parts = cpe.toLowerCase().split(':'); return tokens.every(t => parts.some(p => p.includes(t))); }
function vulnMatchesTokens(vuln, tokens) { const desc = vuln?.cve?.descriptions?.[0]?.value?.toLowerCase() || ''; const refs = vuln?.cve?.references?.flatMap(r => r.url.toLowerCase() || []) || []; return tokens.every(t => desc.includes(t) || refs.some(u => u.includes(t))); }
async function fetchNvdCvesByKeyword(keyword) {
try { const res = await fetch(`https://services.nvd.nist.gov/rest/json/cves/2.0?keywordSearch=${encodeURIComponent(keyword)}&resultsPerPage=20`); return await res.json(); } catch { return { vulnerabilities: [] }; }
}
function renderVendorProductResults(json) {
const vulns = json.vulnerabilities || [];
let html = '';
vulns.forEach(vuln => {
const cve = vuln?.cve; if (!cve) return;
const id = cve.id || 'Unknown';
const desc = cve.descriptions?.[0]?.value || 'No description';
const score = cve.metrics?.cvssMetricV31?.[0]?.cvssData?.baseScore || 0;
const sev = severityFromScore(score);
const cls = classFromScore(score);
html += `<div class="item"><div class="title">${id} <span class="chip ${cls}">${sev} (${score})</span></div><div class="meta">${desc}</div></div>`;
});
const content = document.getElementById('cveContent');
content.innerHTML = html || '<div class="meta">No matching vulnerabilities found.</div>';
renderRelevantSearches(keyword);
}
async function runVendorProductSearch(keyword) {
const loadingEl = document.getElementById("loading"); if (loadingEl) loadingEl.style.display = "flex";
try {
const json = await fetchNvdCvesByKeyword(keyword);
renderVendorProductResults(json);
} catch (err) {
document.getElementById("cveContent").innerHTML = `<div class="meta">Error loading data: ${err.message}</div>`;
renderRelevantSearches(keyword);
} finally { if (loadingEl) loadingEl.style.display = "none"; }
}
/* ---------- CVE flow ---------- */
/* [unchanged: isCVE, runSearch] */
function isCVE(str){ return /^CVE-\d{4}-\d{4,}$/i.test(str); }
async function runSearch() {
const inputRaw = (document.getElementById("cve")?.value || "").trim();
const input = inputRaw.toUpperCase();
// If not CVE, delegate to vendor/product search
if (!isCVE(input)) {
if (inputRaw.length < 2) {
toast("Enter at least 2 characters for vendor/product search");
return;
}
return runVendorProductSearch(inputRaw);
}
// Show loading overlay
const loadingEl = document.getElementById("loading");
if (loadingEl) loadingEl.style.display = "flex";
// --- helper: try KEV date from multiple sources (feed + localStorage map) ---
function getKevAddedDate(kevObj, cveIdUpper) {
// 1) direct from the object returned by loadKEV()
let d = '';
if (kevObj) {
d = kevObj.dateAdded || kevObj.date_added || '';
if (d) return d;
}
// 2) fallback to the watcher map persisted in localStorage
try {
const map = JSON.parse(localStorage.getItem('cveWatcher.kevMap') || '{}') || {};
const entry = map[cveIdUpper];
if (entry) {
return entry.dateAdded || entry.date_added || '';
}
} catch { /* ignore parse errors */ }
// 3) no date found
return '';
}
try {
// Fetch CNA (CVE Services), NVD, EPSS in parallel
const [cveRes, nvdRes, epssRes] = await Promise.all([
fetch(`https://cveawg.mitre.org/api/cve/${input}`),
fetch(`https://services.nvd.nist.gov/rest/json/cves/2.0?cveId=${input}`),
fetch(`https://api.first.org/data/v1/epss?cve=${input}`)
]);
if (!cveRes.ok) throw new Error("CVE not found");
// KEV + ransomware tag
const kevEntry = await getKevEntry(input).catch(() => null);
const kevYes = !!kevEntry;
const ransomwareTag = kevEntry ? (kevEntry.knownRansomwareCampaignUse || 'Unknown') : 'Unknown';
// ✅ robust KEV date resolution
const kevDateRaw = getKevAddedDate(kevEntry, input);
const kevAddedPretty = kevDateRaw ? new Date(kevDateRaw).toLocaleDateString() : '';
const kevLabel = kevYes
? `CISA KEV: Yes${kevAddedPretty ? ` — Added: ${kevAddedPretty}` : ''}`
: 'CISA KEV: No';
// CNA record
const cveData = await cveRes.json();
const cna = cveData?.containers?.cna || {};
const desc = cna?.descriptions?.[0]?.value || "No description";
const cnaName = cna?.providerMetadata?.shortName || "Unknown";
const adpProviders = Array.isArray(cveData?.containers?.adp) ? cveData.containers.adp : [];
const published = cveData.cveMetadata?.datePublished
? new Date(cveData.cveMetadata.datePublished).toLocaleDateString()
: 'N/A';
// SSVC block (best effort)
let ssvcInlineHtml = '';
try {
const allMetrics = (adpProviders || [])
.flatMap(p => (p.metrics || []).map(m => ({ provider: p, metric: m })));
const ssvcMetricEntry =
allMetrics.find(({ provider, metric }) =>
(provider?.providerMetadata?.shortName || '').toLowerCase().includes('cisa') &&
metric?.other && String(metric.other.type || '').toLowerCase() === 'ssvc'
) ||
allMetrics.find(({ metric }) =>
metric?.other && String(metric.other.type || '').toLowerCase() === 'ssvc'
);
const ssvcContent = ssvcMetricEntry?.metric?.other?.content;
const parsed = extractSsvcDeep(ssvcContent);
const exploitation = capFirst(parsed.exploitation);
const automatable = capFirst(parsed.automatable);
const technicalImpact = capFirst(parsed.technicalImpact);
const decision = capFirst(parsed.decision);
const providerName = ssvcMetricEntry?.provider?.providerMetadata?.shortName || 'ADP';
ssvcInlineHtml = `
<div class="metrics-box">
<div class="title">SSVC Metrics (${providerName})</div>
<table>
<tr><th>Exploitation</th><td>${exploitation}</td></tr>
<tr><th>Automatable</th><td>${automatable}</td></tr>
<tr><th>Technical Impact</th><td>${technicalImpact}</td></tr>
${decision !== 'N/A' ? `<tr><th>Decision</th><td>${decision}</td></tr>` : ''}
</table>
</div>`;
if (!ssvcMetricEntry || !ssvcContent) {
ssvcInlineHtml = `
<div class="metrics-box">