Алгоритм грубой силы с seg крипты.придираться - PullRequest
0 голосов
/ 29 мая 2018

У меня есть файл, содержащий зашифрованные пароли пользователей.Я хочу проверять каждый пароль с каждой возможной комбинацией буквенных символов (в зависимости от длины, которую дает пользователь), и, если она одинакова, я записываю ее в файл, как в системе аутентификации по паролю с использованием функции crypt.Однако, когда алгоритм работает какое-то время (с длиной> 4), он случайно отбрасывает сегмент.ошибка, как на скриншоте ниже.

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);
}
...