0

It seems I get segmentation fault when I try to decrypt the passwords, I somehow thought my logic is right but it seems it's not working. I also get four warnings in using crypt function for implicit declaration of crypt and incompatible integer to pointer conversion. Here is the code:

#define _X_OPEN_SOURCE

#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
    // making sure the have 2 inputs
    if (argc != 2)
    {
        printf("Put in the statement: ./crack username\n");
        return 1;
    }

    char  *hash = argv[1];
    char salt[2];

    // first two salt characters to hash
    salt[0] = hash[0];
    salt[1] = hash[1];

    char alphabet[] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};

    char guessTwoChars[3];

    // for 2 char passwords 52 * 51 / 2!
    for (int i = 0; i < 52; i++)
    {
        guessTwoChars[0] = alphabet[i];

        for (int j = 0; j < 52; j++)
        {
            guessTwoChars[1] = alphabet[j];
            if (strcmp (hash, crypt(guessTwoChars,salt)) == 0)
            {
                printf("Password is %s\n",guessTwoChars);
            }
        }
    }

    // for 3 char passwrds 3 innermost loops
    char guessThreeChars[4];

    for (int i = 0; i < 52; i++)
    {
        guessThreeChars[0] = alphabet[i];

        for (int j = 0; j < 52; j++)
        {
            guessThreeChars[1]  = alphabet[j];

            for(int k = 0; k < 52; k++)
            {
                guessThreeChars[2] = alphabet[k];
                if (strcmp (hash, crypt(guessThreeChars,salt)) == 0)
                {
                    printf("Password is %s\n",guessThreeChars);
                }
            }
        }

    }

    char guessFourChars[5];

    // for 4 char passwords
      for (int i = 0; i < 52; i++)
    {
        guessFourChars[0] = alphabet[i];

        for (int j = 0; j < 52; j++)
        {
            guessFourChars[1]  = alphabet[j];

            for (int k = 0; k < 52; k++)
            {
                guessFourChars[2] = alphabet[k];

                for (int l = 0; l < 52; l++)
                {
                    guessFourChars[3] = alphabet[k];
                     if (strcmp (hash, crypt(guessFourChars,salt)) == 0)
                    {
                        printf("Password is %s\n",guessFourChars);
                    }
                }
            }
        }

    }
    return 0;
}
0

You are using a crypt function that does not seem to be defined anywhere, please tell us what is crypt,on the other hand the statements:

char guessTwoChars[3];

.......

for (int i = 0; i < 52; i++)
    {
        guessTwoChars[0] = alphabet[i];

        for (int j = 0; j < 52; j++)
        {
            guessTwoChars[1] = alphabet[j]

And other similar statements, always assign the last alphabet value to guessTwoChars [0] etc, ie

guessTwoChars[0]= Z
guessTwoChars[1]= Z

etc

  • crypt is a part of unistd.h library. It is the password encryption function, you can read on it on the manual page. – Arsenal Vakili May 9 '17 at 13:33

You must log in to answer this question.

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