diff --git a/crack.c b/crack.c index 6f055b4298e793757d465cd45cb9b3b646a30c60..5f034398081805afaf497c5c536ad3d6b8a766d8 100644 --- a/crack.c +++ b/crack.c @@ -17,7 +17,7 @@ #include <sys/resource.h> #include <sys/time.h> #include <sys/stat.h> -int check_guess(BYTE secrets[], BYTE hash[]); +int check_guess(BYTE secrets[], BYTE hash[], int size); int get_password(char *line, FILE *fp); @@ -36,15 +36,18 @@ get_password(char *line, FILE *fp) { -int check_guess(BYTE secrets[], BYTE hash[]) { +int check_guess(BYTE secrets[], BYTE hash[], int size) { //for(int i=0; i<32;i++){ // printf("%02x",hash[i]); //} //printf("\n"); int compare_size = 32; int flag; + + int turn = (size /32) + 1; + //printf("size is %d, turn is %d\n",size, turn); //flag = true; - for(int i = 1 ; i < 11 ; i++) { + for(int i = 1 ; i < turn ; i++) { flag = -1; for(int k = (i - 1) *compare_size; k < i *compare_size; k++) { if (secrets[k] != hash[k-((i - 1) *compare_size)]) { @@ -56,7 +59,11 @@ int check_guess(BYTE secrets[], BYTE hash[]) { } if(flag == 1){ + //int num; + //num = flag * i; + //printf("this is true for %d\n", i); //printf("true!!!!\n"); + //printf("return value should be %d\n",num); return flag * i; } } @@ -70,13 +77,23 @@ int main( int argc, char **argv ) /* check we have 0 argument, test for guessing password*/ if( argc < 2 ) - { + { + FILE *fp; FILE *fp1; + int pwd4_size; fp1 = fopen("out.txt", "w"); BYTE secrets[320]; fp = fopen("pwd4sha256", "rb"); fread(secrets, 320, 1, fp); + /*Move file point at the end of file.*/ + fseek(fp, 0, SEEK_END); + + /*Get the current position of the file pointer.*/ + pwd4_size=ftell(fp); + + fseek(fp, 0, SEEK_SET); + printf("size is %d\n", pwd4_size); for(int i = 0; i < 320; i++){ printf("%02x", secrets[i]); @@ -100,8 +117,8 @@ int main( int argc, char **argv ) sha256_init(&ctx); sha256_update(&ctx, (BYTE*)guess, strlen(guess)); sha256_final(&ctx, data); - if (check_guess(secrets, data) > 0) { - secret_num = check_guess(secrets, data); + if (check_guess(secrets, data, pwd4_size) > 0) { + secret_num = check_guess(secrets, data, pwd4_size); printf("%s %d\n",guess, secret_num); fprintf(fp1, "%s %d\n", guess, secret_num); } @@ -111,7 +128,62 @@ int main( int argc, char **argv ) } } } + guess[5] = '\0'; + + FILE *fp3; + BYTE long_secrets[640]; + fp3 = fopen("pwd6sha256", "rb"); + fread(long_secrets, 640, 1, fp3); + int pwd6_size; + /*Move file point at the end of file.*/ + fseek(fp3, 0, SEEK_END); + + /*Get the current position of the file pointer.*/ + pwd6_size=ftell(fp3); + + fseek(fp3, 0, SEEK_SET); + printf("size is %d\n", pwd6_size); + for(int i = 0; i < 640; i++){ + + printf("%02x", long_secrets[i]); + if(((i+1) %32) == 0) { + printf("\n"); + } + } + printf("\n"); + + char long_guess[7]; + int long_secret_num; + SHA256_CTX long_ctx; + BYTE long_data[SHA256_BLOCK_SIZE]; + for(int i = 48; i < 58; i++) { + for(int j = 48; j < 58; j++) { + for(int l = 48; l < 58; l++) { + for(int k = 48; k < 58; k++) { + for(int n = 48; n < 58; n++) { + for(int m = 48; m < 58; m++) { + sprintf(long_guess, "%c%c%c%c%c%c", i, j, l, k, n, m); + //printf("%s\n",guess); + + sha256_init(&long_ctx); + sha256_update(&long_ctx, (BYTE*)long_guess, strlen(long_guess)); + sha256_final(&long_ctx, long_data); + if (check_guess(long_secrets, long_data, pwd6_size) > 0) { + long_secret_num = check_guess(long_secrets, long_data, pwd6_size); + long_secret_num = long_secret_num + 10; + //printf("long secret num should be %d\n", long_secret_num); + printf("%s %d\n",long_guess, long_secret_num); + fprintf(fp1, "%s %d\n", long_guess, long_secret_num); + } + } + } + } + } + } + } + long_guess[7] = '\0'; + return 0; } @@ -125,11 +197,12 @@ int main( int argc, char **argv ) { FILE *fp1; fp1 = fopen(argv[2], "rb"); - BYTE secrets[320]; - fread(secrets, 320, 1, fp1); int fp1_size; fseek(fp1, 0, SEEK_END); fp1_size=ftell(fp1); + fseek(fp1, 0, SEEK_SET); + BYTE secrets[fp1_size]; + fread(secrets, fp1_size, 1, fp1); for(int i = 0; i < fp1_size; i++){ printf("%02x", secrets[i]); @@ -148,8 +221,8 @@ int main( int argc, char **argv ) sha256_init(&ctx); sha256_update(&ctx, (BYTE*)line, strlen(line)); sha256_final(&ctx, data); - if (check_guess(secrets, data) > 0) { - secret_num = check_guess(secrets, data); + if (check_guess(secrets, data, fp1_size) > 0) { + secret_num = check_guess(secrets, data, fp1_size); printf("%s %d\n", line, secret_num); } } diff --git a/out.txt b/out.txt index 2deff07b0f39ad67458fe696cfb3d01bd375446c..f6f1b81ac7de3ed277b9f9d1c7dfa626be47c1fa 100644 --- a/out.txt +++ b/out.txt @@ -8,3 +8,8 @@ oca{ 10 reng 2 tuyy 9 weij 7 +090909 25 +360258 11 +369258 13 +379258 12 +469258 29 diff --git a/outcomeone.txt b/outcomeone.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391