具有crypt seg的Bruteforce算法。故障

时间:2018-05-29 17:25:06

标签: c linux encryption password-encryption

我有一个包含加密用户密码的文件。我想用每个可能的字母字符组合检查每个密码(取决于用户提供的长度),如果它相同,我将其写入文件,如使用crypt函数的密码认证系统。然而,当算法运行一段时间(长度> 4)时,它随机地丢弃一个seg。错误,如下面的截图。

enter image description here

#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <crypt.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sys/stat.h>
#define pass_size 10000000000

char *f_password,*f2_password,*log_password,*log_password2,*f3_password,*f4_founds;
int i=0,founds=0,ans,found=0,length;
char username[1000];
char password[1000];
int counter=0;


static const char alphabet[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
 int x=0;
static const int alphabetSize = sizeof(alphabet) - 1;



int main(void)
{

clock_t begin=clock();
void bruteSequential(int maxlen);
void bruteImpl(char* str, int index, int maxDepth);



printf("Press 1 for Bruteforce.\n");
printf("Press 2 for Exit.\n");
scanf("%d",&ans);



switch(ans)
 {


    case 1:
    {
        printf("Enter the length of the passwords\n");
        scanf("%d",&length);
        bruteSequential(length);
        break;

    }

    case 2:
    printf("Bye!\n");
    exit(1);

 }

 clock_t end=clock();
 double time_spent=(double)(end-begin)/CLOCKS_PER_SEC;      //clock ticking!
 printf("Time of process :  %f  Seconds \n",time_spent);
 return 0;

}






//bruteforse time 
void bruteImpl(char* str, int index, int maxDepth)
{
  FILE *f4=fopen("Users_found2.txt","a+");
  FILE *f=fopen("shadow_2016.txt","r");
  FILE *f6=fopen("encr_pass","a+");

    for (int i = 0; i < alphabetSize; ++i)
    {
        str[index] = alphabet[i];

        if (index == maxDepth - 1)
         {


            f_password=(char*) malloc(1000000000*sizeof(char));
            x++;
            printf("Attempt %d , with word %s... \n",x,str);


            while((fscanf(f,"%s",f_password)!=EOF ))
            {

             strcpy(username,strtok(f_password,":"));
             strcpy(password,strtok(NULL,":"));
             log_password = crypt(str,password); 
             fprintf(f6,"%s\n",log_password);


             if (strcmp(log_password,password)==0)    
             {                              


              fprintf(f4,"Access Granted of user %s with password %s from (Bruteforce) \n ",username,str);

              found++;


              }                                                       

            }

        }

        else bruteImpl(str, index + 1, maxDepth);
    }
    fclose(f);
    fclose(f4);
    fclose(f6);
    printf("%d password(s) found, see Users_found.txt file for users passwords... \n",found);
}



//bruteforce time
void bruteSequential(int maxLen)
{
    char* buf = malloc(maxLen + 1);

    for (int i = 1; i <= maxLen; ++i)
    {
        memset(buf, 0, maxLen + 1);
        bruteImpl(buf, 0, i);
    }

    free(buf);
}

0 个答案:

没有答案