-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.cfm
More file actions
100 lines (84 loc) · 2.68 KB
/
Copy pathrun.cfm
File metadata and controls
100 lines (84 loc) · 2.68 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
<cfsetting requesttimeout="9000">
<cfscript>
files = directoryList(expandPath("./cve-db/database/java/"), true, "path", "*.yaml");
i = 0;
data = {};
for (f in files) {
processYAMLFile(f);
writeOutput(f & "<br>");
cfflush();
}
fileWrite(expandPath("./database/vic-latest.json"), serializeJSON(data), "utf-8");
if(url.keyExists("debug")) {
writeDump(data);
}
writeOutput("DONE");
function processYAMLFile(filePath) {
local.snakeYaml = createObject("java", "org.yaml.snakeyaml.Yaml");
local.yaml = local.snakeYaml.load(fileRead(arguments.filePath));
local.summary = "";
local.package = "";
local.v = "";
if (yaml.keyExists("title")) {
summary = yaml["title"];
}
if (yaml.keyExists("description")) {
summary = summary & ". " & yaml["description"];
}
for (package in yaml["affected"]) {
local.packageID = package["groupId"] & ":" & package["artifactId"];
data[packageID] = {"vulnerabilities":[], "extractors":{}};
data[packageID].extractors["filename"] = [ "#package["artifactId"]#-(§§version§§).jar"];
if (!package.keyExists("fixedin")) {
if (url.keyExists("debug")) {
writeOutput("<h3>Missing fixedin in: #f#</h3>");
}
continue;
}
for (v in package["fixedin"]) {
v = listFirst(v);
if (!reFind("[a-zA-Z]", v)) {
v = replace(v, ">=", "");
vuln = { "below":v, "identifiers": {"CVE":["CVE-#yaml["cve"]#"], "summary":summary }, "info":[]};
if (yaml.keyExists("references")) {
for (ref in yaml["references"]) {
vuln.info.append(ref);
}
}
data[packageID].vulnerabilities.append(vuln);
}
}
if (arrayLen(data[packageID].vulnerabilities) == 0) {
continue;
}
if (yaml.keyExists("package_urls")) {
data[packageID].extractors["hashes"] = {};
arrayEach(yaml["package_urls"], function(p) {
local.fileName = listLast(p, "/");
if (arrayLen(yaml["affected"]) == 1 || findNoCase(package["artifactId"], fileName) ) {
data[packageID].extractors["hashes"][urlToSha1(p)] = reReplace(fileName, "#package["artifactId"]#-(.+)\.jar", "\1");
}
}, true, 20);
}
}
i++;
if (url.keyExists("debug")) {
writeDump(yaml);
if (i>3) {
break;
}
}
}
function urlToSha1(address) {
var tempPath = getTempDirectory() & createUUID() & ".jar";
cfhttp(url="#arguments.address#", method="get", file="#tempPath#", getasbinary="true");
if (!fileExists(tempPath)) {
return repeatString("0", 40);
}
return fileSha1(tempPath);
}
function fileSha1(path) {
var fIn = createObject("java", "java.io.FileInputStream").init(path);
return createObject("java", "org.apache.commons.codec.digest.DigestUtils").sha1Hex(fIn);
}
</cfscript>