diff --git a/crack.c b/crack.c index ce93287a8fbaff86a848e7fa021f33f0798d7037..c8b1e2b3c449c181f64aaac4b04857394f9ff2fb 100644 --- a/crack.c +++ b/crack.c @@ -7,440 +7,535 @@ #include "sha256.h" #include "sha256.c" #include <stdbool.h> -int exist[30]; + int exist[30]; BYTE old[6]; -int count=0; +int count = 0; +void makeguess(char * word_list, int hashes[][32],int a); -void printRandomString(int hashes[30][32]) -{ bool cracked = true; -SHA256_CTX ctx; - +void printRandomString(int hashes[30][32]) { + bool cracked = true; + SHA256_CTX ctx; - BYTE buffer[SHA256_BLOCK_SIZE]; - - for (int i = 0; i < 100000000000000000; ++i) { - if (count=30) - { - break; - } + BYTE buffer[SHA256_BLOCK_SIZE]; + + for (int i = 0; i < 100000000000000000; ++i) { + if (count == 30) { + break; + } BYTE res[6]; - for (int j = 0; j < 6; j++) - res[j] = (rand()% 26)+97;; - res[6]='\0'; - sha256_init(&ctx); - sha256_update(&ctx, res, sizeof(res)); - sha256_final(&ctx, buffer); - - for(int k=10; k<30; k++){ - - cracked = true; - for(int a=0; a<32; a++){ - if( buffer[a] != hashes[k][a] ){ - - cracked=false; - break; - } - } - if( cracked==true && exist[k+1]!=1 ){ - ctx.data[6] = '\0'; - exist[k+1]=1; - ++count; - printf("%s %d\n", ctx.data, k+1); - } - } + for (int j = 0; j < 6; j++) + res[j] = (rand() % 26) + 97;; + res[6] = '\0'; + sha256_init( & ctx); + sha256_update( & ctx, res, sizeof(res)); + sha256_final( & ctx, buffer); + + for (int k = 10; k < 30; k++) { + cracked = true; + for (int a = 0; a < 32; a++) { + if (buffer[a] != hashes[k][a]) { - } + cracked = false; + break; + } + } + if (cracked == true && exist[k + 1] != 1) { + ctx.data[6] = '\0'; + exist[k + 1] = 1; + ++count; + printf("%s %d\n", ctx.data, k + 1); + } + } + + } } -void variations(char *word_list_file, int hashes[30][32]) -{ +void variations(char * word_list_file, int hashes[30][32]) { SHA256_CTX ctx; - BYTE buffer[SHA256_BLOCK_SIZE]; - BYTE password[6]; - bool cracked = true; - - FILE *word_list; - word_list=fopen(word_list_file, "rb"); + BYTE buffer[SHA256_BLOCK_SIZE]; + BYTE password[6]; + bool cracked = true; - while ( fgets(password, 7, word_list) != '\0'){ - if (count==30) - { - break; - } + FILE * word_list; + word_list = fopen(word_list_file, "rb"); - for (int c = 0; c < 6; ++c) - { BYTE password1[6]; - for (int i = 0; i < 6; ++i) - { - if (i==c) - { - - if (password[c]>=65 && password[c]<90) - { - password1[c]=password[c]+32; - } - else if (password[c]>=97 && password[c]<123) - { - password1[c]=password[c]-32; - } - else{ - password1[c]=password[c]; - } + while (fgets(password, 7, word_list) != '\0') { + if (count == 30) { + break; + } + + for (int c = 0; c < 6; ++c) { + BYTE password1[6]; + for (int i = 0; i < 6; ++i) { + if (i == c) { + + if (password[c] >= 65 && password[c] < 90) { + password1[c] = password[c] + 32; + } else if (password[c] >= 97 && password[c] < 123) { + password1[c] = password[c] - 32; + } else { + password1[c] = password[c]; } - else{ - password1[i]=password[i]; - } + } else { + password1[i] = password[i]; + } + } + password1[6] = '\0'; + + sha256_init( & ctx); + sha256_update( & ctx, password1, sizeof(password1)); + sha256_final( & ctx, buffer); + + for (int j = 10; j < 30; j++) { + + cracked = true; + for (int i = 0; i < 32; i++) { + if (buffer[i] != hashes[j][i]) { + + cracked = false; + break; } - password1[6]='\0'; - - - sha256_init(&ctx); - sha256_update(&ctx, password1, sizeof(password1)); - sha256_final(&ctx, buffer); - - for(int j=10; j<30; j++){ - - cracked = true; - for(int i=0; i<32; i++){ - if( buffer[i] != hashes[j][i] ){ - - cracked=false; - break; - } - } - if( cracked==true && exist[j+1]!=1){ - ctx.data[6] = '\0'; - exist[j+1]=1; - count++; - printf("%s %d\n", ctx.data, j+1); - } } - + if (cracked == true && exist[j + 1] != 1) { + ctx.data[6] = '\0'; + exist[j + 1] = 1; + count++; + printf("%s %d\n", ctx.data, j + 1); + } } - - } + } - + } + fclose(word_list); } -void printRandomString1(int k) -{ - - for (int i = 0; i < k-1; ++i) { +void printRandomString1(int k) { + + for (int i = 0; i < k - 1; ++i) { BYTE res[6]; - for (int j = 0; j < 6; j++) - res[j] = (rand()% 59)+65;; - res[6]='\0'; - printf("%s\n",res ); -} + for (int j = 0; j < 6; j++) + res[j] = (rand() % 59) + 65;; + res[6] = '\0'; + printf("%s\n", res); + } } - -void bruteforce(int hashes[30][32]){ - SHA256_CTX ctx; - BYTE buffer[SHA256_BLOCK_SIZE]; - BYTE password[4]; - bool cracked = true; - - - for(int c1=32; c1<127; c1++){ - password[0] = c1; - if( count == 10 ) break; - for(int c2=32; c2<127; c2++){ - password[1] = c2; - if( count == 10 ) break; - for(int c3=32; c3<127; c3++){ - password[2] = c3; - if( count == 10 ) break; - for(int c4=32; c4<127; c4++){ - if( count == 10 ) break; - password[3] = c4; - password[4] = '\0'; - - - sha256_init(&ctx); - sha256_update(&ctx, password, sizeof(password)); - sha256_final(&ctx, buffer); - - for(int i=1; i<11; i++){ - cracked = true; - for(int j=0; j<32; j++){ - if( buffer[j] != hashes[i][j] ){ - cracked = false; - break; - } - } - if(cracked==true){ - count++; - ctx.data[4] = '\0'; - printf("%s %d\n", ctx.data, i); - } - } - } - } +void bruteforce(int hashes[30][32]) { + SHA256_CTX ctx; + BYTE buffer[SHA256_BLOCK_SIZE]; + BYTE password[4]; + bool cracked = true; + + for (int c1 = 32; c1 < 127; c1++) { + password[0] = c1; + if (count == 10) break; + for (int c2 = 32; c2 < 127; c2++) { + password[1] = c2; + if (count == 10) break; + for (int c3 = 32; c3 < 127; c3++) { + password[2] = c3; + if (count == 10) break; + for (int c4 = 32; c4 < 127; c4++) { + if (count == 10) break; + password[3] = c4; + password[4] = '\0'; + + sha256_init( & ctx); + sha256_update( & ctx, password, sizeof(password)); + sha256_final( & ctx, buffer); + + for (int i = 1; i < 11; i++) { + cracked = true; + for (int j = 0; j < 32; j++) { + if (buffer[j] != hashes[i][j]) { + cracked = false; + break; + } + } + if (cracked == true) { + count++; + ctx.data[4] = '\0'; + printf("%s %d\n", ctx.data, i); + } + } } + } } + } } // C program to print all permutations with duplicates allowed /* Function to swap values at two pointers */ -void swap(char *x, char *y) -{ - char temp; - temp = *x; - *x = *y; - *y = temp; -} +void swap(char * x, char * y) { + char temp; + temp = * x; + * x = * y; + * y = temp; +} /* Function to print permutations of string This function takes three parameters: 1. String 2. Starting index of the string 3. Ending index of the string. */ -void permute(char *a, int l, int r,int hashes[30][32],int status) -{ SHA256_CTX ctx; - BYTE buffer[SHA256_BLOCK_SIZE]; - bool cracked = true; - int count1 = 0; - char word[30]; - -int i; -if (l == r) - { if(status!=2){ - BYTE n[6]; - for (int k = 0; k < 6; ++k) - { - n[k]=a[k]; +void permute(char * a, int l, int r, int hashes[30][32], int status) { + SHA256_CTX ctx; + BYTE buffer[SHA256_BLOCK_SIZE]; + bool cracked = true; + int count1 = 0; + char word[30]; + + int i; + if (l == r) { + if (status != 2) { + BYTE n[6]; + for (int k = 0; k < 6; ++k) { + n[k] = a[k]; - } - n[6]='\0'; - sha256_init(&ctx); - sha256_update(&ctx, n, sizeof(n)); - sha256_final(&ctx, buffer); + } + n[6] = '\0'; + sha256_init( & ctx); + sha256_update( & ctx, n, sizeof(n)); + sha256_final( & ctx, buffer); - for(int j=10; j<30; j++){ - - cracked = true; - for(int i=0; i<32; i++){ - if( buffer[i] != hashes[j][i] ){ - - cracked=false; - break; - } - } - if( cracked==true && exist[j+1]!=1){ - ctx.data[6] = '\0'; - exist[j+1]=1; - printf("%s %d\n", ctx.data, j+1); - } + for (int j = 10; j < 30; j++) { + + cracked = true; + for (int i = 0; i < 32; i++) { + if (buffer[i] != hashes[j][i]) { + + cracked = false; + break; + } + } + if (cracked == true && exist[j + 1] != 1) { + ctx.data[6] = '\0'; + exist[j + 1] = 1; + printf("%s %d\n", ctx.data, j + 1); } - }else{BYTE n[6]; - int count1=0; - for (int k = 0; k < 6; ++k) - { - n[k]=a[k]; - if (old[k]==n[k]) - { - ++count1; } + } else { + BYTE n[6]; + int count1 = 0; + for (int k = 0; k < 6; ++k) { + n[k] = a[k]; + if (old[k] == n[k]) { + ++count1; + } - } + } - n[6]='\0'; - if(count1<6) - { - printf("%s\n",n ); - for (int k = 0; k < 7; ++k) - { - old[k]=n[k]; + n[6] = '\0'; + if (count1 < 6) { + printf("%s\n", n); + for (int k = 0; k < 7; ++k) { + old[k] = n[k]; + + } + } } + } else { + for (i = l; i <= r; i++) { + swap((a + l), (a + i)); + permute(a, l + 1, r, hashes, status); + swap((a + l), (a + i)); //backtrack } - - }} -else -{ - for (i = l; i <= r; i++) - { - swap((a+l), (a+i)); - permute(a, l+1, r,hashes,status); - swap((a+l), (a+i)); //backtrack - } -} -} + } +} /* Driver program to test above functions */ -void permutations1(char *word_list_file, int hashes[30][32],int status) -{ - SHA256_CTX ctx; - BYTE buffer[SHA256_BLOCK_SIZE]; - BYTE password[12]; - bool cracked = true; - - char word[30]; +void permutations1(char * word_list_file, int hashes[30][32], int status) { + SHA256_CTX ctx; + BYTE buffer[SHA256_BLOCK_SIZE]; + BYTE password[12]; + bool cracked = true; + char word[30]; - FILE *word_list; - word_list=fopen(word_list_file, "rb"); + FILE * word_list; + word_list = fopen(word_list_file, "rb"); - + while (fgets(password, 7, word_list) != '\0') { - while ( fgets(password, 7, word_list) != '\0'){ - - for (int i = 6; i < 12; ++i) - { - if (password[i-6]>=65 && password[i-6]<90) - { - password[i]=password[i-6]+32; - } - else - { - password[i]=password[i-6]-32; - } - - } + for (int i = 6; i < 12; ++i) { + if (password[i - 6] >= 65 && password[i - 6] < 90) { + password[i] = password[i - 6] + 32; + } else { + password[i] = password[i - 6] - 32; + } - password[12]='\0'; - - permute(password,0,11,hashes,status); + } -} + password[12] = '\0'; + + permute(password, 0, 11, hashes, status); + + } + fclose(word_list); } -void crack6(char *word_list_file, int hashes[30][32]) -{ - SHA256_CTX ctx; - BYTE buffer[SHA256_BLOCK_SIZE]; - BYTE password[6]; - bool cracked = true; - - char word[30]; +void crack6(char * word_list_file, int hashes[30][32]) { + SHA256_CTX ctx; + BYTE buffer[SHA256_BLOCK_SIZE]; + BYTE password[6]; + bool cracked = true; + char word[30]; - FILE *word_list; - word_list=fopen(word_list_file, "rb"); + FILE * word_list; + word_list = fopen(word_list_file, "rb"); - while ( fgets(password, 7, word_list) != '\0'){ - - password[6]='\0'; - sha256_init(&ctx); - sha256_update(&ctx, password, sizeof(password)); - sha256_final(&ctx, buffer); - for(int j=10; j<30; j++){ - - cracked = true; - for(int i=0; i<32; i++){ - if( buffer[i] != hashes[j][i] ){ - - cracked=false; - break; - } - } - if( cracked==true && exist[j+1]!=1 ){ - ctx.data[6] = '\0'; - exist[j+1]=1; - ++count; - printf("%s %d\n", ctx.data, j+1); - } - } - } + while (fgets(password, 7, word_list) != '\0') { + + password[6] = '\0'; + sha256_init( & ctx); + sha256_update( & ctx, password, sizeof(password)); + sha256_final( & ctx, buffer); + for (int j = 10; j < 30; j++) { + + cracked = true; + for (int i = 0; i < 32; i++) { + if (buffer[i] != hashes[j][i]) { + + cracked = false; + break; + } + } + if (cracked == true && exist[j + 1] != 1) { + ctx.data[6] = '\0'; + exist[j + 1] = 1; + ++count; + printf("%s %d\n", ctx.data, j + 1); + } + } + } + fclose(word_list); } +int main(int argc, char * argv[]) { + int status = argc; + int hashes[30][32]; - int main(int argc, char *argv[]){ - int status=argc; - int hashes[30][32]; - - if(argc==1) - { + if (argc == 1) { unsigned char buff[320]; int hashes[30][32]; - FILE *file_4, *file_6; - int i,a=0,b=0; - file_4=fopen("pwd4sha256", "rb"); - - fread(buff,sizeof(buff),1,file_4); - - - for(i = 0; i<320; i++){ - if(i%32==0){ - a++; - b=0; - } - hashes[a][b]=buff[i]; - b++; - } - - bruteforce(hashes); - unsigned char buff6[640]; - file_6=fopen("pwd6sha256","rb"); - fread(buff6, sizeof(buff6),1, file_6); - for(i=0,a=9; i<640;++i) - { - if(i%32 == 0){ - a++; - b=0; - printf("\n"); - } - hashes[a][b]=buff6[i]; - - - b++; - } - crack6("100k_passwords.txt",hashes); - variations("common_passwords1.txt",hashes); - printRandomString(hashes); - - - - - + FILE * file_4, * file_6; + int i, a = 0, b = 0; + file_4 = fopen("pwd4sha256", "rb"); + + fread(buff, sizeof(buff), 1, file_4); + + for (i = 0; i < 320; i++) { + if (i % 32 == 0) { + a++; + b = 0; + } + hashes[a][b] = buff[i]; + b++; + } + + bruteforce(hashes); + unsigned char buff6[640]; + file_6 = fopen("pwd6sha256", "rb"); + fread(buff6, sizeof(buff6), 1, file_6); + for (i = 0, a = 9; i < 640; ++i) { + if (i % 32 == 0) { + a++; + b = 0; + + } + hashes[a][b] = buff6[i]; + + b++; + } + crack6("100k_passwords.txt", hashes); + variations("common_passwords1.txt", hashes); + printRandomString(hashes); fclose(file_4); fclose(file_6); -} -if (argc==2) -{ - int k= atoi(argv[1]); - printf("%d\n",k ); - printRandomString1(k); + } + if (argc == 2) { + int k = atoi(argv[1]); + printf("%d\n", k); + printRandomString1(k); + + } + if (argc == 3) { + FILE * password_file; + password_file = fopen(argv[1], "rb"); + char word[10000]; + + int i, a = 0, b = 0; + fseek(password_file, 0L, SEEK_END); + int sz = ftell(password_file); + + rewind(password_file); + int hashes[sz / 32][32]; + unsigned char buff[sz]; + fread(buff, sizeof(buff), 1, password_file); + for (i = 0; i < sz; i++) { + if (i % 32 == 0) { + a++; + b = 0; + } -} -if (argc==3) -{ - FILE *password_file,*word_list_file; - password_file=fopen(argv[1],"rb"); - word_list_file=fopen(argv[2],"rb"); - int i,a=0,b=0; - fseek(password_file, 0L, SEEK_END); - int sz = ftell(password_file); - - rewind(password_file); - int hashes[sz/32][32]; - unsigned char buff[sz]; - fread(buff,sizeof(buff),1,password_file); - for(i = 0; i<sz; i++){ - if(i%32==0){ - a++; - b=0; - printf("\n"); - } - - hashes[a][b]=buff[i]; - - b++; - } - crack6(argv[2],hashes); - variations("common_passwords1.txt",hashes); - + hashes[a][b] = buff[i]; + + b++; + } + + makeguess(argv[2], hashes, a); + } + return 0; } - return 0; +void makeguess(char * word_list, int hashes[][32], int a) { + SHA256_CTX ctx; + BYTE buffer[SHA256_BLOCK_SIZE]; + BYTE word[10000]; + FILE * fp; + int j=0; + char c; + fp = fopen(word_list, "rb"); + int len=0; + bool cracked=true; + int exist[a]; + + while((c = fgetc(fp)) != EOF) + { + if(c == '\n') + { + + word[len]='\0'; + + sha256_init( & ctx); + sha256_update( & ctx, word, len); + sha256_final( & ctx, buffer); + + for (int j = 0; j < a; j++) { + + cracked = true; + for (int i = 0; i < 32; i++) { + if (buffer[i] != hashes[j][i]) { + + cracked = false; + break; + } + } + if (cracked == true && exist[j + 1] != 1) { + ctx.data[6] = '\0'; + exist[j+1]=1; + ++count; + printf("%s %d\n", ctx.data,j+1); + } + } + for (int k = 0; k < len; ++k) { + BYTE password1[len-1]; + for (int l = 0; l < len; ++l) { + if (k == l) { + + + if (word[k] >= 65 && word[k] < 90) { + password1[k] = word[k] + 32; + } else if (word[k] >= 97 && word[k] < 123) { + password1[k] = word[k] - 32; + } else { + password1[k] = word[k]; + } + } else { + password1[l] = word[l]; + } + } + password1[len] = '\0'; + + + sha256_init( & ctx); + sha256_update( & ctx, password1, len); + sha256_final( & ctx, buffer); + + for (int j = 0; j < a; j++) { + + cracked = true; + for (int i = 0; i < 32; i++) { + if (buffer[i] != hashes[j][i]) { + + cracked = false; + break; + } + } + if (cracked == true && exist[j + 1] != 1) { + ctx.data[6] = '\0'; + exist[j + 1] = 1; + count++; + printf("%s %d\n", ctx.data, j + 1); + } + } + + } + for (int k = 0; k < len; ++k) { + BYTE password1[len-1]; + for (int l = 0; l < len; ++l) { + if (k == l) { + + + if (word[k] >= 65 && word[k] < 90) { + password1[k] = word[k] + 32; + } else if (word[k] >= 97 && word[k] < 123) { + password1[k] = word[k] - 32; + } else { + password1[k] = word[k]; + } + } else { + password1[l] = word[l]; + } + } + password1[len] = '\0'; + password1[0] = password1[0] - 32; + + + sha256_init( & ctx); + sha256_update( & ctx, password1, len); + sha256_final( & ctx, buffer); + + for (int j = 0; j < a; j++) { + + cracked = true; + for (int i = 0; i < 32; i++) { + if (buffer[i] != hashes[j][i]) { + + cracked = false; + break; + } + } + if (cracked == true && exist[j + 1] != 1) { + ctx.data[6] = '\0'; + exist[j + 1] = 1; + count++; + printf("%s %d\n", ctx.data, j + 1); + } + } + + } + len=0; + + } + else + { + word[len]=c; + ++len; + } + } + + + + } \ No newline at end of file diff --git a/crack.exe b/crack.exe index 6c5299eeb54ca9f5415cf4816ee1aef7e63e2a54..a3817294e441f955c9f0db15c9c3d71958c828ac 100644 Binary files a/crack.exe and b/crack.exe differ