forked from ASeriousMister/SeedSearch.py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseedsearch.py
283 lines (264 loc) · 8.36 KB
/
seedsearch.py
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env python3
from hdwallet.utils import is_mnemonic
import os
import argparse
import docx
from PyPDF2 import PdfReader
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
# intro
print(color.YELLOW + "Welcome to seedsearch.py! Let\'s hunt for some BIP39 mnemonic seed\n" + color.END)
print(color.RED + 'DISCLAIMER: ' + color.END + 'This tool works with BIP39 seed')
print(' It is intended to make searches in a quick way, but it has not to be considered exhaustive\n')
print(color.PURPLE + 'This is a lite version, it will only look for seeds, without trying to check them online\n' + color.END)
parser = argparse.ArgumentParser(description='Mnemonic seed finder')
parser.add_argument('-d', metavar='directory', type=str, required=True, help='Directory to scan')
args = parser.parse_args()
directory = args.d
# Quits if directory does not exist
if not os.path.exists(directory):
quit(color.RED + 'Directory does not exist!' + color.END)
def getListOfFiles(dirName):
# create a list of file and sub directories
listOfFile = os.listdir(dirName)
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getListOfFiles(fullPath)
else:
allFiles.append(fullPath)
return allFiles
def check_lang(word):
f = open('Wordlists/b39en')
if word in f.read():
f.close()
return 'english'
f = open('Wordlists/b39it')
if word in f.read():
f.close()
return 'italian'
f = open('Wordlists/b39cz')
if word in f.read():
f.close()
return 'czech'
f = open('Wordlists/b39es')
if word in f.read():
f.close()
return 'spanish'
f = open('Wordlists/b39fr')
if word in f.read():
f.close()
return 'french'
f = open('Wordlists/b39pr')
if word in f.read():
f.close()
return 'portuguese'
f = open('Wordlists/b39cn')
if word in f.read():
f.close()
return 'chinese_simplified'
f = open('Wordlists/b39cn2')
if word in f.read():
f.close()
return 'chinese_traditional'
f = open('Wordlists/b39jp')
if word in f.read():
f.close()
return 'japanese'
f = open('Wordlists/b39kr')
if word in f.read():
f.close()
return 'korean'
f.close()
return 'none'
def check_word(word, language):
if language == 'english':
f = open('Wordlists/b39en')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'italian':
f = open('Wordlists/b39it')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'czech':
f = open('Wordlists/b39cz')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'spanish':
f = open('Wordlists/b39es')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'french':
f = open('Wordlists/b39fr')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'portuguese':
f = open('Wordlists/b39pr')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'chinese_simplified':
f = open('Wordlists/b39cn')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'chinese_traditional':
f = open('Wordlists/b39cn2')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'japanese':
f = open('Wordlists/b39jp')
if word in f.read():
f.close()
return True
else:
f.close()
return False
if language == 'korean':
f = open('Wordlists/b39kr')
if word in f.read():
f.close()
return True
else:
f.close()
return False
# Get text from docx files
def getText(filename):
doc = docx.Document(filename)
fullText = []
for para in doc.paragraphs:
fullText.append(para.text)
return '\n'.join(fullText)
# Get the list of all files in the given path
listOfFiles = getListOfFiles(directory)
# Changes working directory to avoid issues with file opening
# use full path to open wordlists or full path to open files
# os.chdir('folder/with/wordlist')
temp_seed = [] # list that stores the seed during execution
seed_out = []
seed2check = []
n_files = len(listOfFiles)
print(color.BLUE + f'There are {n_files} files to scan' + color.END)
i = 0
# iterate through all the files
# print(listOfFiles)
while i < n_files:
# manage docx files
if '.docx' in listOfFiles[i]:
with open(directory + 'fgrtgdtegd', 'w') as f: # random filename to avoid conflicts
f.write(getText(listOfFiles[i]))
f.close()
f = open(directory + 'fgrtgdtegd', 'r')
f.seek(0)
# manage pdf files
elif '.pdf' in listOfFiles[i]:
reader = PdfReader(listOfFiles[i])
text = ""
for page in reader.pages:
text += page.extract_text() + "\n"
with open(directory + 'fgrtgdtegd', 'w') as f:
f.write(text)
f.close()
f = open(directory + 'fgrtgdtegd', 'r')
f.seek(0)
# managing other files like txt, csv, html, json, etc.
else:
# Try if file can't be handled
try:
with open(listOfFiles[i], 'r') as tc:
content = tc.read()
except UnicodeDecodeError:
print(color.YELLOW + '\nUnable to open ' + listOfFiles[i] + color.END)
i += 1
continue
f = open(listOfFiles[i], 'r')
language = ''
line = f.readline()
while line: # reads the lines
for word in line.split():
checking = True # used to check other wordlists if a word is not in the current wordlist
while checking:
if len(temp_seed) == 0:
# identify language
language = check_lang(word)
if language == 'none':
checking = False
else:
temp_seed.append(word)
checking = False
else:
if check_word(word, language):
temp_seed.append(word)
checking = False
else:
temp_seed = []
if (len(temp_seed) > 11) and (len(temp_seed) % 3 == 0):
temp_seed_str = ' '.join(temp_seed)
# adds only valid bip39 seeds to output
if is_mnemonic(temp_seed_str, language):
langprint = language.upper()
# adds language of the seed (uppercase and in brackets) to the output string
temp_seed_str += ' (' + langprint + ')'
seed_out.append(temp_seed_str)
seed2check.append(temp_seed_str)
temp_seed = []
elif len(temp_seed) > 24:
temp_seed = []
line = f.readline()
# Printing the output
pr = 0
if len(seed_out) > 0:
print(color.DARKCYAN + f'\n=== Seeds found in {listOfFiles[i]} ===' + color.END)
while pr < len(seed_out):
pr += 1
prpr = str(pr)
print(prpr + ' ' + seed_out[pr - 1])
seed_out = []
f.close()
i += 1
# delete temporary file
if os.path.isfile(directory + 'fgrtgdtegd'):
os.remove(directory + 'fgrtgdtegd')