-
-
Save andreiglingeanu/7239877 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _XOPEN_SOURCE | |
#include <ctype.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
int yell_args(int argc, char** argv); | |
short is_password(const char* plain, const char* salt, const char* cipher); | |
short dict_attack(const char* salt, const char* cipher); | |
int main(int argc, char *argv[]) | |
{ | |
if (yell_args(argc, argv)) | |
{ | |
return 1; | |
} | |
char salt[2]; | |
strncpy(salt, argv[1], 2); | |
// do dictionary based attack | |
if (!dict_attack(salt, argv[1])) | |
{ | |
puts("Dictionary attack failed:("); | |
return 1; | |
} | |
return 0; | |
} | |
int yell_args(int argc, char** argv) | |
{ | |
if (argc < 2) | |
{ | |
printf("You passed no arguments!\n"); | |
return 1; | |
} | |
else if (argc > 2) | |
{ | |
printf("You passed to much arguments.\n"); | |
return 1; | |
} | |
return 0; | |
} | |
short is_password(const char* plain, const char* salt, const char* cipher) | |
{ | |
return strcmp(crypt(plain, salt), cipher) == 0; | |
} | |
short dict_attack(const char* salt, const char* cipher) | |
{ | |
FILE* fp = fopen("/usr/share/dict/words", "r"); | |
char word[256]; | |
int success = 0; | |
char* hacked; | |
while(fgets(word, sizeof(word), fp) != NULL) | |
{ | |
int len = strlen(word); | |
if (word[len - 1] == '\n') | |
word[len - 1] = 0; | |
if(is_password(word, salt, cipher)) | |
{ | |
hacked = word; | |
success = 1; | |
break; | |
} | |
} | |
fclose(fp); | |
if (success) | |
printf("%s\n", hacked); | |
return success; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment