This repository was archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathparser.js
More file actions
190 lines (179 loc) · 5.46 KB
/
parser.js
File metadata and controls
190 lines (179 loc) · 5.46 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
const policyViolationFindingRules = [
{
policyViolationPrefix: /^Add these key exchange algorithms/,
findingTemplate: {
description: "Good / encouraged SSH key algorithms are missing",
name: "Missing SSH Key Algorithms"
}
},
{
policyViolationPrefix: /^Add these MAC algorithms/,
findingTemplate: {
description: "Good / encouraged SSH MAC algorithms are missing",
name: "Missing SSH MAC Algorithms"
}
},
{
policyViolationPrefix: /^Add these encryption ciphers/,
findingTemplate: {
description: "Good / encouraged SSH encryption ciphers are missing",
name: "Missing SSH encryption Ciphers"
}
},
{
policyViolationPrefix: /^Add these compression algorithms/,
findingTemplate: {
description: "Good / encouraged SSH compression algorithms are missing",
name: "Missing SSH compression algorithms"
}
},
{
policyViolationPrefix: /^Add these authentication methods/,
findingTemplate: {
description: "Good / encouraged SSH authentication methods are missing",
name: "Missing SSH authentication methods"
}
},
{
policyViolationPrefix: /^Remove these key exchange algorithms/,
findingTemplate: {
description: "Deprecated / discouraged SSH key algorithms are used",
name: "Insecure SSH Key Algorithms"
}
},
{
policyViolationPrefix: /^Remove these MAC algorithms/,
findingTemplate: {
description: "Deprecated / discouraged SSH MAC algorithms are used",
name: "Insecure SSH MAC Algorithms"
}
},
{
policyViolationPrefix: /^Remove these encryption ciphers/,
findingTemplate: {
description: "Deprecated / discouraged SSH encryption ciphers are used",
name: "Insecure SSH encryption Ciphers"
}
},
{
policyViolationPrefix: /^Remove these compression algorithms/,
findingTemplate: {
description:
"Deprecated / discouraged SSH compression algorithms are used",
name: "Insecure SSH compression algorithms"
}
},
{
policyViolationPrefix: /^Remove these authentication methods/,
findingTemplate: {
description: "Discouraged SSH authentication methods are used",
name: "Discouraged SSH authentication methods"
}
},
{
policyViolationPrefix: /^Update your ssh version to/,
findingTemplate: {
description: "Outdated SSH protocol version used",
name: "Outdated SSH Protocol Version"
}
}
];
/**
* Creating the actual secureCodeBox Finding from the template from the policyViolationFindingRule and the SSH_Scan recomendation string
*/
function createPolicyViolationFinding({
name,
description,
recommendation,
host: { hostname, ipAddress }
}) {
const payload = recommendation.split(": ")[1].split(", ");
return {
name,
description,
category: "SSH Policy Violation",
osi_layer: "NETWORK",
severity: "MEDIUM",
reference: {},
hint: recommendation,
location: hostname || ipAddress,
attributes: {
hostname: hostname,
ip_address: ipAddress,
payload: payload
}
};
}
/**
* Transforms a recommendation string from the Mozilla SSH_Scan Tools into a SSH Policy Violation Findings
*
* @param {string} recommendation
*/
function transformRecommendationToFinding(
recommendation,
{ hostname, ipAddress }
) {
for (const rule of policyViolationFindingRules) {
if (rule.policyViolationPrefix.test(recommendation)) {
return createPolicyViolationFinding({
name: rule.findingTemplate.name,
description: rule.findingTemplate.description,
recommendation,
host: { hostname, ipAddress }
});
}
}
}
/**
* Convert the SSH_Scan file / json into secureCodeBox Findings
*/
async function parse(fileContent) {
const hosts = fileContent;
return hosts
.flatMap(host => {
if (host.error) {
return undefined;
}
const hostname = host.hostname || null;
const ipAddress = host.ip;
const recommendations = host.compliance.recommendations || [];
const policyViolationFindings = recommendations.map(recommendation =>
transformRecommendationToFinding(recommendation, {
hostname,
ipAddress
})
);
const location = hostname || ipAddress;
const compliance = host.compliance;
const serviceFinding = {
name: "SSH Service",
description: "SSH Service Information",
category: "SSH Service",
osi_layer: "APPLICATION",
severity: "INFORMATIONAL",
reference: {},
hint: "",
location: location,
attributes: {
hostname: host.hostname || null,
ip_address: host.ip,
server_banner: host.server_banner || null,
ssh_version: host.ssh_version || null,
os_cpe: host.os_cpe,
ssh_lib_cpe: host.ssh_lib_cpe,
compliance_policy: compliance && compliance.policy,
compliant: compliance && compliance.compliant,
grade: compliance && compliance.grade,
references: compliance && compliance.references,
auth_methods: host.auth_methods,
key_algorithms: host.key_algorithms,
encryption_algorithms: host.encryption_algorithms_server_to_client,
mac_algorithms: host.mac_algorithms_server_to_client,
compression_algorithms: host.compression_algorithms_server_to_client
}
};
return [serviceFinding, ...policyViolationFindings];
})
.filter(Boolean);
}
module.exports.parse = parse;