-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmissing-security-controls.js
84 lines (79 loc) · 2.28 KB
/
missing-security-controls.js
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
var Weight = {
AV: {
N: 0.85,
A: 0.62,
L: 0.55,
P: 0.2
},
AC: {
H: 0.44,
L: 0.77
},
PR: {
U: {
N: 0.85,
L: 0.62,
H: 0.27
},
// These values are used if Scope is Unchanged
C: {
N: 0.85,
L: 0.68,
H: 0.5
}
},
// These values are used if Scope is Changed
UI: {
N: 0.85,
R: 0.62
},
S: {
U: 6.42,
C: 7.52
}
};
function calculate(element) {
var cvssVersion = "3.1";
var exploitabilityCoefficient = 8.22;
var scopeCoefficient = 1.08;
var p;
var val = {}, metricWeight = {};
try {
var inputs = $(element).parent().parent().parent().find('input[type="radio"]');
inputs.each(function () {
if (this.checked) {
val[$(this).attr("data-field").toUpperCase()] = $(this).attr("data-value").toUpperCase();
if (typeof val[$(this).attr("data-field").toUpperCase()] === "undefined" || val[$(this).attr("data-field").toUpperCase()] === null) {
return "?";
}
metricWeight[$(this).attr("data-field").toUpperCase()] = Weight[$(this).attr("data-field").toUpperCase()][val[$(this).attr("data-field").toUpperCase()]];
}
});
} catch (err) {
return err; // TODO: need to catch and return sensible error value & do a better job of specifying *which* parm is at fault.
}
metricWeight.PR = Weight.PR[val.S][val.PR];
//
// CALCULATE THE CVSS BASE SCORE
//
var roundUp1 = function Roundup(input) {
var int_input = Math.round(input * 100000);
if (int_input % 10000 === 0) {
return int_input / 100000
} else {
return (Math.floor(int_input / 10000) + 1) / 10
}
};
try {
var baseScore, exploitability;
var exploitabalitySubScore = exploitabilityCoefficient * metricWeight.AV * metricWeight.AC * metricWeight.PR * metricWeight.UI;
if (val.S === 'U') {
baseScore = roundUp1(Math.min(exploitabalitySubScore, 10));
} else {
baseScore = roundUp1(Math.min(exploitabalitySubScore * scopeCoefficient, 10));
}
return baseScore.toFixed(1);
} catch (err) {
return err;
}
};