Skip to content

Instantly share code, notes, and snippets.

@shortstuffsushi
Created January 9, 2017 00:05
Show Gist options
  • Save shortstuffsushi/bfed132a4440396c3d412fab398a94d4 to your computer and use it in GitHub Desktop.
Save shortstuffsushi/bfed132a4440396c3d412fab398a94d4 to your computer and use it in GitHub Desktop.
Quick Crack demo
#define _XOPEN_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("Please enter exactly one hashed password as a command line argument.");
return 1;
}
char salt[2] = { argv[1][0], argv[1][1] };
char guess[5] = { 'a', '\0', '\0', '\0', '\0' };
while (strcmp(crypt(guess, salt), argv[1]))
{
//printf("Tried %s and failed.\n", guess);
for (int i = 0; i < 4; i++) {
// Hasn't been used yet, default to a and stop looping
if (guess[i] < 'a') {
guess[i] = 'a';
break;
}
// Greater than the upper boundary, reset and continue loop
else if (++guess[i] > 'z') {
if (i == 3) {
printf("Your password doesn't exist\n");
return 1;
}
guess[i] = 'a';
}
// Less than the upper boundary, break loop
else {
break;
}
}
}
printf("Your password was %s.\n", guess);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment