-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebunpack.js
79 lines (66 loc) · 2.24 KB
/
webunpack.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
const lib = require('./lib/index.js');
const fs = require('fs');
var DIR_TMPWEBPACK = __dirname+"/tmpwebpack/";
function printCmdUsage() {
console.error("---------\nwebunpack\n---------\n");
console.error("command: node webunpack.js option [file1] [file2]\n\t");
console.error("option:");
console.error(" - getvulns: fetch vulnerabilities from npmjs.com and print the result to console");
console.error(" - createdb: create signatures database (file2) from list of vulnerable modules in file1");
console.error(" - filterdb: filter signatures database (file1) to remove duplicate signatures");
console.error(" - updatedb: update signatures database (file2) from list of vulnerable modules in file1");
console.error(" - unpack: analyze packed file2 against signatures database (file1)\n\n");
}
if(!fs.existsSync(DIR_TMPWEBPACK)) {
printTmpDirDoesntExist();
}
try {
fs.accessSync(DIR_TMPWEBPACK, fs.constants.W_OK | fs.constants.R_OK);
}
catch (e) {
printTmpDirDoesntExist();
}
if(process.argv.length > 2) {
switch(process.argv[2]) {
case "getvulns":
lib.fetchVulnerabilities();
break;
case "createdb":
if(process.argv.length > 4) {
lib.createSignatures(process.argv[3], process.argv[4]);
}
else {
printCmdUsage();
}
break;
case "updatedb":
if(process.argv.length > 4) {
lib.updateSignatures(process.argv[3], process.argv[4]);
}
else {
printCmdUsage();
}
break;
case "filterdb":
if(process.argv.length > 3) {
lib.signaturesdbFilter(process.argv[3]);
}
else {
printCmdUsage();
}
break;
case "unpack":
if(process.argv.length > 4) {
console.dir(lib.unpackFile(process.argv[4], process.argv[3]), {'maxArrayLength': null});
}
else {
printCmdUsage();
}
break;
default:
printCmdUsage();
}
}
else {
printCmdUsage();
}