-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
609 lines (440 loc) · 25 KB
/
main.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter import messagebox as mb
from tkinter import filedialog as fd
from tkinter.scrolledtext import ScrolledText
import json
import webbrowser
import helpers
import os
'''
LookupMaster
OSINT tool for looking up names, usernames, phone numbers, e-mails, and more with a simple and user-friendly GUI.
'''
class MenuTab:
def __init__(self, root, module_name=None):
self.main_frame = root
self.module_data = None
self.module_name = module_name
self.refresh_module_data()
def refresh_module_data(self):
self.module_data = self.load_module_file()
def load_module_file(self) -> dict[str, dict[str, str]]:
# This is currently for the module editor tab but may be used in the future. Wish to remove the os dependency
if self.module_name is None:
return_dict = {}
for root, dirs, files in os.walk('modules'):
for filename in files:
file_path = os.path.join(root, filename)
with open(file_path) as f:
# split at the . and lower() to get just a plain filename
return_dict[filename.split('.')[0].lower()] = json.loads(f.read())
# Remove mutator dict -- it isn't formatted like the others and can't be viewed yet with module editor
return_dict.pop('mutator')
# print(return_dict)
return return_dict
with open(f'modules/{self.module_name}.json') as f:
return json.loads(f.read())
# def __del__(self):
# # Untested but this should delete all widgets in the root frame to prevent memory leaks if the object is deleted
# for widget in self.main_frame.winfo_children():
# widget.destroy()
class ModuleEditorTab(MenuTab):
def __init__(self, root):
super().__init__(root)
self.main_frame.grid_columnconfigure(2, weight=2)
self.main_listbox_var = tk.StringVar()
# CDCDCD is color code for windows scrollbar color
self.main_listbox = tk.Listbox(self.main_frame, height=16, width=67,
selectbackground='#CDCDCD', selectforeground='black', exportselection=False)
self.main_listbox.grid(sticky='nsw', columnspan=4)
self.main_listbox_scrollbar = ttk.Scrollbar(self.main_frame, orient=tk.VERTICAL,
command=self.main_listbox.yview)
self.main_listbox_scrollbar.grid(column=3, row=0, sticky='nse')
self.main_listbox['yscrollcommand'] = self.main_listbox_scrollbar.set
self.main_listbox.bind('<<ListboxSelect>>', lambda x: [self.listbox_item_selected()])
ttk.Label(self.main_frame, text='Title: ', justify='right').grid(column=0, row=1)
ttk.Label(self.main_frame, text='URL: ', justify='right').grid(column=0, row=2)
ttk.Label(self.main_frame, text='Mask: ', justify='right').grid(column=0, row=3)
ttk.Label(self.main_frame, text='API Key: ', justify='right').grid(column=0, row=4)
ttk.Label(self.main_frame, text='Captcha: ', justify='right').grid(column=0, row=5)
self.module_title_var = tk.StringVar()
self.module_title_entry = ttk.Entry(self.main_frame, width=32, textvariable=self.module_title_var)
self.module_title_entry.grid(column=1, row=1, pady=5, padx=10, columnspan=3, sticky='we')
self.module_title_entry.bind('<Any-KeyRelease>', lambda x: [self.module_title_validation()])
self.url_var = tk.StringVar()
ttk.Entry(self.main_frame, width=32, textvariable=self.url_var).grid(column=1, row=2, pady=5, padx=10,
columnspan=3, sticky='we')
self.mask_var = tk.StringVar()
ttk.Entry(self.main_frame, width=32, textvariable=self.mask_var).grid(column=1, row=3, pady=5, padx=10,
columnspan=3, sticky='we')
self.api_key_var = tk.StringVar()
ttk.Entry(self.main_frame, width=32, textvariable=self.api_key_var).grid(column=1, row=4, pady=5, padx=10,
columnspan=3, sticky='we')
self.captcha_var = tk.StringVar()
ttk.Checkbutton(self.main_frame, variable=self.captcha_var, onvalue='True', offvalue='False').grid(
column=1, row=5, sticky='w', pady=2, padx=10)
ttk.Button(self.main_frame, text='Save Module', command=self.save_module_file).grid(column=2, row=5,
sticky='w')
self.add_module_button = ttk.Button(self.main_frame, text='Add New Module to File',
command=self.add_empty_module)
self.add_module_button.grid(column=2, row=5, sticky='e')
self.update_main_listbox()
def module_title_validation(self):
self.module_title_var.set(helpers.remove_all_whitespace(self.module_title_var.get()))
def add_empty_module(self):
template = {
"url": "",
"mask": "",
"api-key": "N/A",
"captcha": "False"
}
name = helpers.get_alternate_name('NewModule', self.module_data[self.get_current_item_category()])
self.module_data[self.get_current_item_category()][name] = template
self.update_main_listbox()
def update_main_listbox(self):
self.main_listbox.delete(0, END)
for k, v in self.module_data.items():
for title in v.keys():
self.main_listbox.insert(END, k + '.json | ' + title)
def verify_overwrite(self) -> bool:
return mb.askokcancel(title='Confirm Overwrite',
message='Doing this will overwrite current module file. Continue?',
icon='warning')
def save_module_file(self):
if self.verify_overwrite():
new_module = {
'url': self.url_var.get(),
'mask': self.mask_var.get(),
'api-key': self.api_key_var.get(),
'captcha': self.captcha_var.get()
}
del self.module_data[self.get_current_item_category()][self.get_current_item_title()]
self.module_data[self.get_current_item_category()][self.module_title_var.get()] = new_module
with open('modules/' + self.get_current_item_filename(), 'w') as f:
f.write(json.dumps(self.module_data[self.get_current_item_category()], indent=2))
# print(json.dumps(self.module_data, indent=2))
self.refresh_module_data()
self.update_main_listbox()
def set_current_selection_attribute(self, attr: str, value: str):
self.module_data[self.get_current_item_category()][self.get_current_item_title()][attr] = value
def listbox_item_selected(self):
item_values = self.get_current_item_values()
self.module_title_var.set(self.get_current_item_title())
self.url_var.set(item_values['url'])
self.mask_var.set(item_values['mask'])
self.api_key_var.set(item_values['api-key'])
self.captcha_var.set(item_values['captcha'])
def get_current_selection(self):
if not self.main_listbox.curselection():
return ''
else:
return self.main_listbox.get(self.main_listbox.curselection())
def get_current_item_filename(self):
return self.get_current_selection().split(' ')[0]
def get_current_item_category(self):
return self.get_current_selection().split('.', 1)[0].lower()
def get_current_item_title(self):
return self.get_current_selection().split(' ')[2]
def get_current_item_values(self):
return self.module_data[self.get_current_item_category()][self.get_current_item_title()]
class PermutationTab(MenuTab):
def __init__(self, root):
super().__init__(root, 'mutator')
self.main_frame.grid_columnconfigure(2, weight=2)
# First name entry
ttk.Label(self.main_frame, text='First Name:').grid(column=0, row=1, pady=2)
self.first_name_var = tk.StringVar()
self.first_name_entry = ttk.Entry(self.main_frame, textvariable=self.first_name_var)
self.first_name_entry.grid(column=1, row=1, sticky='we', columnspan=2)
# Middle name entry
ttk.Label(self.main_frame, text='Middle Name:').grid(column=0, row=2, pady=2)
self.middle_name_var = tk.StringVar()
self.middle_name_entry = ttk.Entry(self.main_frame, textvariable=self.middle_name_var)
self.middle_name_entry.grid(column=1, row=2, sticky='we', columnspan=2)
# Last name entry
ttk.Label(self.main_frame, text='Last Name:').grid(column=0, row=3, pady=2)
self.last_name_var = tk.StringVar()
self.last_name_entry = ttk.Entry(self.main_frame, textvariable=self.last_name_var)
self.last_name_entry.grid(column=1, row=3, sticky='we', columnspan=2)
ttk.Label(self.main_frame, text='Domain:').grid(column=0, row=4, pady=2)
self.domain_var = tk.StringVar()
self.domain_entry = ttk.Entry(self.main_frame, textvariable=self.domain_var)
self.domain_entry.grid(column=1, row=4, sticky='we', columnspan=2)
self.mode_var = tk.StringVar(value='email')
self.email_radiobutton = ttk.Radiobutton(self.main_frame, text='E-Mail', variable=self.mode_var, value='email')
self.email_radiobutton.grid(column=1, row=0, sticky='w')
self.extended_email_radiobutton = ttk.Radiobutton(self.main_frame, text='Extended E-Mail',
variable=self.mode_var, value='email-extended')
self.extended_email_radiobutton.grid(column=1, row=0, sticky='n', columnspan=2)
self.username_radiobutton = ttk.Radiobutton(self.main_frame, text='Username', variable=self.mode_var,
value='username')
self.username_radiobutton.grid(column=1, row=5, sticky='w')
ttk.Label(self.main_frame, text='Username:').grid(column=0, row=6, pady=2)
self.username_var = tk.StringVar()
self.username_entry = ttk.Entry(self.main_frame, textvariable=self.username_var)
self.username_entry.grid(column=1, row=6, sticky='we', columnspan=2)
ttk.Separator(self.main_frame, orient='horizontal').grid(sticky='we', pady=10, columnspan=3, row=7)
ttk.Label(self.main_frame, text='Numbers of Interest:\n'
'( - ) denotes range\n'
'e.g. "1-4" = 1, 2, 3, 4').grid(column=0, row=8, pady=2)
self.noi_textbox = ScrolledText(self.main_frame, height=10, width=32, font=('Helvetica', 10))
self.noi_textbox.grid(column=1, row=8)
# optional textbox entry for numbers of interest
# optional email domain entry
# checkboxes for allowed characters in permutation ( ., -, _ )
# box for numbers specifically to go onto end
# option to generate incremental numbers on end or as numbers of interest within specified range
ttk.Button(self.main_frame, text='Generate Permutations', command=self.create_results_popup).grid(
column=0, columnspan=3, pady=10, sticky='we')
self.first_name_var.set(value='John')
self.last_name_var.set(value='Smith')
self.domain_var.set(value='gmail.com')
def get_noi(self) -> list[str]:
# print(list(x for x in self.noi_textbox.get('1.0', END).strip().split('\n') if x != ''))
# generator for textbox to remove lines that are only whitespace and trailing spaces
return list(x for x in self.noi_textbox.get('1.0', END).strip().split('\n') if x != '')
def create_results_popup(self):
t = tk.Toplevel()
t.geometry('300x325')
t.title('Generated Permutations')
t.columnconfigure(0, weight=1)
t.resizable(False, False)
t.grid()
frame = ttk.Frame(t, borderwidth=5, relief='solid', padding=5)
frame.grid(sticky='nswe')
perms = self.generate_permutations()
ttk.Label(frame, text=f'{len(perms)} permutations').grid()
results_box = ScrolledText(frame, height=16, width=37, font=('Helvetica', 10))
results_box.grid()
for p in perms:
results_box.insert(END, p + '\n')
ttk.Button(frame, text='Save to File',
command=lambda: self.save_permutations_to_file(results_box.get('1.0', END))).grid(pady=5,
sticky='we')
def save_permutations_to_file(self, results: str):
file_types = (('Text files', '*.txt'),
('All files', '*.*'))
# Starts save as dialog
f = fd.asksaveasfile(mode='w', defaultextension='.txt', filetypes=file_types)
# Returns none if dialog is cancelled
if f is None:
return
# Write result data to the file
f.write(results.strip())
# Close file
f.close()
def generate_permutations(self):
if self.mode_var.get() == 'username':
return self.generate_username_permutations()
elif self.mode_var.get() == 'email' or self.mode_var.get() == 'email-extended':
return self.generate_email_permutations()
def generate_email_permutations(self) -> list[str]:
noi = helpers.interpret_noi(self.get_noi())
masks = self.module_data[self.mode_var.get()]
return helpers.generate_email_permutations(self.first_name_var.get(), self.middle_name_var.get(),
self.last_name_var.get(), self.domain_var.get(), noi, masks)
def generate_username_permutations(self) -> list[str]:
noi = helpers.interpret_noi(self.get_noi())
masks = self.module_data[self.mode_var.get()]
return helpers.generate_username_permutations(self.username_var.get(), noi, masks)
class PhoneLookupTab(MenuTab):
def __init__(self, root):
super().__init__(root, 'phone')
self.main_frame.grid_columnconfigure(1, weight=2)
self.phone_entry_label = ttk.Label(self.main_frame, text='Enter a Phone Number (0-9, A-Z)')
self.phone_entry_label.grid(pady=5, columnspan=2, sticky='n')
self.phone_var = tk.StringVar()
self.phone_entry = ttk.Entry(self.main_frame, textvariable=self.phone_var, width=18, justify=tk.CENTER,
font=('Helvetica', 12, 'bold'))
self.phone_entry.grid(pady=5, padx=10, columnspan=2, sticky='we')
# For best practice, this should eventually use a StringVar and refresh dynamically
self.phone_entry_msg = ttk.Label(self.main_frame, text='Phone number must be 10 characters.', foreground='red')
self.phone_entry_msg.grid(columnspan=2, sticky='n')
self.phone_entry.bind('<Any-KeyRelease>', lambda x: [self.phone_input_validation()])
self.buttons = {}
self.create_buttons()
def phone_input_validation(self):
self.phone_var.set(helpers.remove_special_characters(self.phone_var.get().strip()))
pi = self.get_sanitized_number()
while len(pi) > 10:
self.phone_entry.delete(10, END)
pi = self.get_sanitized_number()
if len(pi) != 10:
self.phone_entry_msg.config(text='Phone number must be 10 characters.', foreground='red')
else:
self.phone_entry_msg.config(text='Valid Number', foreground='green')
def get_sanitized_number(self):
return helpers.clean_phone_number(self.phone_var.get())
def refresh_buttons(self):
self.clear_buttons()
self.create_buttons()
def clear_buttons(self):
for button in self.buttons.values():
button.destroy()
self.buttons = {}
def create_buttons(self):
button_counter = 0
for n, d in self.module_data.items():
# print(n, d)
# Have to create an on-click function for the button to use.
def on_click(target=d):
# print('Button Clicked')
if not self.phone_entry_msg.cget('text') == 'Valid Number':
return
r = target['url'] + helpers.translate_phone_mask(target['mask'][0], target['mask'][1],
self.get_sanitized_number())
# Desired click operation goes here.
# TODO: implement webbrowser to open a chrome tab. alternatively, implement scraping. add some way to
# configure scraped information in modules.json, then then offer option to save data to file or
# open in a TopLevel with a textbox
print(r)
webbrowser.open_new(r)
# ugly one-liner but does what I want it to -- find better solution for dynamic button placement
column = 0 if button_counter < 10 else 1
button_counter += 1
# Have to add to grid after, otherwise .grid operation returns None
self.buttons[n.lower()] = ttk.Button(self.main_frame, text=n + '*' if d['captcha'] == 'True' else n,
command=on_click)
self.buttons[n.lower()].grid(sticky='ew', column=column, row=button_counter + 4, padx=10, pady=2)
# Adds CAPTCHA text next to button when applicable
# if d['captcha'] == 'True':
# ttk.Label(self.main_frame, text='CAPTCHA', foreground='red', font=('Helvetica', 12, 'bold')).grid(
# column=column + 1, sticky='nsew', row=button_counter + 3)
class EmailLookupTab(MenuTab):
def __init__(self, root):
super().__init__(root, 'email')
self.main_frame.grid_columnconfigure(1, weight=2)
self.email_entry_label = ttk.Label(self.main_frame, text='Enter an E-Mail Address ([email protected])')
self.email_entry_label.grid(pady=5, columnspan=2, sticky='n')
self.email_var = tk.StringVar()
self.email_entry = ttk.Entry(self.main_frame, textvariable=self.email_var, width=18, justify=tk.CENTER,
font=('Helvetica', 12, 'bold'))
self.email_entry.grid(pady=5, padx=10, columnspan=2, sticky='we')
# For best practice, this should eventually use a StringVar and refresh dynamically
self.email_entry_msg = ttk.Label(self.main_frame, text='Invalid E-Mail', foreground='red')
self.email_entry_msg.grid(columnspan=2, sticky='n')
self.email_entry.bind('<Any-KeyRelease>', lambda x: [self.email_input_validation()])
self.buttons = {}
self.create_buttons()
def email_input_validation(self):
self.email_var.set(self.email_var.get().strip())
if helpers.validate_email_format(self.email_var.get()):
self.email_entry_msg.config(text='Valid E-Mail', foreground='green')
else:
self.email_entry_msg.config(text='Invalid E-Mail', foreground='red')
def refresh_buttons(self):
self.clear_buttons()
self.create_buttons()
def clear_buttons(self):
for button in self.buttons.values():
button.destroy()
self.buttons = {}
def create_buttons(self):
button_counter = 0
for n, d in self.module_data.items():
# print(n, d)
# Have to create an on-click function for the button to use.
def on_click(target=d):
# print('Button Clicked')
if not self.email_entry_msg.cget('text') == 'Valid E-Mail':
return
# Desired click operation goes here.
# TODO: implement webbrowser to open a chrome tab. alternatively, implement scraping. add some way to
# configure scraped information in modules.json, then then offer option to save data to file or
# open in a TopLevel with a textbox
r = target['url'] + target['mask'].replace('X', self.email_var.get())
print(r)
webbrowser.open_new(r)
# ugly one-liner but does what I want it to -- find better solution for dynamic button placement
column = 0 if button_counter < 10 else 1
button_counter += 1
# Have to add to grid after, otherwise .grid operation returns None
self.buttons[n.lower()] = ttk.Button(self.main_frame, text=n + '*' if d['captcha'] == 'True' else n,
command=on_click)
self.buttons[n.lower()].grid(sticky='ew', column=column, row=button_counter + 4, padx=10, pady=2)
# Adds CAPTCHA text next to button when applicable
# if d['captcha'] == 'True':
# ttk.Label(self.main_frame, text='CAPTCHA', foreground='red', font=('Helvetica', 12, 'bold')).grid(
# column=column + 1, sticky='nsew', row=button_counter + 3)
class UsernameLookupTab(MenuTab):
def __init__(self, root):
super().__init__(root, 'username')
self.main_frame.grid_columnconfigure(1, weight=2)
self.username_entry_label = ttk.Label(self.main_frame, text='Enter a Username (A-Z, 0-9, -, _)')
self.username_entry_label.grid(pady=5, columnspan=2, sticky='n')
self.username_var = tk.StringVar()
self.username_entry = ttk.Entry(self.main_frame, textvariable=self.username_var, width=18, justify=tk.CENTER,
font=('Helvetica', 12, 'bold'))
self.username_entry.grid(pady=5, padx=10, columnspan=2, sticky='we')
# todo: check for non url-safe chars; validate_username method
self.username_entry.bind('<Any-KeyRelease>', lambda x: [])
self.buttons = {}
self.create_buttons()
def refresh_buttons(self):
self.clear_buttons()
self.create_buttons()
def clear_buttons(self):
for button in self.buttons.values():
button.destroy()
self.buttons = {}
def create_buttons(self):
self.clear_buttons()
button_counter = 0
for n, d in self.module_data.items():
# print(n, d)
# Have to create an on-click function for the button to use.
def on_click(target=d):
# print('Button Clicked')
# Desired click operation goes here.
# TODO: implement webbrowser to open a chrome tab. alternatively, implement scraping. add some way to
# configure scraped information in modules.json, then then offer option to save data to file or
# open in a TopLevel with a textbox
r = target['url'] + target['mask'].replace('X', self.username_var.get())
print(r)
webbrowser.open_new(r)
# TODO: find better solution for dynamic button placement
if button_counter > 20:
column = 2
elif button_counter > 10:
column = 1
else:
column = 0
button_counter += 1
# Have to add to grid after, otherwise .grid operation returns None
self.buttons[n.lower()] = ttk.Button(self.main_frame, text=n + '*' if d['captcha'] == 'True' else n,
command=on_click)
self.buttons[n.lower()].grid(sticky='ew', column=column, row=button_counter + 3, padx=10, pady=2)
class App:
def __init__(self, root):
self.window = root
self.window.title('Lookup Master')
self.window.geometry('380x450')
self.window.resizable(0, 0)
self.window.grid_columnconfigure(0, weight=1)
self.main_notebook = ttk.Notebook(self.window, padding=5)
self.main_notebook.grid(sticky='nswe')
#self.name_lookup_frame = ttk.Frame(self.main_notebook)
#self.main_notebook.add(self.name_lookup_frame, text='Name')
self.phone_lookup_frame = ttk.Frame(self.main_notebook)
self.main_notebook.add(self.phone_lookup_frame, text='Phone')
self.phone_lookup = PhoneLookupTab(self.phone_lookup_frame)
self.username_lookup_frame = ttk.Frame(self.main_notebook)
self.main_notebook.add(self.username_lookup_frame, text='Username')
self.username_lookup = UsernameLookupTab(self.username_lookup_frame)
self.email_frame = ttk.Frame(self.main_notebook)
self.main_notebook.add(self.email_frame, text='E-Mail')
self.email_lookup = EmailLookupTab(self.email_frame)
self.module_editor_frame = ttk.Frame(self.main_notebook)
self.main_notebook.add(self.module_editor_frame, text='Module Editor')
self.module_editor = ModuleEditorTab(self.module_editor_frame)
self.permutation_frame = ttk.Frame(self.main_notebook)
self.main_notebook.add(self.permutation_frame, text='Permutator')
self.permutator = PermutationTab(self.permutation_frame)
def main():
root = tk.Tk()
instance = App(root)
root.mainloop()
if __name__ == '__main__':
main()