forked from MaxCamillo/android-keystore-password-recover
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartWordlistResume.java
More file actions
132 lines (105 loc) · 3.81 KB
/
SmartWordlistResume.java
File metadata and controls
132 lines (105 loc) · 3.81 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
package AndroidKeystoreBrute;
/** ravensbane
*
* @version 1.0 on 20.2.2016
* @author
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Map;
public class SmartWordlistResume extends Thread {
static long lastCall = 0;
static final String resumeFile = "AndroidKeystoreBrute_Resume"; // the file name we'll resume from
// periodically save progress to a file
public void run() {
long sleepTime = 30000L;
try {
// don't try to save immediately when the thread spins up
Thread.sleep(sleepTime);
} catch (Exception e) {
}
File file = new File(resumeFile);
while (!SmartWordlistPasswd.found && !SmartWordlistPasswd.allPwdsTested) {
if ((System.nanoTime() - lastCall) > sleepTime * 1000000L) {
try {
// get the last produced combo that was picked up by a consumer and wait
// briefly to make sure it gets consumed before we write it to a file
String[] localS = SmartWordlistProducer.lastComboProduced;
Thread.sleep(100);
BufferedWriter writer = new BufferedWriter(new FileWriter(file, false));
// keystore
writer.write(SmartWordlistPasswd.keystoreFileName);
writer.newLine();
// dictionary
writer.write(SmartWordlistPasswd.dictFileName);
writer.newLine();
// write last combo to file, one word per line
int len = localS.length;
for (int i = 1; i < len; ++i) {
writer.write(localS[i]);
writer.newLine();
}
writer.close();
System.out.println("Progress saved in file: " + resumeFile + "\r\n");
} catch (Exception e) {
System.out.println("Unable to write to file: " + resumeFile + "\r\n");
}
lastCall = System.nanoTime();
try {
Thread.sleep(sleepTime);
} catch (Exception e) {
}
}
}
try {
file.delete();
} catch (Exception e) {
System.out.println("Unable to delete file: " + resumeFile);
}
}
// read saved progress from file to use as a resume point
public static ArrayList<String> getResumePoint(Map<String, String> words) throws IOException {
ArrayList<String> resumePoint = new ArrayList<String>();
BufferedReader file;
try {
file = new BufferedReader(new InputStreamReader(new FileInputStream(resumeFile)));
} catch (Exception e) {
return resumePoint;
}
String word = "";
// the first line should contain the same keystore file name as the one specified in args
word = file.readLine();
if (word == null || !word.equals(SmartWordlistPasswd.keystoreFileName)) {
file.close();
throw new IOException(resumeFile + " does not contain data for this keystore");
}
// the second line should contain the same dictionary file name as the one specified in args
word = file.readLine();
if (word == null || !word.equals(SmartWordlistPasswd.dictFileName)) {
file.close();
throw new IOException(resumeFile + " does not contain data from this dictionary");
}
// the other lines should contain the words we last checked from the dictionary
while ((word = file.readLine()) != null) {
// skip empty String
if (word.equals(""))
continue;
// make sure the word is a permutation of a word in the dictionary
if (words.containsKey(word)) {
resumePoint.add(word);
} else {
file.close();
throw new IOException(
resumeFile + " contains a word that does not match any allowed permutation of dictionary words)");
}
}
file.close();
return resumePoint;
}
}