-
Notifications
You must be signed in to change notification settings - Fork 0
/
crack_test.c
101 lines (85 loc) · 3.34 KB
/
crack_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* crack.c
*
* Computer Science 50
* Problem Set 2 (Hacker Edition)
*
* Password cracker assuming DES based encryption, in this case, the crypt() function of C.
* WARNING: Run time is hours/days.
*
*/
#define _XOPEN_SOURCE
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <crypt.h>
#include <unistd.h>
// Compile with || clang -o crack crack.c -lcrypt
// Run with || ./crack [hash]
// Tested on
/*
1 || 50Xu9TV42tQOg || 0.002s || 3,420 possible passwords
al || 507IH4BV0kgzc || 0.789s || 324,900 possible passwords
RoR || 50b5ILzBEDplw || 45.780s || 30,865,500 possible passwords
Ruby || 50VfakyL0ptK. || 4170.874s || 2,932,222,500 possible passwords
Linux || 50u8HReKZleek || 355826.965s || 278,561,137,500 possible passwords
*/
// You can try with
/*
AliOsm || 50F7Vs3yYSpak || Do it! || 26,463,308,062,500 possible passwords
abcdefg || 50ozejrWnaK1U || Do it! || 2,514,014,265,937,500 possible passwords
12345678 || 50gyRGMzn6mi6 || Do it! || 238,831,355,264,062,500 possible passwords
*/
int main(int argc, char* argv[]) {
// make sure there exist one command argument only
if (argc != 2) {
printf("Usage: ./crack hash\n");
return 1;
}
// uncomment this two lines to generate new hashes
/*
printf("%s\n", crypt("abcdefg", "50"));
return 0;
*/
// generated password to crack encrypted one
char generated_password[5] = {};
// test array to store passwords of all lengths
char test[5] = {};
// extract salt from encrypted password
char salt[3];
salt[0] = argv[1][0];
salt[1] = argv[1][1];
// store all ASCII characters in an array
char arr[95];
for(int i = 0; i < 95; i++) arr[i] = (char) (i + 32);
printf("Trying to hack entered hash, please wait an hour, a day or months,\nyou will stay here a long long (long)^(inf) time :D\n");
// try all possible passwords of length 8 or less
for(int i = 0; i < 95; i++)
for(int j = 0; j < 95; j++)
for(int k = 0; k < 95; k++)
for(int l = 0; l < 95; l++)
{
// generate first password
generated_password[0] = arr[i];
generated_password[1] = arr[j];
generated_password[2] = arr[k];
generated_password[3] = arr[l];
// try all subpasswords of all lengths from generated password
for(int q = 0, r = 4; q <= 3; q++, r--)
for(int s = 0; s < q + 1; s++) {
// take r characters
strncpy(test, generated_password+s, r);
test[r] = '\0';
// try password of length r
if(strcmp(crypt(test, salt), argv[1]) == 0) {
printf("Password found!\n%s\n", test);
return 0;
}
}
}
// if nothing found print nothing found xD
printf("Nothing found :(\n");
return 0;
}