script that probably doesn't work anymore
0
wallet_guided_bruteforce.js
1/**
2 * ETH Keystore Guided Bruteforce
3 *
4 * NO IDEA IF THIS SCRIPT STILL WORKS.
5 * I just keep it now because it's a funny story to me.
6 *
7 * @description
8 * A small script I used to bruteforce my ethereum password for a really old
9 * wallet from list of possible passphrase combinations. It did the job at
10 * that time (phew)! Originally built in node.js, I rejiggered to be a deno
11 * app so I wouldn't need to push package.json, and to make importing json
12 * files look cleaner.
13 *
14 * Required Files:
15 * `keystore.json` is the wallet keystore
16 * `template.json`` is nested array of word/phrase combinations
17 *
18 * @example deno run deno run wallet_guided_bruteforce.js
19 */
20import { bold, green, red, yellow } from "jsr:@std/fmt/colors";
21import keythereum from "npm:keythereum";
22
23import keystore from "./keystore.json" assert { type: "json" };
24import passwordTemplate from "./template.json" assert { type: "json" };
25
26const response = getPasswordCombinations(passwordTemplate)
27 .find((password) => Boolean(checkPass(password)));
28
29if (!response) console.log(red(bold("Failed to find password")));
30
31function checkPass(password) {
32 try {
33 const privateKey = keythereum.recover(password, keystore).toString("hex");
34 console.log(`0x${keystore.address}: 0x${privateKey}`);
35 console.log(green(bold("FOUND PASSWORD", password)));
36 return password;
37 } catch (e) {
38 console.log("tried", password);
39 // Expected "bad-pass" error is mismatch. Anything else is sus.
40 if (!(e.message || "").includes("authentication code mismatch")) {
41 console.log(
42 yellow(bold("Unexpected Error, please try previous password")),
43 );
44 console.log(e);
45 }
46 }
47}
48
49function getPasswordCombinations(arr) {
50 if (arr.length == 1) return arr[0];
51
52 const result = [];
53 const allCasesOfRest = getPasswordCombinations(arr.slice(1)); // recur with the rest of array
54
55 for (let i = 0; i < allCasesOfRest.length; i++) {
56 for (let j = 0; j < arr[0].length; j++) {
57 result.push(arr[0][j] + allCasesOfRest[i]);
58 }
59 }
60 return result;
61}
62
63const exampleKeystoreJsonFile = {
64 "version": 3,
65 "id": "36ff6493-21a5-41f5-998f-ed8e53627ed2",
66 "address": "a9f7d6911a3169289229b761099403db87581640",
67 "crypto": {
68 "ciphertext":
69 "b09e6dfe731c092e4951b861b7c576dcd65834fdbbf3fd5c39e88a5510c2a0b0",
70 "cipherparams": {
71 "iv": "3e125a0889bbac987901b7007f2f571a",
72 },
73 "cipher": "aes-128-ctr",
74 "kdf": "scrypt",
75 "kdfparams": {
76 "dklen": 32,
77 "salt":
78 "58298ca71cf02f698780a1ba53a3efc1f4162c81296045214cfaecc75ce849e0",
79 "n": 8192,
80 "r": 8,
81 "p": 1,
82 },
83 "mac": "41f440e55e9da8e5075cb401cf9a66cff34d26eb3ca772a70ed9370c99f697a1",
84 },
85};
86
87const exampleTemplateFile = [
88 ["one", "two", "three"],
89 ["two", "two", "three"],
90 ["one", "two", "three"],
91 ["one", "two", "three"],
92 ["one", "two", "three"],
93];