forked from Ahaz1701/EvilWorker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt_log_file.js
More file actions
51 lines (40 loc) · 1.64 KB
/
Copy pathdecrypt_log_file.js
File metadata and controls
51 lines (40 loc) · 1.64 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
const fs = require("fs");
const crypto = require("crypto");
//!\ It is strongly recommended to modify the encryption key and store it more securely for real engagements. /!\\
const ENCRYPTION_KEY = "HyP3r-M3g4_S3cURe-EnC4YpT10n_k3Y";
const clArguments = process.argv;
if (clArguments.length !== 3) {
console.error(`/!\\ Usage: ${clArguments[0]} ${clArguments[1]} $ENCRYPTED_LOG_FILE_PATH /!\\`);
process.exit(1);
}
const decryptedLogFile = decryptLogFile(clArguments[2]);
console.log(decryptedLogFile);
function decryptData(iv, encryptedData) {
try {
const decipher = crypto.createDecipheriv("aes-256-ctr", ENCRYPTION_KEY, Buffer.from(iv, "hex"));
let decryptedData = decipher.update(encryptedData, "hex", "utf-8");
decryptedData += decipher.final("utf-8");
return decryptedData;
}
catch (error) {
throw new Error(`Log file decryption failed: ${error.message}`);
}
}
function decryptLogFile(logFilePath) {
try {
if (!fs.existsSync(logFilePath)) {
throw new Error(`The ${logFilePath} file does not exist`);
}
const encryptedLogs = fs.readFileSync(logFilePath, "utf8").split("\n");
let decryptedData = "";
for (const encryptedLog of encryptedLogs) {
if (!encryptedLog.trim()) continue;
const encryptedEntry = JSON.parse(encryptedLog);
const [[iv, encryptedData]] = Object.entries(encryptedEntry);
decryptedData += decryptData(iv, encryptedData);
}
return decryptedData;
} catch (error) {
console.error(error);
}
}