-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCracker.java
More file actions
167 lines (114 loc) · 5.14 KB
/
Cracker.java
File metadata and controls
167 lines (114 loc) · 5.14 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package Default;
import java.util.Scanner;
import java.util.stream.Stream;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.nio.file.Files;
import java.io.IOException;
import java.math.BigInteger;
import java.util.stream.Collectors;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
public class Cracker {
public static void main(String args[]){
System.out.print("Enter User to hack: ");
Scanner scan = new Scanner(System.in);
String user = scan.nextLine();
//String userline = "";
long startTime = System.currentTimeMillis();
String log = "userlog.txt";
String dict = "dictionary.txt";
String lines = "";
//String guess = "";
String[] nums = {"0","1","2","3","4","5","6","7","8","9",""};
String[] chars = { "@","#","$","%","&",""};
// List<String> list = new ArrayList<>();
try (Stream<String> stream = Files.lines(Paths.get(log))) {
//searches user log for line of info of desired username
String userlist = stream.filter(line -> line.contains(user + ":"))
.map(n -> n.toString())
.collect(Collectors.joining(":"));
//isolates stored password hash from the user:password format
String cut = user + ":";
String userpass = userlist.replaceAll(cut, "");
//runs through dictionary once to check for weak type password
Scanner scanner2 = new Scanner(Paths.get(dict));
String dictword = "";
while(scanner2.hasNextLine()) {
dictword = scanner2.nextLine();
if (md5(dictword).contentEquals(userpass)) {
System.out.println("Password is: "+dictword);
System.exit(0);
}
}
// scans for type 2 moderate passwords
Scanner scanner = new Scanner(Paths.get(dict));
boolean found = false;
String[] isFound = {"Notfound"};
while((scanner.hasNextLine())&&(!(isFound[0].contentEquals("found")))) {
lines = scanner.nextLine();
//System.out.println("Testing Combinations for: " +lines);
//iterates through each combination of characters and integers, stores combo as list
//recursive call permutes through each order combination for the characters, intigers, and base dictionary word
for (int j = 0; j< chars.length; j++){
for (int k = j; k< chars.length; k++){
for (int l = 0; l< nums.length; l++){
for (int m = l; m< nums.length; m++) {
ArrayList order = new ArrayList<>(Arrays.asList(lines, chars[j], chars[k], nums[l], nums[m]));
// removes blank spaces from recursive call
for (int z =0 ; z < order.size(); z++) {
if (order.get(z) == ""){
order.remove(z);
z--;
}
}
recursion(order,"",userpass, isFound);
//if (isFound[0].contentEquals("found")){
//}
}
}
}
}
}
long end = System.currentTimeMillis();
float time = ((end-startTime)/1000F);
System.out.println("Took "+time +" seconds.");
} catch (IOException e) {
e.printStackTrace();
}
}
public static String md5(String input) {
String md5 = null;
if(null == input) return null;
try {
//Create MessageDigest object for MD5
MessageDigest digest = MessageDigest.getInstance("MD5");
//Update input string in message digest
digest.update(input.getBytes(), 0, input.length());
//Converts message digest value in base 16 (hex)
md5 = new BigInteger(1, digest.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return md5;
}
public static void recursion(ArrayList<String> strings, String guessString, String userpass,String[] isFound){
if (strings.size() == 0){
//guess(guessString);
if (md5(guessString).contentEquals(userpass)) {
System.out.println("Password is "+guessString);
isFound[0] = "found";
}
}
for (int i=0; i< strings.size(); i++){
ArrayList<String> newStrings = new ArrayList<String>(strings);
newStrings.remove(i);
recursion(newStrings, guessString + strings.get(i), userpass, isFound);
if ((i <= strings.size()-2) && (strings.get(i) == strings.get(i+1) )) {
i++;
}
}
}
}