From c48fe9012b9ec83f1977e6d5b41c58bc0edcb751 Mon Sep 17 00:00:00 2001
From: aneesh <achattaraj@student.unimelb.edu.au>
Date: Fri, 24 May 2019 16:29:35 +1000
Subject: [PATCH] crack fixwd

---
 crack.c | 207 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 108 insertions(+), 99 deletions(-)

diff --git a/crack.c b/crack.c
index e68effa..5fddd90 100644
--- a/crack.c
+++ b/crack.c
@@ -9,6 +9,7 @@
 #include <stdbool.h>
 int exist[30];
 BYTE old[6];
+int count=0;
 
 void printRandomString(int hashes[30][32]) 
 {   bool cracked = true;
@@ -16,8 +17,12 @@ SHA256_CTX ctx;
  
 
     BYTE buffer[SHA256_BLOCK_SIZE];
-    int count = 0;
+    
     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;; 
@@ -39,6 +44,7 @@ SHA256_CTX ctx;
             if( cracked==true && exist[k+1]!=1 ){
                 ctx.data[6] = '\0';
                 exist[k+1]=1;
+                ++count;
                 printf("%s %d\n", ctx.data, k+1);        
             }
         }
@@ -48,43 +54,47 @@ SHA256_CTX ctx;
 }
 void variations(char *word_list_file, int hashes[30][32])
 {
-	SHA256_CTX ctx;
+  SHA256_CTX ctx;
     BYTE buffer[SHA256_BLOCK_SIZE];
     BYTE password[6];
     bool cracked = true;
-    int count = 0;
+    
     FILE *word_list;
     word_list=fopen(word_list_file, "rb");
 
     while ( fgets(password, 7, word_list) != '\0'){
-
-    	for (int c = 0; c < 6; ++c)
-    	{	BYTE password1[6];
-    		for (int i = 0; i < 6; ++i)
+      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];
-          	}
+            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);
+            password1[6]='\0';
+            
+            
+            sha256_init(&ctx);
             sha256_update(&ctx, password1, sizeof(password1));
             sha256_final(&ctx, buffer);
                     
@@ -101,11 +111,12 @@ void variations(char *word_list_file, int hashes[30][32])
             if( cracked==true && exist[j+1]!=1){
                 ctx.data[6] = '\0';
                 exist[j+1]=1;
+                count++;
                 printf("%s %d\n", ctx.data, j+1);        
             }
         }
     
-    	}
+      }
           
 
    }
@@ -116,11 +127,11 @@ void variations(char *word_list_file, int hashes[30][32])
 }
 void printRandomString1(int k) 
 {
-    int count = 0;
-    for (int i = 0; i < k; ++i) {
+    
+    for (int i = 0; i < k-1; ++i) {
     BYTE res[6];
     for (int j = 0; j < 6; j++)  
-        res[j] = (rand()% 26)+97;; 
+        res[j] = (rand()% 59)+65;; 
     res[6]='\0';
     printf("%s\n",res );
 } 
@@ -132,7 +143,7 @@ void bruteforce(int hashes[30][32]){
     BYTE buffer[SHA256_BLOCK_SIZE];
     BYTE password[4];
     bool cracked = true;
-    int count = 0;
+    
     
     for(int c1=32; c1<127; c1++){
         password[0] = c1;
@@ -177,10 +188,10 @@ void bruteforce(int hashes[30][32]){
 /* Function to swap values at two pointers */
 void swap(char *x, char *y) 
 { 
-	char temp; 
-	temp = *x; 
-	*x = *y; 
-	*y = temp; 
+  char temp; 
+  temp = *x; 
+  *x = *y; 
+  *y = temp; 
 } 
 
 /* Function to print permutations of string 
@@ -192,20 +203,20 @@ 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 count = 0;
+    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);
+  { 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);
 
@@ -226,48 +237,48 @@ if (l == r)
             }
         }
     }else{BYTE n[6];
-    	int count=0;
-		for (int k = 0; k < 6; ++k)
-		{
-			n[k]=a[k];
-			if (old[k]==n[k])
-			{
-				++count;
-			}
-
-		}
-
-		n[6]='\0';
-		if(count<6)
-		{
-		printf("%s\n",n ); 
-		for (int k = 0; k < 7; ++k)
-		{
-			old[k]=n[k];
-
-		}
-		}
+      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];
+
+    }
+    }
 
     }}
 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 
-	} 
+  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;
+{ 
+   SHA256_CTX ctx;
     BYTE buffer[SHA256_BLOCK_SIZE];
     BYTE password[12];
     bool cracked = true;
-    int count = 0;
+    
     char word[30];
 
 
@@ -277,18 +288,18 @@ void permutations1(char *word_list_file, int hashes[30][32],int status)
     
 
     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;
-          	}
-          	
+            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';
@@ -304,7 +315,7 @@ void crack6(char *word_list_file, int hashes[30][32])
     BYTE buffer[SHA256_BLOCK_SIZE];
     BYTE password[6];
     bool cracked = true;
-    int count = 0;
+    
     char word[30];
 
 
@@ -330,6 +341,7 @@ void crack6(char *word_list_file, int hashes[30][32])
             if( cracked==true && exist[j+1]!=1 ){
                 ctx.data[6] = '\0';
                 exist[j+1]=1;
+                ++count;
                 printf("%s %d\n", ctx.data, j+1);        
             }
         }  
@@ -362,7 +374,7 @@ void crack6(char *word_list_file, int hashes[30][32])
        b++;
    }
    
-   
+   bruteforce(hashes);
    unsigned char buff6[640];
    file_6=fopen("pwd6sha256","rb");
    fread(buff6, sizeof(buff6),1, file_6);
@@ -374,7 +386,7 @@ void crack6(char *word_list_file, int hashes[30][32])
            printf("\n");
        }
        hashes[a][b]=buff6[i];
-       printf("%x", hashes[a][b]);
+       
        
        b++;
    }
@@ -392,9 +404,9 @@ void crack6(char *word_list_file, int hashes[30][32])
 }
 if (argc==2)
 {
-	int k=  atoi(argv[1]);
-	printf("%d\n",k );
-	printRandomString1(k);
+  int k=  atoi(argv[1]);
+  printf("%d\n",k );
+  printRandomString1(k);
 
 
 }
@@ -406,7 +418,7 @@ if (argc==3)
   int i,a=0,b=0;
   fseek(password_file, 0L, SEEK_END);
   int sz = ftell(password_file);
-  printf("%d\n", sz );
+  
   rewind(password_file);
   int hashes[sz/32][32];
   unsigned char buff[sz];
@@ -419,7 +431,7 @@ if (argc==3)
        }
        
        hashes[a][b]=buff[i];
-       printf("%x",hashes[a][b]);  
+        
        b++;
    }
    
@@ -429,7 +441,4 @@ if (argc==3)
 }
    return 0;
 
-}
-
-
-
+}
\ No newline at end of file
-- 
GitLab