-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathparser.js
More file actions
102 lines (94 loc) · 2.78 KB
/
parser.js
File metadata and controls
102 lines (94 loc) · 2.78 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
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
export async function parse(fileContent) {
if (!fileContent) {
return [];
}
if (fileContent === "[\n") {
throw new Error(
"Parser received an invalid report file. This can happen when whatweb is passed invalid arguments. Check the scan configuration.",
);
}
const report = JSON.parse(fileContent);
if (!report || !Array.isArray(report)) {
return [];
}
const targets = await parseResultFile(report);
return transformToFindings(targets);
}
function transformToFindings(targets) {
const targetFindings = targets.map((target) => {
let finding = {
name: target.uri,
category: "WEB APPLICATION",
description: target.title,
location: target.uri,
osi_layer: "NETWORK",
severity: "INFORMATIONAL",
attributes: {
requestConfig: target.requestConfig,
ip_addresses: [target.ipAddress],
country: target.country,
HTML5: target.html5,
},
};
target.additional.forEach((additional) => {
if (!finding.attributes[additional[0]]) {
//Check if key already exists
finding.attributes[additional[0]] =
("string" in additional[1] ? additional[1].string[0] : "") +
("module" in additional[1] ? "/" + additional[1].module[0] : "");
}
});
if (!finding.attributes.HTML5)
//Do not show in findings if undefined
delete finding.attributes.HTML5;
return finding;
});
return [...targetFindings];
}
/**
* Parses a given Whatweb JSON file and extracts all targets
* @param {*} fileContent
*/
function parseResultFile(fileContent) {
let targetList = [];
for (const rawTarget of fileContent) {
if (Object.keys(rawTarget).length > 0) {
//Check for empty target
let newTarget = {
uri: rawTarget.target,
httpStatus: rawTarget.http_status,
requestConfig: rawTarget.request_config.headers["User-Agent"],
ipAddress: null,
title: null,
html5: null,
country: null,
additional: [],
};
if (rawTarget.plugins) {
for (const [key, value] of Object.entries(rawTarget.plugins)) {
switch (key) {
case "IP":
newTarget.ipAddress = value.string[0];
break;
case "Title":
newTarget.title = value.string[0];
break;
case "HTML5":
newTarget.html5 = true;
break;
case "Country":
newTarget.country = value.string[0] + "/" + value.module[0];
break;
default:
newTarget.additional.push([key, value]);
}
}
}
targetList.push(newTarget);
}
}
return targetList;
}