0

My version of crack.c is not finding two passwords. As far as I can tell, I am exhausting the entire alphabetic search space, and I've found both upper and lowercase passwords. Assuming there's no spaces or other special characters in the solution set, what could this brute force solution be missing?

//Headers, args, salt, etc omitted
char alphabet[53] = {'A'};
for(int i = 0;i<26;i++)
{
    alphabet[i]=alphabet[0];
    alphabet[0]++;
}
alphabet[0] = 'A';

alphabet[26]= 'a';
for(int i = 26;i<52;i++)
{
    alphabet[i]=alphabet[26];
    alphabet[26]++;
}
alphabet[26]= 'a';

for(int first=0;first<53;first++)
{
    for(int second=0;second<53;second++)
    {
        for(int third=0;third<53;third++)
        {
            for(int fourth=0;fourth<53;fourth++)
            {
                for(int fifth=0;fifth<53;fifth++)
                {
                    char candidate[] = {alphabet[first],alphabet[second],alphabet[third],alphabet[fourth],alphabet[fifth]};
                    char *candidate_crypt = crypt(candidate,salt);
                    if (strcmp(hash, candidate_crypt) == 0)
                    {
                        printf("%s",candidate);
                        exit(0);
                    }
                }
            }
        }
    }
}
printf("No result found");
return 1;

Edit:

Took off the 5 character assignment, but still not finding those last passwords...

1

char candidate[5] is a char array with 5 chars. It is not a 'string' which is what crypt needs. (a string is a char array that ends in a null char).

I'm actually surprised you are finding any passwords given that you are passing a non-null terminated array to crypt. But I'd guess the ones you aren't cracking are 5-character passwords.

3
  • Great spot! I changed it to candidate[] as reflected above, but still not cracking the new ones. You are correct that all passwords I did crack were four or less characters. – pcm Apr 19 '18 at 23:43
  • 1
    You still don't have a string capable of holding 5 chars, since you don't have room for the null char, which you aren't adding. a string "abcde" is stored in memory as {'a', 'b', 'c', 'd', 'e', '\0'} – curiouskiwi Apr 20 '18 at 3:10
  • That's it. thanks! – pcm Apr 20 '18 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .