tester password online meme force cracker crack brute attack c algorithm loops recursion brute-force

online - Brute Force Password Cracking Algorithm



password tester time to crack (3)

Estoy tratando de escribir un cracker de contraseñas de fuerza bruta en C que prueba todas las cadenas alfanuméricas posibles de longitud 1, luego todas las cadenas posibles de longitud 2, etc. hasta un tamaño de cadena dado. Tengo una solución funcional pero voluminosa que es:

void forceCrack(char* hash, int passLength, int maxPassLength) { int i, j, k, l, m, n, o, p, q, r; char string1[maxPassLength + 1]; char alphanum[63] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789"; for (i = 0; i <= sizeof(string1); i++) { string1[i] = ''/0''; } if (passLength < maxPassLength) // 1 Length for (i = 0; i < strlen(alphanum); i++) { // For every alphanumerical value string1[0] = alphanum[i]; checkPass(hash, string1); // Checks the string } passLength++; printf("Finished passwords of length %d/n", passLength); if (passLength < maxPassLength) // 2 Length for (i = 0; i < strlen(alphanum); i++) { string1[0] = alphanum[i]; for (j = 0; j < strlen(alphanum); j++) { string1[1] = alphanum[j]; checkPass(hash, string1); } } passLength++; printf("Finished passwords of length %d/n", passLength); if (passLength < maxPassLength) // 3 Length for (i = 0; i < strlen(alphanum); i++) { string1[0] = alphanum[i]; for (j = 0; j < strlen(alphanum); j++) { string1[1] = alphanum[j]; for (k = 0; k < strlen(alphanum); k++) { string1[2] = alphanum[k]; checkPass(hash, string1); } } } passLength++; printf("Finished passwords of length %d/n", passLength); ...

Lamentablemente, este método requiere agregar un conjunto de bucles para cada tamaño incrementado de cadena que se vuelve extremadamente voluminoso, y solo funciona para los tamaños de cadena hasta una longitud precodificada.

Estoy buscando una solución que use bucles o recursión y funcionará para cualquier cadena de longitud. Cualquier método que he pensado hasta ahora termina con los bucles que comprueban, para una cadena de longitud máxima máxima comprueba, 1, 01, 001, 0001, 0002, ... en vez de cada longitud 1 cadena primero, luego pasa a cada longitud 2 cuerdas. ¿Puede alguien ayudarme con una solución?


Este pasa por todos los dígitos de un solo dígito, luego todos de doble dígito, luego triples, y así sucesivamente.

#include <stdio.h> #include <string.h> #include <stdlib.h> static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; static const int alphabet_size = sizeof(alphabet) - 1; void brute_impl(char * str, int index, int max_depth) { int i; for (i = 0; i < alphabet_size; ++i) { str[index] = alphabet[i]; if (index == max_depth - 1) { printf("%s/n", str); // put check() here instead } else { brute_impl(str, index + 1, max_depth); } } } void brute_sequential(int max_len) { char * buf = malloc(max_len + 1); int i; for (i = 1; i <= max_len; ++i) { memset(buf, 0, max_len + 1); brute_impl(buf, 0, i); } free(buf); } int main(void) { brute_sequential(3); return 0; }


Supongamos que tiene una función char * checkPasswordsOfLength(int) que comprueba todas las contraseñas de una longitud específica y devuelve la contraseña si se encuentra o nulo en caso contrario.
Entonces solo:

int i = 0; char * password = NULL; while (!password) { password = checkPasswordsOfLength(++i); }

Espero que esto es lo que querías decir, aunque no estoy seguro de que te haya entendido :)


¿Algo como esto?

const uint CHAR_OFFSET = 32; const uint CHARS = 95; bool crack(char* str, uint pos, uint size){ for(uint i = 0; i < CHARS; ++i){ str[pos] = CHAR_OFFSET + i; if(pos + 1 < size){ if(crack(str, pos + 1, size)) return true; } else if(check(str, size)) // check() tests substring of first (size) letters return true; } return false; } void test(){ uint size = 10; char str[size]; for(uint i = 1; i < size; ++i){ memset(str, CHAR_OFFSET, i * sizeof(char)); if(crack(str, 0, i)) break; } }