khulnasoft commited on
Commit
95a5333
1 Parent(s): a02da4a

Update cvss.js

Browse files
Files changed (1) hide show
  1. cvss.js +446 -586
cvss.js CHANGED
@@ -1,608 +1,468 @@
1
- // work in progress
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- vectorMap4 = {
4
- "attackVector": "AV",
5
- "attackComplexity": "AC",
6
- "attackRequirements": "AT",
7
- "privilegesRequired": "PR",
8
- "userInteraction": "UI",
9
- "vulnConfidentialityImpact": "VC",
10
- "vulnIntegrityImpact": "VI",
11
- "vulnAvailabilityImpact": "VA",
12
- "subConfidentialityImpact": "SC",
13
- "subIntegrityImpact": "SI",
14
- "subAvailabilityImpact": "SA",
15
- "Safety": "S",
16
- "Automatable": "AU",
17
- "Recovery": "R",
18
- "valueDensity": "V",
19
- "vulnerabilityResponseEffort": "RE",
20
- "providerUrgency": "U",
21
- "exploitMaturity": "E"
22
- };
23
-
24
- function invertObject(obj) {
25
- const inverted = {};
26
- for (const key in obj) {
27
- inverted[obj[key]] = key;
28
- }
29
- return inverted;
30
- }
31
-
32
 
33
- var metricMap4 = invertObject(vectorMap4);
34
-
35
- var valueMap = {
36
- "UNDEFINED": "X",
37
- "GREEN": "Green",
38
- "RED": "Red",
39
- "CLEAR": "Clear",
40
- "AMBER": "Amber"
41
- };
42
 
43
- function vector(cv){
44
- var v = "CVSS:4.0";
45
- for(const key in metricMap4) {
46
- if(cv[key])
47
- v = v + '/' + key + ':' + cv[key]
48
- }
49
- return v;
50
- }
51
 
52
- function vectorize(c) {
53
- var cv = {};
54
- for(const key in c){
55
- var m = vectorMap4[key];
56
- var v = undefined;
57
- console.log(key +'='+ c[key])
58
- if(m && c[key]) {
59
- v = valueMap[c[key]] || c[key].charAt(0);
60
- }
61
- if(v) {
62
- cv[m]=v;
63
- }
64
- }
65
- return cv;
66
- }
67
 
68
- function vectorizeString(s) {
69
- var cv = {};
70
- var metrics = s.split("/");
71
- for(index in metrics) {
72
- var [key, value] = metrics[index].split(":");
73
- cv[key] = value;
74
- }
75
- return cv;
76
- }
 
 
77
 
78
- function macroVector(cvss) {
79
- var c = vectorize(cvss);
 
 
 
 
80
 
81
- var N='N', P='P', X='X', H='H', L='L', R='R', S = 'S';
 
 
 
 
 
82
 
83
- var av = c.AV,
84
- ac = c.AC,
85
- ui = c.UI,
86
- at = c.AT,
87
- pr = c.PR,
88
- vc = c.VC,
89
- va = c.VA,
90
- vi = c.VI,
91
- sc = c.SC,
92
- si = c.SI,
93
- sa = c.SA,
94
- e = e,
95
- cr = c.CR,
96
- ir = c.IR,
97
- ar = c.AR,
98
- msi = c.MSI,
99
- msa = c.MSA
100
- ;
101
 
102
- if([vc, vi, va, sc, si, sa].every((met) => met == N)) {
103
- return 0;
104
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
- // Compute EQs
108
- // => EQ1 - Table 25
109
- var eq = [];
110
- eq[1] = 0;
111
- if(av == N && pr == N && ui == N) {
112
- eq[1] = 0
113
- } else if ((av == N || pr == N || ui == N) && !(av == N && pr == N && ui == N) && !(av == P)) {
114
- eq[1] = 1
115
- } else if (av == P || !(av == N || pr == N || ui == N)) {
116
- eq[1] = 2
117
- } else {
118
- console.log("EQ1 invalid CVSS configuration: AV:%s/PR:%s/UI:%s\n", av, pr, ui);
119
- return undefined;
120
- }
121
- // => EQ2 - Table 26
122
- eq[2] = 0
123
- if (ac == L && at == N) {
124
- eq[2] = 0
125
- } else if (!(ac == L && at == N)) {
126
- eq[2] = 1
127
- } else {
128
- console.log("EQ2 invalid CVSS configuration: AC:%s/AT:%s\n", ac, at)
129
- return undefined;
130
- }
131
- // => EQ3 - Table 27
132
- eq[3] = 0;
133
- if(vc == H && vi == H){
134
- eq[3] = 0
135
- } else if (!(vc == H && vi == H) && (vc == H || vi == H || va == H)) {
136
- eq[3] = 1
137
- } else if (!(vc == H || vi == H || va == H)) {
138
- eq[3] = 2
139
- } else {
140
- console.log("EQ3 invalid CVSS configuration: VC:%s/VI:%s/VA:%s\n", vc, vi, va)
141
- return undefined;
142
-
143
- }
144
- // => EQ4 - Table 28
145
- eq[4] = 0
146
- if (msi == S || msa == S) {
147
- eq[4] = 0
148
- } else if (!(msi == S && msa == S) && (sc == H || si == H || sa == H)) {
149
- eq[4] = 1
150
- } else if (!(msi == S && msa == S) && !(sc == H || si == H || sa == H)) {
151
- eq[4] = 2
152
- } else {
153
- console.log("EQ4 invalid CVSS configuration: MSI:%s/MSA:%s/SC:%s/SI:%s/SA:%s\n", msi, msa, cvss40.get("SC"), cvss40.get("SI"), cvss40.get("SA"))
154
- return undefined;
155
- }
156
- // => EQ5 - Table 29
157
- eq[5] = 0
158
- if (e == "A" || e == X || e == undefined) {
159
- eq[5] = 0
160
- } else if (e == "P") {
161
- eq[5] = 1
162
- } else if (e == "U") {
163
- eq[5] = 2
164
- } else {
165
- console.log("EQ5 invalid CVSS configuration: E:%s\n", e)
166
- return undefined;
167
- }
168
- // => EQ6 - Table 30
169
- eq[6] = 0
170
- if (av == N && pr == N && ui == N) {
171
- eq[6] = 0
172
- } else if ((cr == H && vc == H) || (c.IR == H && vi == H) || (c.AR == H && va == H) ){
173
- eq[6] = 1
174
- } else {
175
- console.log("EQ6 invalid CVSS configuration: AV:%s/PR:%s/UI:%s/CR:%s/VC:%s/IR:%s/VI:%s/AR:%s/VA:%s\n", av, pr, ui, cr, vc, c.IR, vi)
176
- return undefined;
177
-
178
- }
179
- // => EQ3+EQ6 - Table 31
180
- eq[7]= 0
181
- if (vc == H && vi == H && (cr == H || ir == H || (ar == H && va == H))) {
182
- eq[7] = '00';
183
- } else if (vc == H && vi == H && !(cr == H || ir == H) && !(ar == H && va == H)) {
184
- eq[7] = '01';
185
- } else if (!(vc == H && vi == H) && (vc == H || vi == H || va == H) && (cr == H && vc == H) || (ir == H && vi == H) || (ar == H && va == H)) {
186
- eq[7] = 10;
187
- } else if (!(vc == H && vi == H) && (vc == H || vi == H || va == H) && !(cr == H && vc == H) && !(ir == H && vi == H) && !(ar == H && va == H)) {
188
- eq[7] = 11;
189
- } else if (!(vc == H || vi == H || va == H) && (cr == H && vc == H) || (ir == H && vi == H) || (ar == H && va == H)){
190
- eq[7] = 20;
191
- } else if (!(vc == H || vi == H || va == H) && !(cr == H && vc == H) && !(ir == H && vi == H) && !(ar == H && va == H)) {
192
- eq[7] = 21;
193
- } else {
194
- console.log("EQ36 invalid CVSS configuration: CR:%s/VC:%s/IR:%s/VI:%s/AR:%s/VA:%s\n", cr, vc, ir, vi, ar, va)
195
- return undefined;
196
- }
197
- var current = eq;
198
- var diff = [];
199
- var currentScore = lookup(eq);
200
- for(const eqSet = 1; eqSet < 7; eqSet++) {
201
- var lowSet = Array.from(originalArray);
202
- lowSet[eqSet] = lowSet[eqSet]+1;
203
- var lowScore = lookup(lowSet);
204
- var maxDiff = currentScore - lowScore;
205
- var mV = maxVectors(eqSet);
206
- var hammingDistance = 0;
207
- for(const m in mV) {
208
- var hd = getHammingDistance(c, vectorizeString(m));
209
- if(hd > hammingDistance) {
210
- hammingDistance = hd;
211
- }
212
- }
213
- var prop = hammingDistance/depth;
214
- diff[eqSet] = maxDiff * prop;
215
- }
216
- }
217
 
218
- function getHammingDistance(a, b) {
219
- var dist = {};
220
- for(const key in a) {
221
- dist[key] = levels[key][a[key]] - levels[key][b[key]];
222
- }
223
- if(a.MSI == 'S') {
224
- dist.SI = levels.SI['S'] - levels.SI[b.SI]
225
- }
226
- if(a.MSA == 'S') {
227
- dist.SI = levels.SA['S'] - levels.SA[b.SA]
228
- }
229
- var ret = 0;
230
- for(const key in dist) {
231
- ret = ret + Math.abs(dist[key]);
232
- }
233
- return ret;
234
- }
235
 
236
- const maxHamming = {
237
- "eq1" : {
238
- "0" : 1,
239
- "1" : 4,
240
- "2" : 5
241
- },
242
- "eq2" : {
243
- "0" : 1,
244
- "1" : 2
245
- },
246
- "eq3" : {
247
- "00": 7,
248
- "01": 6,
249
- "10": 8,
250
- "11": 8,
251
- "21": 10
252
- },
253
- "eq4" : {
254
- "0" : 6,
255
- "1" : 5,
256
- "2" : 4
257
 
258
- },
259
- "eq5" : {
260
- "0" : 1,
261
- "1" : 1,
262
- "2" : 1
263
- },
264
- }
265
 
266
- function maxVectors(eqSet, eqVal) {
267
- return maxComposed[eqSet-1][eqVal];
268
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
 
270
- const maxComposed = [
271
- {
272
- "0": ["AV:N/PR:N/UI:N/"],
273
- "1" : ["AV:A/PR:N/UI:N/","AV:N/PR:L/UI:N/","AV:N/PR:N/UI:P/"],
274
- "2": ["AV:P/PR:N/UI:N/","AV:A/PR:L/UI:P/"]
275
- },
276
- {
277
- "0" : ["AC:L/AT:N/"],
278
- "1" : ["AC:H/AT:N/","AC:L/AT:P/"]
279
- },
280
- {
281
- "00": ["VC:H/VI:H/VA:H/CR:H/IR:H/AR:H/"],
282
- "01": ["VC:H/VI:H/VA:L/CR:M/IR:M/AR:H/","VC:H/VI:H/VA:H/CR:M/IR:M/AR:M/"],
283
- "10": ["VC:L/VI:H/VA:H/CR:H/IR:H/AR:H/","VC:H/VI:L/VA:H/CR:H/IR:H/AR:H/"],
284
- "11": ["VC:L/VI:H/VA:L/CR:H/IR:M/AR:H/","VC:L/VI:H/VA:H/CR:H/IR:M/AR:M/","VC:H/VI:L/VA:H/CR:M/IR:H/AR:M/","VC:H/VI:L/VA:L/CR:M/IR:H/AR:H/","VC:L/VI:L/VA:H/CR:H/IR:H/AR:M/"],
285
- "21": ["VC:L/VI:L/VA:L/CR:H/IR:H/AR:H/"]
286
- },
287
- {
288
- "0" : ["SC:H/SI:S/SA:S/"],
289
- "1" : ["SC:H/SI:H/SA:H/"],
290
- "2" : ["SC:L/SI:L/SA:L/"]
291
 
292
- },
293
- {
294
- "0" : ["E:A/"],
295
- "1" : ["E:P/"],
296
- "2" : ["E:U/"],
297
- },
298
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
- function lookup(m) {
301
- var score = lookuptable[m.join('');
302
- return score;
303
- }
 
304
 
305
- const lookuptable = {
306
- "000000": 10,
307
- "000001": 9.9,
308
- "000010": 9.8,
309
- "000011": 9.5,
310
- "000020": 9.5,
311
- "000021": 9.2,
312
- "000100": 10,
313
- "000101": 9.6,
314
- "000110": 9.3,
315
- "000111": 8.7,
316
- "000120": 9.1,
317
- "000121": 8.1,
318
- "000200": 9.3,
319
- "000201": 9,
320
- "000210": 8.9,
321
- "000211": 8,
322
- "000220": 8.1,
323
- "000221": 6.8,
324
- "001000": 9.8,
325
- "001001": 9.5,
326
- "001010": 9.5,
327
- "001011": 9.2,
328
- "001020": 9,
329
- "001021": 8.4,
330
- "001100": 9.3,
331
- "001101": 9.2,
332
- "001110": 8.9,
333
- "001111": 8.1,
334
- "001120": 8.1,
335
- "001121": 6.5,
336
- "001200": 8.8,
337
- "001201": 8,
338
- "001210": 7.8,
339
- "001211": 7,
340
- "001220": 6.9,
341
- "001221": 4.8,
342
- "002001": 9.2,
343
- "002011": 8.2,
344
- "002021": 7.2,
345
- "002101": 7.9,
346
- "002111": 6.9,
347
- "002121": 5,
348
- "002201": 6.9,
349
- "002211": 5.5,
350
- "002221": 2.7,
351
- "010000": 9.9,
352
- "010001": 9.7,
353
- "010010": 9.5,
354
- "010011": 9.2,
355
- "010020": 9.2,
356
- "010021": 8.5,
357
- "010100": 9.5,
358
- "010101": 9.1,
359
- "010110": 9,
360
- "010111": 8.3,
361
- "010120": 8.4,
362
- "010121": 7.1,
363
- "010200": 9.2,
364
- "010201": 8.1,
365
- "010210": 8.2,
366
- "010211": 7.1,
367
- "010220": 7.2,
368
- "010221": 5.3,
369
- "011000": 9.5,
370
- "011001": 9.3,
371
- "011010": 9.2,
372
- "011011": 8.5,
373
- "011020": 8.5,
374
- "011021": 7.3,
375
- "011100": 9.2,
376
- "011101": 8.2,
377
- "011110": 8,
378
- "011111": 7.2,
379
- "011120": 7,
380
- "011121": 5.9,
381
- "011200": 8.4,
382
- "011201": 7,
383
- "011210": 7.1,
384
- "011211": 5.2,
385
- "011220": 5,
386
- "011221": 3,
387
- "012001": 8.6,
388
- "012011": 7.5,
389
- "012021": 5.2,
390
- "012101": 7.1,
391
- "012111": 5.2,
392
- "012121": 2.9,
393
- "012201": 6.3,
394
- "012211": 2.9,
395
- "012221": 1.7,
396
- "100000": 9.8,
397
- "100001": 9.5,
398
- "100010": 9.4,
399
- "100011": 8.7,
400
- "100020": 9.1,
401
- "100021": 8.1,
402
- "100100": 9.4,
403
- "100101": 8.9,
404
- "100110": 8.6,
405
- "100111": 7.4,
406
- "100120": 7.7,
407
- "100121": 6.4,
408
- "100200": 8.7,
409
- "100201": 7.5,
410
- "100210": 7.4,
411
- "100211": 6.3,
412
- "100220": 6.3,
413
- "100221": 4.9,
414
- "101000": 9.4,
415
- "101001": 8.9,
416
- "101010": 8.8,
417
- "101011": 7.7,
418
- "101020": 7.6,
419
- "101021": 6.7,
420
- "101100": 8.6,
421
- "101101": 7.6,
422
- "101110": 7.4,
423
- "101111": 5.8,
424
- "101120": 5.9,
425
- "101121": 5,
426
- "101200": 7.2,
427
- "101201": 5.7,
428
- "101210": 5.7,
429
- "101211": 5.2,
430
- "101220": 5.2,
431
- "101221": 2.5,
432
- "102001": 8.3,
433
- "102011": 7,
434
- "102021": 5.4,
435
- "102101": 6.5,
436
- "102111": 5.8,
437
- "102121": 2.6,
438
- "102201": 5.3,
439
- "102211": 2.1,
440
- "102221": 1.3,
441
- "110000": 9.5,
442
- "110001": 9,
443
- "110010": 8.8,
444
- "110011": 7.6,
445
- "110020": 7.6,
446
- "110021": 7,
447
- "110100": 9,
448
- "110101": 7.7,
449
- "110110": 7.5,
450
- "110111": 6.2,
451
- "110120": 6.1,
452
- "110121": 5.3,
453
- "110200": 7.7,
454
- "110201": 6.6,
455
- "110210": 6.8,
456
- "110211": 5.9,
457
- "110220": 5.2,
458
- "110221": 3,
459
- "111000": 8.9,
460
- "111001": 7.8,
461
- "111010": 7.6,
462
- "111011": 6.7,
463
- "111020": 6.2,
464
- "111021": 5.8,
465
- "111100": 7.4,
466
- "111101": 5.9,
467
- "111110": 5.7,
468
- "111111": 5.7,
469
- "111120": 4.7,
470
- "111121": 2.3,
471
- "111200": 6.1,
472
- "111201": 5.2,
473
- "111210": 5.7,
474
- "111211": 2.9,
475
- "111220": 2.4,
476
- "111221": 1.6,
477
- "112001": 7.1,
478
- "112011": 5.9,
479
- "112021": 3,
480
- "112101": 5.8,
481
- "112111": 2.6,
482
- "112121": 1.5,
483
- "112201": 2.3,
484
- "112211": 1.3,
485
- "112221": 0.6,
486
- "200000": 9.3,
487
- "200001": 8.7,
488
- "200010": 8.6,
489
- "200011": 7.2,
490
- "200020": 7.5,
491
- "200021": 5.8,
492
- "200100": 8.6,
493
- "200101": 7.4,
494
- "200110": 7.4,
495
- "200111": 6.1,
496
- "200120": 5.6,
497
- "200121": 3.4,
498
- "200200": 7,
499
- "200201": 5.4,
500
- "200210": 5.2,
501
- "200211": 4,
502
- "200220": 4,
503
- "200221": 2.2,
504
- "201000": 8.5,
505
- "201001": 7.5,
506
- "201010": 7.4,
507
- "201011": 5.5,
508
- "201020": 6.2,
509
- "201021": 5.1,
510
- "201100": 7.2,
511
- "201101": 5.7,
512
- "201110": 5.5,
513
- "201111": 4.1,
514
- "201120": 4.6,
515
- "201121": 1.9,
516
- "201200": 5.3,
517
- "201201": 3.6,
518
- "201210": 3.4,
519
- "201211": 1.9,
520
- "201220": 1.9,
521
- "201221": 0.8,
522
- "202001": 6.4,
523
- "202011": 5.1,
524
- "202021": 2,
525
- "202101": 4.7,
526
- "202111": 2.1,
527
- "202121": 1.1,
528
- "202201": 2.4,
529
- "202211": 0.9,
530
- "202221": 0.4,
531
- "210000": 8.8,
532
- "210001": 7.5,
533
- "210010": 7.3,
534
- "210011": 5.3,
535
- "210020": 6,
536
- "210021": 5,
537
- "210100": 7.3,
538
- "210101": 5.5,
539
- "210110": 5.9,
540
- "210111": 4,
541
- "210120": 4.1,
542
- "210121": 2,
543
- "210200": 5.4,
544
- "210201": 4.3,
545
- "210210": 4.5,
546
- "210211": 2.2,
547
- "210220": 2,
548
- "210221": 1.1,
549
- "211000": 7.5,
550
- "211001": 5.5,
551
- "211010": 5.8,
552
- "211011": 4.5,
553
- "211020": 4,
554
- "211021": 2.1,
555
- "211100": 6.1,
556
- "211101": 5.1,
557
- "211110": 4.8,
558
- "211111": 1.8,
559
- "211120": 2,
560
- "211121": 0.9,
561
- "211200": 4.6,
562
- "211201": 1.8,
563
- "211210": 1.7,
564
- "211211": 0.7,
565
- "211220": 0.8,
566
- "211221": 0.2,
567
- "212001": 5.3,
568
- "212011": 2.4,
569
- "212021": 1.4,
570
- "212101": 2.4,
571
- "212111": 1.2,
572
- "212121": 0.5,
573
- "212201": 1,
574
- "212211": 0.3,
575
- "212221": 0.1
576
- }
577
 
578
- function getLevel(m,v) {
579
- return levels[m][v]
580
- }
 
 
 
 
 
 
581
 
582
- const levels = {
583
- 'AV': {"N": 0.0, "A": 0.1, "L": 0.2, "P": 0.3},
584
- 'PR': {"N": 0.0, "L": 0.1, "H": 0.2},
585
- 'UI': {"N": 0.0, "P": 0.1, "A": 0.2},
586
- 'AC': {'L':0.0, 'H':0.1},
587
- 'AT': {'N':0.0, 'P':0.1},
588
- 'VC': {'H':0.0, 'L':0.1, 'N':0.2},
589
- 'VI': {'H':0.0, 'L':0.1, 'N':0.2},
590
- 'VA': {'H':0.0, 'L':0.1, 'N':0.2},
591
- 'SC': {'H':0.1, 'L':0.2, 'N':0.3},
592
- 'SI': {'S':0.0, 'H':0.1, 'L':0.2, 'N':0.3},
593
- 'SA': {'S':0.0, 'H':0.1, 'L':0.2, 'N':0.3},
594
- 'CR': {'H':0.0, 'M':0.1, 'L':0.2},
595
- 'IR': {'H':0.0, 'M':0.1, 'L':0.2},
596
- 'AR': {'H':0.0, 'M':0.1, 'L':0.2},
597
- 'E': {'U': 0.2, 'P': 0.1, 'A': 0}
598
- }
 
 
 
 
 
 
599
 
600
- function score(mv) {
601
- var eq1 = mv[0],
602
- eq2 = mv[1],
603
- eq3 = mv[2],
604
- eq4 = mv[3],
605
- eq5 = mv[4],
606
- eq6 = mv[5],
607
- eq36 = mv[6];
608
- }
 
 
 
 
1
+ /* Copyright (c) 2015-2019, Chandan B.N.
2
+ *
3
+ * Copyright (c) 2019, FIRST.ORG, INC
4
+ *
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
8
+ * following conditions are met:
9
+ * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10
+ * disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
12
+ * following disclaimer in the documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
14
+ * products derived from this software without specific prior written permission.
15
+ *
16
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
17
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+ */
24
 
25
+ /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ CVSSjs Version 0.1 beta
 
 
 
 
 
 
 
 
28
 
29
+ Usage:
30
+ craete an html element with an id for eg.,
31
+ <div id="cvssboard"></div>
 
 
 
 
 
32
 
33
+ // create a new instance of CVSS calculator:
34
+ var c = new CVSS("cvssboard");
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ // create a new instance of CVSS calculator with some event handler callbacks
37
+ var c = new CVSS("cvssboard", {
38
+ onchange: function() {....} //optional
39
+ onsubmit: function() {....} //optional
40
+ }
41
+
42
+ // set a vector
43
+ c.set('AV:L/AC:L/PR:N/UI:N/S:C/C:N/I:N/A:L');
44
+
45
+ //get the value
46
+ c.get() returns an object like:
47
 
48
+ {
49
+ score: 4.3,
50
+ vector: 'AV:L/AC:L/PR:N/UI:N/S:C/C:N/I:N/A:L'
51
+ }
52
+
53
+ */
54
 
55
+ var CVSS = function (id, options) {
56
+ this.options = options;
57
+ this.wId = id;
58
+ var e = function (tag) {
59
+ return document.createElement(tag);
60
+ };
61
 
62
+ // Base Group
63
+ this.bg = {
64
+ AV: 'Attack Vector',
65
+ AC: 'Attack Complexity',
66
+ PR: 'Privileges Required',
67
+ UI: 'User Interaction',
68
+ S: 'Scope',
69
+ C: 'Confidentiality',
70
+ I: 'Integrity',
71
+ A: 'Availability'
72
+ };
 
 
 
 
 
 
 
73
 
74
+ // Base Metrics
75
+ this.bm = {
76
+ AV: {
77
+ N: {
78
+ l: 'Network',
79
+ d: "<b>Worst:</b> The vulnerable component is bound to the network stack and the set of possible attackers extends beyond the other options listed below, up to and including the entire Internet. Such a vulnerability is often termed “remotely exploitable” and can be thought of as an attack being exploitable at the protocol level one or more network hops away (e.g., across one or more routers)."
80
+ },
81
+ A: {
82
+ l: 'Adjacent',
83
+ d: "<b>Worse:</b> The vulnerable component is bound to the network stack, but the attack is limited at the protocol level to a logically adjacent topology. This can mean an attack must be launched from the same shared physical (e.g., Bluetooth or IEEE 802.11) or logical (e.g., local IP subnet) network, or from within a secure or otherwise limited administrative domain (e.g., MPLS, secure VPN to an administrative network zone). One example of an Adjacent attack would be an ARP (IPv4) or neighbor discovery (IPv6) flood leading to a denial of service on the local LAN segment."
84
+ },
85
+ L: {
86
+ l: 'Local',
87
+ d: "<b>Bad:</b> The vulnerable component is not bound to the network stack and the attacker’s path is via read/write/execute capabilities. Either: <ul><li>the attacker exploits the vulnerability by accessing the target system locally (e.g., keyboard, console), or remotely (e.g., SSH);</li><li>or the attacker relies on User Interaction by another person to perform actions required to exploit the vulnerability (e.g., using social engineering techniques to trick a legitimate user into opening a malicious document).</li></ul>"
88
+ },
89
+ P: {
90
+ l: 'Physical',
91
+ d: "<b>Bad:</b> The attack requires the attacker to physically touch or manipulate the vulnerable component. Physical interaction may be brief (e.g., evil maid attack) or persistent. An example of such an attack is a cold boot attack in which an attacker gains access to disk encryption keys after physically accessing the target system. Other examples include peripheral attacks via FireWire/USB Direct Memory Access (DMA)."
92
+ }
93
+ },
94
+ AC: {
95
+ L: {
96
+ l: 'Low',
97
+ d: "<b>Worst:</b> Specialized access conditions or extenuating circumstances do not exist. An attacker can expect repeatable success when attacking the vulnerable component."
98
+ },
99
+ H: {
100
+ l: 'High',
101
+ d: "<b>Bad:</b> A successful attack depends on conditions beyond the attacker's control. That is, a successful attack cannot be accomplished at will, but requires the attacker to invest in some measurable amount of effort in preparation or execution against the vulnerable component before a successful attack can be expected."
102
+ }
103
+ },
104
+ PR: {
105
+ N: {
106
+ l: 'None',
107
+ d: "<b>Worst:</b> The attacker is unauthorized prior to attack, and therefore does not require any access to settings or files of the the vulnerable system to carry out an attack."
108
+ },
109
+ L: {
110
+ l: 'Low',
111
+ d: "<b>Worse</b> The attacker requires privileges that provide basic user capabilities that could normally affect only settings and files owned by a user. Alternatively, an attacker with Low privileges has the ability to access only non-sensitive resources."
112
+ },
113
+ H: {
114
+ l: 'High',
115
+ d: "<b>Bad:</b> The attacker requires privileges that provide significant (e.g., administrative) control over the vulnerable component allowing access to component-wide settings and files."
116
+ }
117
+ },
118
+ UI: {
119
+ N: {
120
+ l: 'None',
121
+ d: "<b>Worst:</b> The vulnerable system can be exploited without interaction from any user."
122
+ },
123
+ R: {
124
+ l: 'Required',
125
+ d: "<b>Bad:</b> Successful exploitation of this vulnerability requires a user to take some action before the vulnerability can be exploited. For example, a successful exploit may only be possible during the installation of an application by a system administrator."
126
+ }
127
+ },
128
 
129
+ S: {
130
+ C: {
131
+ l: 'Changed',
132
+ d: "<b>Worst:</b> An exploited vulnerability can affect resources beyond the security scope managed by the security authority of the vulnerable component. In this case, the vulnerable component and the impacted component are different and managed by different security authorities."
133
+ },
134
+ U: {
135
+ l: 'Unchanged',
136
+ d: "<b>Bad:</b> An exploited vulnerability can only affect resources managed by the same security authority. In this case, the vulnerable component and the impacted component are either the same, or both are managed by the same security authority."
137
+ }
138
+ },
139
+ C: {
140
+ H: {
141
+ l: 'High',
142
+ d: "<b>Worst:</b> There is a total loss of confidentiality, resulting in all resources within the impacted component being divulged to the attacker. Alternatively, access to only some restricted information is obtained, but the disclosed information presents a direct, serious impact. For example, an attacker steals the administrator's password, or private encryption keys of a web server."
143
+ },
144
+ L: {
145
+ l: 'Low',
146
+ d: "<b>Bad:</b> There is some loss of confidentiality. Access to some restricted information is obtained, but the attacker does not have control over what information is obtained, or the amount or kind of loss is limited. The information disclosure does not cause a direct, serious loss to the impacted component."
147
+ },
148
+ N: {
149
+ l: 'None',
150
+ d: "<b>Good:</b> There is no loss of confidentiality within the impacted component."
151
+ }
152
+ },
153
+ I: {
154
+ H: {
155
+ l: 'High',
156
+ d: "<b>Worst:</b> There is a total loss of integrity, or a complete loss of protection. For example, the attacker is able to modify any/all files protected by the impacted component. Alternatively, only some files can be modified, but malicious modification would present a direct, serious consequence to the impacted component."
157
+ },
158
+ L: {
159
+ l: 'Low',
160
+ d: "<b>Bad:</b> Modification of data is possible, but the attacker does not have control over the consequence of a modification, or the amount of modification is limited. The data modification does not have a direct, serious impact on the impacted component."
161
+ },
162
+ N: {
163
+ l: 'None',
164
+ d: "<b>Good:</b> There is no loss of integrity within the impacted component."
165
+ }
166
+ },
167
+ A: {
168
+ H: {
169
+ l: 'High',
170
+ d: "<b>Worst:</b> There is a total loss of availability, resulting in the attacker being able to fully deny access to resources in the impacted component; this loss is either sustained (while the attacker continues to deliver the attack) or persistent (the condition persists even after the attack has completed). Alternatively, the attacker has the ability to deny some availability, but the loss of availability presents a direct, serious consequence to the impacted component (e.g., the attacker cannot disrupt existing connections, but can prevent new connections; the attacker can repeatedly exploit a vulnerability that, in each instance of a successful attack, leaks a only small amount of memory, but after repeated exploitation causes a service to become completely unavailable)."
171
+ },
172
+ L: {
173
+ l: 'Low',
174
+ d: "<b>Bad:</b> Performance is reduced or there are interruptions in resource availability. Even if repeated exploitation of the vulnerability is possible, the attacker does not have the ability to completely deny service to legitimate users. The resources in the impacted component are either partially available all of the time, or fully available only some of the time, but overall there is no direct, serious consequence to the impacted component."
175
+ },
176
+ N: {
177
+ l: 'None',
178
+ d: "<b>Good:</b> There is no impact to availability within the impacted component."
179
+ }
180
+ }
181
+ };
182
+
183
+ this.bme = {};
184
+ this.bmgReg = {
185
+ AV: 'NALP',
186
+ AC: 'LH',
187
+ PR: 'NLH',
188
+ UI: 'NR',
189
+ S: 'CU',
190
+ C: 'HLN',
191
+ I: 'HLN',
192
+ A: 'HLN'
193
+ };
194
+ this.bmoReg = {
195
+ AV: 'NALP',
196
+ AC: 'LH',
197
+ C: 'C',
198
+ I: 'C',
199
+ A: 'C'
200
+ };
201
+ var s, f, dl, g, dd, l;
202
+ this.el = document.getElementById(id);
203
+ this.el.appendChild(s = e('style'));
204
+ s.innerHTML = '';
205
+ this.el.appendChild(f = e('form'));
206
+ f.className = 'cvssjs';
207
+ this.calc = f;
208
+ for (g in this.bg) {
209
+ f.appendChild(dl = e('dl'));
210
+ dl.setAttribute('class', g);
211
+ var dt = e('dt');
212
+ dt.innerHTML = this.bg[g];
213
+ dl.appendChild(dt);
214
+ for (s in this.bm[g]) {
215
+ dd = e('dd');
216
+ dl.appendChild(dd);
217
+ var inp = e('input');
218
+ inp.setAttribute('name', g);
219
+ inp.setAttribute('value', s);
220
+ inp.setAttribute('id', id + g + s);
221
+ inp.setAttribute('class', g + s);
222
+ //inp.setAttribute('ontouchstart', '');
223
+ inp.setAttribute('type', 'radio');
224
+ this.bme[g + s] = inp;
225
+ var me = this;
226
+ inp.onchange = function () {
227
+ me.setMetric(this);
228
+ };
229
+ dd.appendChild(inp);
230
+ l = e('label');
231
+ dd.appendChild(l);
232
+ l.setAttribute('for', id + g + s);
233
+ l.appendChild(e('i')).setAttribute('class', g + s);
234
+ l.appendChild(document.createTextNode(this.bm[g][s].l + ' '));
235
+ dd.appendChild(e('small')).innerHTML = this.bm[g][s].d;
236
+ }
237
+ }
238
+ //f.appendChild(e('hr'));
239
+ f.appendChild(dl = e('dl'));
240
+ dl.innerHTML = '<dt>Severity&sdot;Score&sdot;Vector</dt>';
241
+ dd = e('dd');
242
+ dl.appendChild(dd);
243
+ l = dd.appendChild(e('label'));
244
+ l.className = 'results';
245
+ l.appendChild(this.severity = e('span'));
246
+ this.severity.className = 'severity';
247
+ l.appendChild(this.score = e('span'));
248
+ this.score.className = 'score';
249
+ l.appendChild(document.createTextNode(' '));
250
+ l.appendChild(this.vector = e('a'));
251
+ this.vector.className = 'vector';
252
+ this.vector.innerHTML = 'CVSS:3.1/AV:_/AC:_/PR:_/UI:_/S:_/C:_/I:_/A:_';
253
+
254
+ if (options.onsubmit) {
255
+ f.appendChild(e('hr'));
256
+ this.submitButton = f.appendChild(e('input'));
257
+ this.submitButton.setAttribute('type', 'submit');
258
+ this.submitButton.onclick = options.onsubmit;
259
+ }
260
+ };
261
 
262
+ CVSS.prototype.severityRatings = [{
263
+ name: "None",
264
+ bottom: 0.0,
265
+ top: 0.0
266
+ }, {
267
+ name: "Low",
268
+ bottom: 0.1,
269
+ top: 3.9
270
+ }, {
271
+ name: "Medium",
272
+ bottom: 4.0,
273
+ top: 6.9
274
+ }, {
275
+ name: "High",
276
+ bottom: 7.0,
277
+ top: 8.9
278
+ }, {
279
+ name: "Critical",
280
+ bottom: 9.0,
281
+ top: 10.0
282
+ }];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
 
284
+ CVSS.prototype.severityRating = function (score) {
285
+ var i;
286
+ var severityRatingLength = this.severityRatings.length;
287
+ for (i = 0; i < severityRatingLength; i++) {
288
+ if (score >= this.severityRatings[i].bottom && score <= this.severityRatings[i].top) {
289
+ return this.severityRatings[i];
290
+ }
291
+ }
292
+ return {
293
+ name: "?",
294
+ bottom: 'Not',
295
+ top: 'defined'
296
+ };
297
+ };
 
 
 
298
 
299
+ CVSS.prototype.valueofradio = function(e) {
300
+ for(var i = 0; i < e.length; i++) {
301
+ if (e[i].checked) {
302
+ return e[i].value;
303
+ }
304
+ }
305
+ return null;
306
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
307
 
308
+ CVSS.prototype.calculate = function () {
309
+ var cvssVersion = "3.1";
310
+ var exploitabilityCoefficient = 8.22;
311
+ var scopeCoefficient = 1.08;
 
 
 
312
 
313
+ // Define associative arrays mapping each metric value to the constant used in the CVSS scoring formula.
314
+ var Weight = {
315
+ AV: {
316
+ N: 0.85,
317
+ A: 0.62,
318
+ L: 0.55,
319
+ P: 0.2
320
+ },
321
+ AC: {
322
+ H: 0.44,
323
+ L: 0.77
324
+ },
325
+ PR: {
326
+ U: {
327
+ N: 0.85,
328
+ L: 0.62,
329
+ H: 0.27
330
+ },
331
+ // These values are used if Scope is Unchanged
332
+ C: {
333
+ N: 0.85,
334
+ L: 0.68,
335
+ H: 0.5
336
+ }
337
+ },
338
+ // These values are used if Scope is Changed
339
+ UI: {
340
+ N: 0.85,
341
+ R: 0.62
342
+ },
343
+ S: {
344
+ U: 6.42,
345
+ C: 7.52
346
+ },
347
+ C: {
348
+ N: 0,
349
+ L: 0.22,
350
+ H: 0.56
351
+ },
352
+ I: {
353
+ N: 0,
354
+ L: 0.22,
355
+ H: 0.56
356
+ },
357
+ A: {
358
+ N: 0,
359
+ L: 0.22,
360
+ H: 0.56
361
+ }
362
+ // C, I and A have the same weights
363
 
364
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
 
366
+ var p;
367
+ var val = {}, metricWeight = {};
368
+ try {
369
+ for (p in this.bg) {
370
+ val[p] = this.valueofradio(this.calc.elements[p]);
371
+ if (typeof val[p] === "undefined" || val[p] === null) {
372
+ return "?";
373
+ }
374
+ metricWeight[p] = Weight[p][val[p]];
375
+ }
376
+ } catch (err) {
377
+ return err; // TODO: need to catch and return sensible error value & do a better job of specifying *which* parm is at fault.
378
+ }
379
+ metricWeight.PR = Weight.PR[val.S][val.PR];
380
+ //
381
+ // CALCULATE THE CVSS BASE SCORE
382
+ //
383
+ var roundUp1 = function Roundup(input) {
384
+ var int_input = Math.round(input * 100000);
385
+ if (int_input % 10000 === 0) {
386
+ return int_input / 100000
387
+ } else {
388
+ return (Math.floor(int_input / 10000) + 1) / 10
389
+ }
390
+ };
391
+ try {
392
+ var baseScore, impactSubScore, impact, exploitability;
393
+ var impactSubScoreMultiplier = (1 - ((1 - metricWeight.C) * (1 - metricWeight.I) * (1 - metricWeight.A)));
394
+ if (val.S === 'U') {
395
+ impactSubScore = metricWeight.S * impactSubScoreMultiplier;
396
+ } else {
397
+ impactSubScore = metricWeight.S * (impactSubScoreMultiplier - 0.029) - 3.25 * Math.pow(impactSubScoreMultiplier - 0.02, 15);
398
+ }
399
+ var exploitabalitySubScore = exploitabilityCoefficient * metricWeight.AV * metricWeight.AC * metricWeight.PR * metricWeight.UI;
400
+ if (impactSubScore <= 0) {
401
+ baseScore = 0;
402
+ } else {
403
+ if (val.S === 'U') {
404
+ baseScore = roundUp1(Math.min((exploitabalitySubScore + impactSubScore), 10));
405
+ } else {
406
+ baseScore = roundUp1(Math.min((exploitabalitySubScore + impactSubScore) * scopeCoefficient, 10));
407
+ }
408
+ }
409
 
410
+ return baseScore.toFixed(1);
411
+ } catch (err) {
412
+ return err;
413
+ }
414
+ };
415
 
416
+ CVSS.prototype.get = function() {
417
+ return {
418
+ score: this.score.innerHTML,
419
+ vector: this.vector.innerHTML
420
+ };
421
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
 
423
+ CVSS.prototype.setMetric = function(a) {
424
+ var vectorString = this.vector.innerHTML;
425
+ if (/AV:.\/AC:.\/PR:.\/UI:.\/S:.\/C:.\/I:.\/A:./.test(vectorString)) {} else {
426
+ vectorString = 'AV:_/AC:_/PR:_/UI:_/S:_/C:_/I:_/A:_';
427
+ }
428
+ //e("E" + a.id).checked = true;
429
+ var newVec = vectorString.replace(new RegExp('\\b' + a.name + ':.'), a.name + ':' + a.value);
430
+ this.set(newVec);
431
+ };
432
 
433
+ CVSS.prototype.set = function(vec) {
434
+ var newVec = 'CVSS:3.1/';
435
+ var sep = '';
436
+ for (var m in this.bm) {
437
+ var match = (new RegExp('\\b(' + m + ':[' + this.bmgReg[m] + '])')).exec(vec);
438
+ if (match !== null) {
439
+ var check = match[0].replace(':', '');
440
+ this.bme[check].checked = true;
441
+ newVec = newVec + sep + match[0];
442
+ } else if ((m in {C:'', I:'', A:''}) && (match = (new RegExp('\\b(' + m + ':C)')).exec(vec)) !== null) {
443
+ // compatibility with v2 only for CIA:C
444
+ this.bme[m + 'H'].checked = true;
445
+ newVec = newVec + sep + m + ':H';
446
+ } else {
447
+ newVec = newVec + sep + m + ':_';
448
+ for (var j in this.bm[m]) {
449
+ this.bme[m + j].checked = false;
450
+ }
451
+ }
452
+ sep = '/';
453
+ }
454
+ this.update(newVec);
455
+ };
456
 
457
+ CVSS.prototype.update = function(newVec) {
458
+ this.vector.innerHTML = newVec;
459
+ var s = this.calculate();
460
+ this.score.innerHTML = s;
461
+ var rating = this.severityRating(s);
462
+ this.severity.className = rating.name + ' severity';
463
+ this.severity.innerHTML = rating.name + '<sub>' + rating.bottom + ' - ' + rating.top + '</sub>';
464
+ this.severity.title = rating.bottom + ' - ' + rating.top;
465
+ if (this.options !== undefined && this.options.onchange !== undefined) {
466
+ this.options.onchange();
467
+ }
468
+ };