-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparser.py
286 lines (246 loc) · 13 KB
/
parser.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
284
'''
--------------------------------------------------
DBPP - Data Breach Python Parser
--------------------------------------------------
Written by: Taro
Version: 1.0
'''
# TODO
# Make it so you can search after the @ too
import argparse
import sys
def getlang():
print('[1] English version')
print('[2] Magyar verzió')
lang = input()
if lang != '1' and lang != '2':
sys.exit('Please choose the language! (1 - English; 2 - Hungarian)')
return lang
def getargs_en():
parser = argparse.ArgumentParser()
parser.add_argument('-f','--find',dest='find', help='Provide the search term, 2 formats are accepted: Either it starts with @, like @gmail.com, then the program gives all the results which end with @gmail.com, or just provide the start of the email / the whole email like this: example / [email protected]')
parser.add_argument('-o', '--output', dest='output', help='Three values accepted: t, f, b meaning terminal, file and both. This option lets you choose how you want to see the output after the search is done. Default value is b = both')
parser.add_argument('-p', '--path', dest='path', help='This argument lets you provide the input folder, you have to provide the root breach folder, which contains folders like: 0, 1, 2 etc. Default setting is the same folder that the python script is in. Example: C:/something1/databreach')
parser.add_argument('-m', '--mode', dest='mode', help='This let you choose whether you want to search for a password or email. Accepted values are: p - for password, and e - for email.')
args = parser.parse_args()
if not args.find:
parser.error('[-] You forgot to provide the search term, use -f or --find to do so, or use -h or --help for help.')
if not args.mode:
parser.error('[-] You forgot to provide a search mode! Aviable options are: "p" for password and "e" for email.')
if args.mode != 'p' and args.mode != 'e':
parser.error('[-] You gave the wrong search mode. Aviable options are: "p" for password and "e" for email.')
if not args.output:
args.output = 'b'
else:
if args.output not in ['t', 'f', 'b']:
parser.error('[-] You gave a wrong value for the output. Accepted values are: t, f, b')
if not args.path:
args.path = './data'
return args
def getargs_hu():
parser = argparse.ArgumentParser()
parser.add_argument('-f','--find',dest='find', help='Add meg a keresendő dolgot! 2 féle formátum az elfogadott: Vagy @-al kezdődik amit beírsz, pl mint a @gmail.com, ekkor a program visszaad mindent, ami @gmail.com-al végződik, vagy csak add meg egy email elejét / az egész emailt pl. így: valami / [email protected]')
parser.add_argument('-o', '--output', dest='output', help='Három értéket fogadunk el bemenetként: t, f, b amiknek a jelentése: terminal (t), file (f) és mindkettő (b). Ezzel kiválasztod, hogyan szeretnéd kapni a kimenetet. Az alapértelmezett beállítás a b = mindkettő')
parser.add_argument('-p', '--path', dest='path', help='Ezzel adhatod meg, hogy hol vannak az adat fájlok. A sikeres működéshez a gyökérkönyvtárat kell megadni, amikben ezek a mappák vannak: 0, 1, 2 stb. Az alapbeállítás, ha nem adsz meg semmit, az a könyvtár, amiben a python script is van. Példa: C:/valami1/databreach')
parser.add_argument('-m', '--mode', dest='mode', help='Ezzel lehet kiválasztani, hogy a jelszavak vagy az emailek között keresel. Az elfogadott értékek: p - ha jelszavak között, és e - ha emailek között.')
args = parser.parse_args()
if not args.find:
sys.exit('[-] Elfelejtetted megadni, hogy mit keresel! Használd a -f vagy --find -ot, vagy kérj segítséget -h -val vagy --help -val.')
if not args.mode:
parser.error('[-] Nem adtál meg keresési módot! használd a -m-et, és adj p vagy e értéket neki.')
if args.mode != 'p' and args.mode != 'e':
parser.error('[-] Rossz keresési módot adtál meg. A két elfogadott érték: "p" és "e"')
if not args.output:
args.output = 'b'
else:
if args.output not in ['t', 'f', 'b']:
sys.exit('[-] Rossz értéket adtál meg outputnak. Az elfogadott értékek: t, f, b')
if not args.path:
args.path = './data'
return args
def kiir_terminal(mit):
print(mit)
def kiir_file(mit):
with open('passes.txt', 'a') as kifile_pass:
if mit.find(':') != -1:
mit_pass = mit.split(':')
else:
if mit.find(';') != -1:
mit_pass = mit.split(';')
if len(mit_pass) > 2:
passwd = ''
for i in (range(len(mit_pass)-1)):
passwd += mit_pass[i + 1]
else:
passwd = mit_pass[1]
try:
print(passwd, file=kifile_pass)
except UnicodeEncodeError:
print(mit.encode('utf-8', 'ignore'), file=kifile_pass)
with open('emails.txt', 'a') as kifile_email:
if mit.find(':') != -1:
mit_email = mit.split(':')[0]
else:
if mit.find(';') != -1:
mit_email = mit.split(';')[0]
try:
print(mit_email, file=kifile_email)
except UnicodeEncodeError:
print(mit.encode('utf-8', 'ignore'), file=kifile_email)
with open('emails_and_passes.txt', 'a') as kifile_all:
try:
print(mit, file=kifile_all)
except UnicodeEncodeError:
print(mit.encode('utf-8', 'ignore'), file=kifile_all)
def kiir(mit, hogyan):
if hogyan == 't':
kiir_terminal(mit)
elif hogyan == 'f':
kiir_file(mit)
elif hogyan == 'b':
kiir_terminal(mit)
kiir_file(mit)
# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
lang = getlang()
alphnum = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
if lang == '1':
args = getargs_en()
elif lang == '2':
args = getargs_hu()
if args.mode == 'e': # if we are searching for an email
if args.find[0] == '@': # if we looking for an email and we start with @
alphnum.append('symbols')
for mappa in alphnum:
for fajl in alphnum:
if mappa == 'symbols':
openstring = args.path + '/' + mappa
else:
openstring = args.path + '/' + mappa + '/' + fajl
try:
with open(openstring, 'rb') as befile:
for sor in befile:
sor = sor.decode('utf-8', 'ignore').strip()
if sor.find(args.find) != -1:
kiir(sor, args.output)
except PermissionError:
for alfajl in alphnum:
openstring = args.path + '/' + mappa + '/' + fajl + '/' + alfajl
try:
with open(openstring, 'rb') as befile:
for sor in befile:
sor = sor.decode('utf-8', 'ignore').strip()
if sor.find(args.find) != -1:
kiir(sor, args.output)
except PermissionError:
continue
if mappa == 'symbols':
break
# if we looking for an email, but we dont start with an @
else:
if args.find[0].lower() in alphnum: # if the thing we are looking for doesnt start with a symbol
if args.find[1].lower() not in alphnum:
vege = 'symbols'
else:
vege = args.find[1]
try:
with open(args.path + '/' + args.find[0] + '/' + vege, 'rb') as befile:
for sor in befile:
sor = sor.decode('utf-8', 'ignore')
sor = sor.strip()
if sor.find(':') == -1:
sor_keres = sor.split(':')[0]
else:
if sor.find(';') == -1:
sor_keres = sor.split(';')[0]
else:
sor_keres = sor
if sor_keres.find(args.find) != -1:
kiir(sor, args.output)
except PermissionError:
if args.find[0].lower() in alphnum: # if the thing we are looking for doesnt start with a symbol
if args.find[2].lower() not in alphnum:
vege = args.find[1] + '/' + 'symbols'
else:
vege = args.find[1] + '/' + args.find[2]
with open(args.path + '/' + args.find[0] + '/' + vege, 'rb') as befile:
for sor in befile:
sor = sor.decode('utf-8', 'ignore')
sor = sor.strip()
if sor.find(':') == -1:
sor_keres = sor.split(':')[0]
else:
if sor.find(';') == -1:
sor_keres = sor.split(';')[0]
else:
sor_keres = sor
if sor_keres.find(args.find) != -1:
kiir(sor, args.output)
else:
# if the thing we are looking for starts with a symbol
with open(args.path + '/' + 'symbols', 'rb') as befile:
for sor in befile:
sor = sor.decode('utf-8').strip()
if sor.find(args.find) != -1:
kiir(sor, args.output)
elif args.mode == 'p': # if we are searching for a password
for mappa in alphnum:
for fajl in alphnum:
if mappa == 'symbols':
openstring = args.path + '/' + mappa
else:
openstring = args.path + '/' + mappa + '/' + fajl
try:
with open(openstring, 'rb') as befile:
for sor in befile:
sor_atal = sor.decode('utf-8', 'ignore').strip()
if sor_atal.find(':') == -1:
sor_l = sor_atal.split(':')
else:
if sor_atal.find(';') == -1:
sor_l = sor_atal.split(';')
else:
sor_l = sor_atal
if len(sor_l) > 2:
passwd = ''
for i in (range(len(sor_l)-1)):
passwd += sor_l[i + 1]
else:
if len(sor_l) > 1:
passwd = sor_l[1]
else:
passwd = sor_l
if passwd == args.find:
kiir(sor_atal, args.output)
elif sor_atal.find(args.find) != -1:
kiir(sor_atal, args.output)
except PermissionError:
for alfajl in alphnum:
openstring = args.path + '/' + mappa + '/' + fajl + '/' + alfajl
try:
with open(openstring, 'rb') as befile:
for sor in befile:
sor_atal = sor.decode('utf-8', 'ignore').strip()
if sor_atal.find(':') == -1:
sor_l = sor_atal.split(':')
else:
if sor_atal.find(';') == -1:
sor_l = sor_atal.split(';')
else:
sor_l = sor_atal
if len(sor_l) > 2:
passwd = ''
for i in (range(len(sor_l)-1)):
passwd += sor_l[i + 1]
else:
if len(sor_l) > 1:
passwd = sor_l[1]
else:
passwd = sor_l
if passwd == args.find:
kiir(sor_atal, args.output)
elif sor_atal.find(args.find) != -1:
kiir(sor_atal, args.output)
except PermissionError:
continue
if mappa == 'symbols':
break