-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpm_domain_discovery.py
More file actions
1397 lines (1228 loc) · 58 KB
/
Copy pathpm_domain_discovery.py
File metadata and controls
1397 lines (1228 loc) · 58 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
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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""pm_domain_discovery.py - Domain Discovery, Scraping & Loading Menus"""
import os
import sys
import time
from datetime import datetime
from pathlib import Path
from pm_config import load_config, save_config
from pm_ui_helpers import (
C, clear_screen, print_banner, print_section, print_menu_item,
print_success, print_error, print_warning, print_info,
get_input, confirm, animated_print,
)
# Try to import Kali module for enhanced features (used in show_scrape_results_menu)
try:
from kali.integration import is_enhanced_mode, kali_expand_domains
KALI_MODULE_AVAILABLE = True
except ImportError:
KALI_MODULE_AVAILABLE = False
def is_enhanced_mode(): return False
def kali_expand_domains(domains, **kwargs): return domains
# Try to import cyberpunk UI components
try:
from ui.cyberpunk_ui import (
cyber_header, cyber_info, cyber_success, cyber_warning,
cyber_error, cyber_prompt, cyber_confirm, get_console,
cyber_banner_discovery, cyber_banner_import,
)
CYBER_UI_AVAILABLE = True
except ImportError:
CYBER_UI_AVAILABLE = False
def run_domain_scrape(keywords, use_google, use_duckduckgo, max_results, existing_domains=None):
"""Run the actual domain scraping and return results"""
from discovery.scraper import DomainScraper
print_section("Scraping Domains", C.BRIGHT_MAGENTA)
print(f"{C.DIM}Safe mode enabled - 2-3 second delays between requests{C.RESET}\n")
scraper = DomainScraper(delay_range=(2, 4))
# If we have existing domains, add them to the scraper
if existing_domains:
scraper.domains = set(existing_domains)
def progress_callback(keyword, current, total):
print(f" {C.CYAN}[{current}/{total}]{C.RESET} Searching: \"{keyword}\"")
try:
domains = scraper.search_all(
keywords=keywords,
max_results_per_keyword=max_results,
use_google=use_google,
use_duckduckgo=use_duckduckgo,
progress_callback=progress_callback
)
except KeyboardInterrupt:
print_warning("\nScraping interrupted by user.")
domains = scraper.domains
# Show errors if any
if scraper.errors:
print()
print_warning("Search errors occurred:")
for error in scraper.errors[:5]: # Limit to first 5
print(f" {C.DIM}• {error}{C.RESET}")
if len(scraper.errors) > 5:
print(f" {C.DIM}• ... and {len(scraper.errors) - 5} more{C.RESET}")
return domains
def interactive_domain_removal(domains: set) -> set:
"""
Interactive UI for reviewing and removing domains.
Uses simple-term-menu for arrow key navigation with search.
Loops until user chooses to proceed.
Args:
domains: Set of domains to review
Returns:
Filtered set of domains (with removals applied)
"""
if not domains:
return domains
# Try to import simple-term-menu
try:
from simple_term_menu import TerminalMenu
except ImportError:
print_warning("simple-term-menu not installed, skipping interactive review")
print_info("Install with: pip install simple-term-menu")
return domains
# Try to import blacklist for permanent additions
try:
from core.blacklist import add_to_blacklist
blacklist_available = True
except ImportError:
blacklist_available = False
current_domains = set(domains) # Work with a copy
# Main review loop
while True:
sorted_domains = sorted(current_domains)
domain_count = len(sorted_domains)
# Show pre-review menu
print(f"\n{C.BRIGHT_CYAN}{'━' * 65}{C.RESET}")
print(f" {C.BRIGHT_WHITE}DOMAIN REVIEW{C.RESET} {C.DIM}// {domain_count} domains{C.RESET}")
print(f"{C.BRIGHT_CYAN}{'━' * 65}{C.RESET}")
# Warn about large lists
if domain_count > 500:
print(f"\n {C.BRIGHT_YELLOW}⚠ Large list ({domain_count} domains) - review may be slow{C.RESET}")
print(f"\n {C.BRIGHT_MAGENTA}[r]{C.RESET} Review & remove domains (↑/↓ navigate, TAB select, / search)")
print(f" {C.BRIGHT_MAGENTA}[d]{C.RESET} Done - proceed with {domain_count} domains")
print(f" {C.BRIGHT_MAGENTA}[q]{C.RESET} Cancel\n")
choice = get_input("Choice", "d")
if choice is None or choice.lower() == 'q':
print_info("Cancelled")
return current_domains
elif choice.lower() == 'd':
print_success(f"Proceeding with {domain_count} domains")
return current_domains
elif choice.lower() != 'r':
print_warning("Invalid choice. Proceeding with current domains.")
return current_domains
# Show interactive picker
print(f"\n{C.BRIGHT_MAGENTA}{'━' * 65}{C.RESET}")
print(f" {C.BRIGHT_WHITE}SELECT DOMAINS TO REMOVE{C.RESET}")
print(f"{C.BRIGHT_MAGENTA}{'━' * 65}{C.RESET}")
print(f" {C.BRIGHT_CYAN}↑/↓{C.RESET} Navigate {C.BRIGHT_CYAN}TAB{C.RESET} Toggle {C.BRIGHT_CYAN}/{C.RESET} Search {C.BRIGHT_CYAN}ESC{C.RESET} Exit search {C.BRIGHT_CYAN}ENTER{C.RESET} Confirm")
print(f"{C.DIM}{'─' * 65}{C.RESET}\n")
try:
menu = TerminalMenu(
sorted_domains,
title=f" [{domain_count} domains] - TAB to select, ENTER when done",
multi_select=True,
show_multi_select_hint=True,
multi_select_select_on_accept=False,
multi_select_empty_ok=True,
# Cyberpunk styling
menu_cursor="▸ ",
menu_cursor_style=("fg_purple", "bold"),
menu_highlight_style=("fg_cyan", "bold"),
search_key="/",
search_highlight_style=("fg_yellow", "bold"),
cycle_cursor=True,
clear_screen=False,
)
selected_indices = menu.show()
except Exception as e:
print_warning(f"Interactive menu failed: {e}")
continue # Go back to review menu
# Handle no selection
if not selected_indices:
print_info("No domains selected")
continue # Loop back to review menu
# Convert indices to domain names
to_remove = {sorted_domains[i] for i in selected_indices}
# Confirmation
print(f"\n{C.BRIGHT_YELLOW}{'═' * 65}{C.RESET}")
print(f" {C.BRIGHT_WHITE}CONFIRM REMOVAL{C.RESET} - {len(to_remove)} domain(s) selected")
print(f"{C.DIM}{'─' * 65}{C.RESET}")
for d in sorted(to_remove)[:15]:
print(f" {C.BRIGHT_RED}✗{C.RESET} {d}")
if len(to_remove) > 15:
print(f" {C.DIM}... and {len(to_remove) - 15} more{C.RESET}")
print(f"{C.BRIGHT_YELLOW}{'═' * 65}{C.RESET}")
print(f"\n {C.BRIGHT_CYAN}[1]{C.RESET} Remove (this session only)")
if blacklist_available:
print(f" {C.BRIGHT_CYAN}[2]{C.RESET} Remove + add to permanent blacklist")
print(f" {C.BRIGHT_CYAN}[3]{C.RESET} Cancel - go back\n")
confirm_choice = get_input("Choice", "1")
if confirm_choice == '1':
current_domains = current_domains - to_remove
print_success(f"Removed {len(to_remove)} domains ({len(current_domains)} remaining)")
# Loop continues - user can review more or choose [d] to proceed
elif confirm_choice == '2' and blacklist_available:
for d in to_remove:
add_to_blacklist(d, persistent=True)
current_domains = current_domains - to_remove
print_success(f"Removed {len(to_remove)} domains + added to permanent blacklist ({len(current_domains)} remaining)")
# Loop continues
else:
print_info("Cancelled - no changes made")
# Loop continues
def _run_delete_domain_lists():
"""Main menu entry point for Delete/Modify domain lists."""
puppetmaster_dir = Path(__file__).parent
domain_lists_dir = puppetmaster_dir / "domain_lists"
available_lists = []
if domain_lists_dir.exists():
for txt_file in sorted(domain_lists_dir.glob("*.txt"), key=lambda x: x.stat().st_mtime, reverse=True):
try:
with open(txt_file, 'r') as f:
domain_count = sum(1 for line in f if line.strip() and not line.strip().startswith('#'))
mod_time = datetime.fromtimestamp(txt_file.stat().st_mtime).strftime('%Y-%m-%d %H:%M')
available_lists.append({
'path': txt_file,
'name': txt_file.name,
'domains': domain_count,
'modified': mod_time
})
except Exception:
pass
_delete_modify_domain_lists(domain_lists_dir, available_lists)
def _delete_modify_domain_lists(domain_lists_dir, available_lists):
"""Submenu for deleting/managing domain list files."""
clear_screen()
if CYBER_UI_AVAILABLE:
console = get_console()
cyber_header("DELETE / MODIFY DOMAIN LISTS")
else:
print_section("Delete / Modify Domain Lists", C.BRIGHT_RED)
if not available_lists:
if CYBER_UI_AVAILABLE:
cyber_info("No domain list files found.")
cyber_prompt("Press Enter to return...")
else:
print_info("No domain list files found.")
get_input("\nPress Enter to return...")
return
if CYBER_UI_AVAILABLE:
console.print(f"[dim]Directory: {domain_lists_dir}[/]")
console.print(f"[dim]{len(available_lists)} file(s) found[/]\n")
console.print(f" [bold yellow]\\[1][/] Select which files to delete")
console.print(f" [bold red]\\[2][/] Delete ALL domain list files")
console.print(f" [bold cyan]\\[B][/] Back\n")
choice = cyber_prompt("Choice", "b")
else:
print(f"{C.DIM}Directory: {domain_lists_dir}{C.RESET}")
print(f"{C.DIM}{len(available_lists)} file(s) found{C.RESET}\n")
print(f" {C.BRIGHT_YELLOW}[1]{C.RESET} Select which files to delete")
print(f" {C.BRIGHT_RED}[2]{C.RESET} Delete ALL domain list files")
print(f" {C.BRIGHT_CYAN}[B]{C.RESET} Back\n")
choice = get_input("Choice", "b")
if not choice or choice.lower() == 'b':
return
elif choice == '1':
_select_and_delete_domain_files(domain_lists_dir, available_lists)
elif choice == '2':
_delete_all_domain_files(domain_lists_dir, available_lists)
def _select_and_delete_domain_files(domain_lists_dir, available_lists):
"""Show numbered list of domain files and let user select which to delete."""
clear_screen()
if CYBER_UI_AVAILABLE:
console = get_console()
cyber_header("SELECT FILES TO DELETE")
console.print()
for i, lst in enumerate(available_lists, 1):
console.print(f" [bold yellow]\\[{i}][/] {lst['name']}")
console.print(f" [dim]{lst['domains']} domains • {lst['modified']}[/]")
console.print()
cyber_info("Enter file numbers separated by commas (e.g. 1,3,5) or 'all'")
selection = cyber_prompt("Files to delete")
else:
print_section("Select Files to Delete", C.BRIGHT_RED)
print()
for i, lst in enumerate(available_lists, 1):
print(f" {C.BRIGHT_YELLOW}[{i}]{C.RESET} {lst['name']}")
print(f" {C.DIM}{lst['domains']} domains • {lst['modified']}{C.RESET}")
print()
print_info("Enter file numbers separated by commas (e.g. 1,3,5) or 'all'")
selection = get_input("Files to delete")
if not selection or selection.strip().lower() == 'b':
return
# Parse selection
if selection.strip().lower() == 'all':
selected = list(available_lists)
else:
selected = []
for part in selection.split(','):
part = part.strip()
if not part:
continue
if not part.isdigit():
if CYBER_UI_AVAILABLE:
cyber_warning(f"Skipping invalid input: '{part}'")
else:
print_warning(f"Skipping invalid input: '{part}'")
continue
idx = int(part) - 1
if 0 <= idx < len(available_lists):
if available_lists[idx] not in selected:
selected.append(available_lists[idx])
else:
if CYBER_UI_AVAILABLE:
cyber_warning(f"Skipping invalid number: {part} (valid range: 1-{len(available_lists)})")
else:
print_warning(f"Skipping invalid number: {part} (valid range: 1-{len(available_lists)})")
if not selected:
if CYBER_UI_AVAILABLE:
cyber_info("No valid files selected.")
cyber_prompt("Press Enter to return...")
else:
print_info("No valid files selected.")
get_input("\nPress Enter to return...")
return
# Show confirmation
if CYBER_UI_AVAILABLE:
console = get_console()
console.print(f"\n[bold red]The following {len(selected)} file(s) will be permanently deleted:[/]\n")
for lst in selected:
console.print(f" [red]✗[/] {lst['name']} [dim]({lst['domains']} domains)[/]")
console.print()
confirmed = cyber_confirm(f"Delete {len(selected)} file(s)?", default=False)
else:
print(f"\n{C.BRIGHT_RED}The following {len(selected)} file(s) will be permanently deleted:{C.RESET}\n")
for lst in selected:
print(f" {C.BRIGHT_RED}✗{C.RESET} {lst['name']} {C.DIM}({lst['domains']} domains){C.RESET}")
print()
confirmed = confirm(f"Delete {len(selected)} file(s)?", default=False)
if not confirmed:
if CYBER_UI_AVAILABLE:
cyber_info("Cancelled - no files deleted.")
else:
print_info("Cancelled - no files deleted.")
return
# Delete files
deleted = 0
errors = 0
for lst in selected:
try:
Path(lst['path']).unlink()
deleted += 1
except Exception as e:
errors += 1
if CYBER_UI_AVAILABLE:
cyber_error(f"Failed to delete {lst['name']}: {e}")
else:
print_error(f"Failed to delete {lst['name']}: {e}")
if deleted > 0:
if CYBER_UI_AVAILABLE:
cyber_success(f"Deleted {deleted} file(s)")
else:
print_success(f"Deleted {deleted} file(s)")
if errors > 0:
if CYBER_UI_AVAILABLE:
cyber_warning(f"{errors} file(s) could not be deleted")
else:
print_warning(f"{errors} file(s) could not be deleted")
if CYBER_UI_AVAILABLE:
cyber_prompt("Press Enter to return...")
else:
get_input("\nPress Enter to return...")
def _delete_all_domain_files(domain_lists_dir, available_lists):
"""Delete all domain list files after confirmation."""
clear_screen()
if CYBER_UI_AVAILABLE:
console = get_console()
cyber_header("DELETE ALL DOMAIN LIST FILES")
console.print(f"\n[bold red]The following {len(available_lists)} file(s) will be permanently deleted:[/]\n")
for lst in available_lists:
console.print(f" [red]✗[/] {lst['name']} [dim]({lst['domains']} domains)[/]")
console.print()
confirmed = cyber_confirm(f"Delete ALL {len(available_lists)} file(s)?", default=False)
else:
print_section("Delete ALL Domain List Files", C.BRIGHT_RED)
print(f"\n{C.BRIGHT_RED}The following {len(available_lists)} file(s) will be permanently deleted:{C.RESET}\n")
for lst in available_lists:
print(f" {C.BRIGHT_RED}✗{C.RESET} {lst['name']} {C.DIM}({lst['domains']} domains){C.RESET}")
print()
confirmed = confirm(f"Delete ALL {len(available_lists)} file(s)?", default=False)
if not confirmed:
if CYBER_UI_AVAILABLE:
cyber_info("Cancelled - no files deleted.")
else:
print_info("Cancelled - no files deleted.")
return
# Delete all files
deleted = 0
errors = 0
for lst in available_lists:
try:
Path(lst['path']).unlink()
deleted += 1
except Exception as e:
errors += 1
if CYBER_UI_AVAILABLE:
cyber_error(f"Failed to delete {lst['name']}: {e}")
else:
print_error(f"Failed to delete {lst['name']}: {e}")
if deleted > 0:
if CYBER_UI_AVAILABLE:
cyber_success(f"Deleted {deleted} of {len(available_lists)} file(s)")
else:
print_success(f"Deleted {deleted} of {len(available_lists)} file(s)")
if errors > 0:
if CYBER_UI_AVAILABLE:
cyber_warning(f"{errors} file(s) could not be deleted")
else:
print_warning(f"{errors} file(s) could not be deleted")
if CYBER_UI_AVAILABLE:
cyber_prompt("Press Enter to return...")
else:
get_input("\nPress Enter to return...")
def show_scrape_results_menu(domains, keywords, use_google, use_duckduckgo, max_results):
"""Show post-scrape menu with options to view, re-run, add more, etc."""
from discovery.scraper import DomainScraper
while True:
clear_screen()
# Use cyberpunk UI if available
if CYBER_UI_AVAILABLE:
console = get_console()
from rich.panel import Panel
from rich.text import Text
cyber_banner_discovery()
cyber_header("SCRAPE RESULTS")
# Show summary in panel
summary_text = Text()
summary_text.append("Current Working Set:\n", style="bold white")
summary_text.append(" Domains collected: ", style="dim")
summary_text.append(f"{len(domains)}\n", style="bold green")
summary_text.append(" Keywords used: ", style="dim")
summary_text.append(f"{len(keywords)}\n\n", style="white")
keywords_preview = ', '.join(keywords[:3]) + ('...' if len(keywords) > 3 else '')
summary_text.append(f"Last keywords: {keywords_preview}", style="dim italic")
console.print(Panel(summary_text, title="[bold green]⟨ RESULTS ⟩[/]", border_style="green"))
console.print()
console.print("[bold white]What would you like to do?[/]\n")
console.print(" [bold yellow]\\[1][/] View domains")
console.print(" [bold yellow]\\[2][/] Add more keywords (keep current domains)")
console.print(" [bold green]\\[A][/] Manually add domains")
console.print(" [bold yellow]\\[3][/] Re-run with same keywords")
console.print(" [bold yellow]\\[4][/] Start fresh (new keywords)")
console.print(" [bold yellow]\\[5][/] Save list to file")
console.print(" [bold magenta]\\[R][/] Review & remove domains")
if KALI_MODULE_AVAILABLE and is_enhanced_mode():
console.print(" [bold cyan]\\[K][/] Expand with Kali tools")
console.print(" [bold yellow]\\[6][/] Load into SpiderFoot scan queue")
console.print(" [bold yellow]\\[7][/] Back to main menu")
console.print()
else:
print_banner()
print_section("Scrape Results", C.BRIGHT_GREEN)
# Show summary
print(f"""
{C.WHITE}Current Working Set:{C.RESET}
Domains collected: {C.BRIGHT_GREEN}{len(domains)}{C.RESET}
Keywords used: {len(keywords)}
{C.DIM}Last keywords: {', '.join(keywords[:3])}{'...' if len(keywords) > 3 else ''}{C.RESET}
""")
print(f"{C.WHITE}What would you like to do?{C.RESET}\n")
print_menu_item("1", "View domains", f"{C.BRIGHT_RED}◆{C.RESET}")
print_menu_item("2", "Add more keywords (keep current domains)", f"{C.BRIGHT_RED}◆{C.RESET}")
print_menu_item("a", "Manually add domains", f"{C.BRIGHT_GREEN}◆{C.RESET}")
print_menu_item("3", "Re-run with same keywords", f"{C.BRIGHT_RED}◆{C.RESET}")
print_menu_item("4", "Start fresh (new keywords)", f"{C.BRIGHT_RED}◆{C.RESET}")
print_menu_item("5", "Save list to file", f"{C.BRIGHT_RED}◆{C.RESET}")
print_menu_item("r", "Review & remove domains", f"{C.BRIGHT_MAGENTA}◆{C.RESET}")
# Show Kali option if available
if KALI_MODULE_AVAILABLE and is_enhanced_mode():
print_menu_item("k", "Expand with Kali tools", f"{C.BRIGHT_CYAN}◆{C.RESET}")
print_menu_item("6", "Load into SpiderFoot scan queue", f"{C.BRIGHT_RED}◆{C.RESET}")
print_menu_item("7", "Back to main menu", f"{C.BRIGHT_RED}◆{C.RESET}")
print()
choice = get_input("Choice", "6")
if choice is None:
choice = "7"
if choice == "1":
# View domains
clear_screen()
print_banner()
print_section(f"Domains Found ({len(domains)})", C.BRIGHT_CYAN)
sorted_domains = sorted(domains)
# Paginate if too many
page_size = 30
total_pages = (len(sorted_domains) + page_size - 1) // page_size
page = 0
while True:
start = page * page_size
end = min(start + page_size, len(sorted_domains))
print(f"\n{C.DIM}Showing {start + 1}-{end} of {len(sorted_domains)}{C.RESET}\n")
for i, domain in enumerate(sorted_domains[start:end], start + 1):
print(f" {C.DIM}{i:4d}.{C.RESET} {domain}")
print()
if total_pages > 1:
print(f"{C.DIM}[n] Next page [p] Previous page [q] Back{C.RESET}")
nav = get_input("", "q")
if nav == 'n' and page < total_pages - 1:
page += 1
elif nav == 'p' and page > 0:
page -= 1
elif nav == 'q' or nav is None:
break
else:
get_input("Press Enter to go back...")
break
elif choice == "2":
# Add more keywords
clear_screen()
print_banner()
print_section("Add More Keywords", C.BRIGHT_CYAN)
print(f"""
{C.WHITE}Current domains:{C.RESET} {len(domains)}
{C.DIM}New domains will be added to your existing set.{C.RESET}
{C.WHITE}Enter additional keywords:{C.RESET}
{C.DIM}Separate multiple keywords with commas.{C.RESET}
""")
new_keywords_input = get_input("Keywords")
if new_keywords_input and new_keywords_input.strip():
new_keywords = [k.strip() for k in new_keywords_input.split(',') if k.strip()]
if new_keywords:
print(f"\n{C.GREEN}✓{C.RESET} {len(new_keywords)} new keyword(s)\n")
new_domains = run_domain_scrape(
new_keywords, use_google, use_duckduckgo, max_results,
existing_domains=domains
)
added = len(new_domains) - len(domains)
domains = new_domains
keywords = keywords + new_keywords
print(f"\n{C.GREEN}✓{C.RESET} Added {added} new unique domains")
print(f" Total domains: {len(domains)}")
get_input("\nPress Enter to continue...")
elif choice == "3":
# Re-run with same keywords
print(f"\n{C.CYAN}Re-running with {len(keywords)} keywords...{C.RESET}\n")
domains = run_domain_scrape(
keywords, use_google, use_duckduckgo, max_results
)
print(f"\n{C.GREEN}✓{C.RESET} Found {len(domains)} unique domains")
get_input("\nPress Enter to continue...")
elif choice == "4":
# Start fresh
if confirm("Clear current domains and start with new keywords?"):
return None # Signal to restart the whole flow
elif choice.lower() == "a":
# Manually add domains
clear_screen()
print_banner()
print_section("Manually Add Domains", C.BRIGHT_GREEN)
print(f"""
{C.WHITE}Enter domains to add to your list.{C.RESET}
{C.DIM}Single domain or comma-separated. URLs auto-cleaned (http:// stripped).{C.RESET}
{C.DIM}Examples:{C.RESET}
example.com
example.com, another.com, third.com
https://example.com/page {C.DIM}→ becomes: example.com{C.RESET}
""")
domain_input = get_input("Domains")
if domain_input and domain_input.strip():
# Parse comma-separated domains
new_domains = []
for d in domain_input.split(','):
d = d.strip().lower()
# Basic cleanup - remove protocols
if d.startswith('http://'):
d = d[7:]
elif d.startswith('https://'):
d = d[8:]
d = d.split('/')[0].strip()
import re as _re
if (d and '.' in d and len(d) <= 253
and _re.match(r'^[a-z0-9][a-z0-9.\-]*[a-z0-9]$', d)):
new_domains.append(d)
if new_domains:
before_count = len(domains)
domains = domains | set(new_domains)
added = len(domains) - before_count
print(f"\n{C.GREEN}✓{C.RESET} Added {added} new domain(s)")
print(f" Total domains: {len(domains)}")
else:
print_warning("No valid domains entered")
get_input("\nPress Enter to continue...")
elif choice == "5":
# Save to file - with domain_lists directory
from discovery.scraper import DomainScraper
scraper = DomainScraper()
# Determine domain_lists directory (relative to puppetmaster)
puppetmaster_dir = Path(__file__).parent
domain_lists_dir = puppetmaster_dir / "domain_lists"
print(f"""
{C.WHITE}Save Domain List{C.RESET}
{C.DIM}Lists are saved to: {domain_lists_dir}{C.RESET}
{C.BRIGHT_YELLOW}[1]{C.RESET} Auto-name with timestamp
{C.BRIGHT_YELLOW}[2]{C.RESET} Enter custom name
{C.BRIGHT_YELLOW}[3]{C.RESET} Save to custom path
""")
save_choice = get_input("Choice", "1")
if save_choice == "1":
# Auto timestamp name
filename = f"domains_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
save_path = domain_lists_dir / filename
elif save_choice == "2":
# Custom name
custom_name = get_input("Enter list name (without .txt)")
if custom_name and custom_name.strip():
# Sanitize filename
safe_name = "".join(c for c in custom_name.strip() if c.isalnum() or c in '-_').strip()
if safe_name:
save_path = domain_lists_dir / f"{safe_name}.txt"
else:
print_warning("Invalid name, using timestamp")
filename = f"domains_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
save_path = domain_lists_dir / filename
else:
filename = f"domains_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
save_path = domain_lists_dir / filename
elif save_choice == "3":
# Custom path
default_filename = f"domains_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
user_path = get_input("File path", default_filename)
if user_path:
save_path = Path(os.path.expanduser(user_path))
else:
save_path = domain_lists_dir / default_filename
else:
filename = f"domains_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
save_path = domain_lists_dir / filename
# Ensure directory exists
save_path.parent.mkdir(parents=True, exist_ok=True)
if scraper.save_to_file(str(save_path), domains):
print_success(f"Saved {len(domains)} domains to: {save_path}")
else:
print_error("Failed to save file.")
get_input("\nPress Enter to continue...")
elif choice == "6":
# Load into SpiderFoot queue
config = load_config()
existing_pending = set(config.get('pending_domains', []))
combined = existing_pending | domains
config['pending_domains'] = list(combined)
config['last_scrape_keywords'] = keywords
config['domains_ready_for_scan'] = True # Flag to show notification
config['domains_ready_count'] = len(combined)
save_config(config)
added = len(combined) - len(existing_pending)
print_success(f"Added {added} new domains to scan queue.")
print_info(f"Total in queue: {len(combined)}")
print()
print(f"{C.BRIGHT_GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{C.RESET}")
print(f"{C.BRIGHT_GREEN} Returning to main menu. Select option [3] to start scanning!{C.RESET}")
print(f"{C.BRIGHT_GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{C.RESET}")
time.sleep(1.5)
break # Return to main menu
elif choice.lower() == "r":
# Review & remove domains interactively
domains = interactive_domain_removal(domains)
elif choice.lower() == "k":
# Expand with Kali tools
if KALI_MODULE_AVAILABLE and is_enhanced_mode():
domains = kali_expand_domains(domains, print_func=print, get_input_func=get_input)
get_input("\nPress Enter to continue...")
else:
print_warning("Kali enhanced mode not available")
get_input("\nPress Enter to continue...")
elif choice == "7":
# Save state before exiting
config = load_config()
config['last_scrape_domains'] = list(domains)
config['last_scrape_keywords'] = keywords
save_config(config)
break
return domains
def scrape_domains_menu():
"""Menu for scraping domains via keywords"""
clear_screen()
# Use cyberpunk UI if available
if CYBER_UI_AVAILABLE:
cyber_banner_discovery()
else:
print_banner()
print_section("Scrape Domains via Keywords", C.BRIGHT_CYAN)
# Check dependencies
try:
from discovery.scraper import DomainScraper
except ImportError as e:
if CYBER_UI_AVAILABLE:
cyber_error(f"Discovery module not available: {e}")
cyber_info("Make sure you're running from the correct directory.")
cyber_prompt("Press Enter to return to main menu")
else:
print_error(f"Discovery module not available: {e}")
print_info("Make sure you're running from the correct directory.")
get_input("\nPress Enter to return to main menu...")
return
# Check if search libraries are available
deps = DomainScraper.check_dependencies()
if not deps['google'] and not deps['duckduckgo']:
if CYBER_UI_AVAILABLE:
cyber_error("No search libraries available!")
cyber_info("Install with: pip install googlesearch-python duckduckgo_search")
cyber_prompt("Press Enter to return to main menu")
else:
print_error("No search libraries available!")
print_info("Install with: pip install googlesearch-python duckduckgo_search")
get_input("\nPress Enter to return to main menu...")
return
# Check for previous session
config = load_config()
last_domains = config.get('last_scrape_domains', [])
last_keywords = config.get('last_scrape_keywords', [])
if last_domains:
if CYBER_UI_AVAILABLE:
console = get_console()
console.print(f"\n[bright_yellow]Previous session found:[/]")
console.print(f" [dim]Domains:[/] [bright_green]{len(last_domains)}[/]")
console.print(f" [dim]Keywords:[/] [bright_cyan]{', '.join(last_keywords[:3])}{'...' if len(last_keywords) > 3 else ''}[/]\n")
console.print(" [bright_yellow][1][/] Continue with previous results")
console.print(" [bright_yellow][2][/] Add new keywords (merge with existing)")
console.print(" [bright_red][3][/] Clear all & start fresh\n")
resume_choice = cyber_prompt("Choice", "1")
else:
print(f"""
{C.BRIGHT_YELLOW}Previous session found:{C.RESET}
Domains: {len(last_domains)}
Keywords: {', '.join(last_keywords[:3])}{'...' if len(last_keywords) > 3 else ''}
""")
print_menu_item("1", "Continue with previous results", "▶️")
print_menu_item("2", "Add new keywords (merge with existing)", "➕")
print_menu_item("3", "Clear all & start fresh", "🆕")
print()
resume_choice = get_input("Choice", "1")
if resume_choice == "1":
# Resume previous session
use_google = deps['google']
use_duckduckgo = deps['duckduckgo']
max_results = 50
result = show_scrape_results_menu(
set(last_domains), last_keywords,
use_google, use_duckduckgo, max_results
)
if result is not None:
return
elif resume_choice == "2":
# Add new keywords but merge with existing domains
use_google = deps['google']
use_duckduckgo = deps['duckduckgo']
max_results = 50
existing_domains = set(last_domains)
clear_screen()
if CYBER_UI_AVAILABLE:
cyber_banner_discovery()
console = get_console()
console.print(f"\n[bright_green]Keeping {len(existing_domains)} existing domains[/]")
console.print("[white]Enter additional keywords to search for more domains.[/]")
console.print("[dim]Separate multiple keywords with commas.[/]\n")
else:
print_banner()
print_section("Add More Keywords", C.BRIGHT_CYAN)
print(f"\n{C.GREEN}Keeping {len(existing_domains)} existing domains{C.RESET}")
print(f"\n{C.WHITE}Enter additional keywords to search for more domains.{C.RESET}")
print(f"{C.DIM}Separate multiple keywords with commas.{C.RESET}\n")
if CYBER_UI_AVAILABLE:
keywords_input = cyber_prompt("Keywords")
else:
keywords_input = get_input("Keywords")
if keywords_input and keywords_input.strip():
new_keywords = [k.strip() for k in keywords_input.split(',') if k.strip()]
if new_keywords:
new_domains = run_domain_scrape(
new_keywords, use_google, use_duckduckgo, max_results,
existing_domains=existing_domains
)
# Merge keywords
all_keywords = last_keywords + [k for k in new_keywords if k not in last_keywords]
added = len(new_domains) - len(existing_domains)
print(f"\n{C.GREEN}✓{C.RESET} Added {added} new unique domains")
print(f" Total domains: {len(new_domains)}")
get_input("\nPress Enter to continue...")
# Go to results menu with merged data
result = show_scrape_results_menu(
new_domains, all_keywords,
use_google, use_duckduckgo, max_results
)
if result is not None:
return
return
# resume_choice == "3" or anything else: clear and start fresh
clear_screen()
if CYBER_UI_AVAILABLE:
cyber_banner_discovery()
else:
print_banner()
print_section("Scrape Domains via Keywords", C.BRIGHT_CYAN)
if CYBER_UI_AVAILABLE:
console = get_console()
console.print("\n[white]Enter keywords to search for domains.[/]")
console.print("[dim]Separate multiple keywords with commas.[/]\n")
console.print("[dim]Examples:[/]")
console.print(" [bright_cyan]•[/] electrical contractors NYC, electrical services New York")
console.print(" [bright_cyan]•[/] plastic surgery clinic, cosmetic surgeon")
console.print(" [bright_cyan]•[/] online tutoring, math help\n")
else:
print(f"""
{C.WHITE}Enter keywords to search for domains.{C.RESET}
{C.DIM}Separate multiple keywords with commas.{C.RESET}
{C.DIM}Examples:{C.RESET}
• electrical contractors NYC, electrical services New York
• plastic surgery clinic, cosmetic surgeon
• online tutoring, math help
""")
# Get keywords
if CYBER_UI_AVAILABLE:
keywords_input = cyber_prompt("Keywords")
else:
keywords_input = get_input("Keywords")
if keywords_input is None or not keywords_input.strip():
if CYBER_UI_AVAILABLE:
cyber_info("Cancelled.")
cyber_prompt("Press Enter to return to main menu")
else:
print_info("Cancelled.")
get_input("\nPress Enter to return to main menu...")
return
keywords = [k.strip() for k in keywords_input.split(',') if k.strip()]
if not keywords:
if CYBER_UI_AVAILABLE:
cyber_error("No valid keywords provided.")
cyber_prompt("Press Enter to return to main menu")
else:
print_error("No valid keywords provided.")
get_input("\nPress Enter to return to main menu...")
return
if CYBER_UI_AVAILABLE:
cyber_success(f"{len(keywords)} keyword(s) entered")
console = get_console()
console.print("\n[white]Search engine:[/]")
if deps['google']:
console.print(" [bright_yellow][1][/] Google [dim](no API key, uses delays)[/]")
else:
console.print(" [dim][1] Google (not available)[/]")
if deps['duckduckgo']:
console.print(" [bright_yellow][2][/] DuckDuckGo [dim](no API key, reliable)[/]")
else:
console.print(" [dim][2] DuckDuckGo (not available)[/]")
if deps['google'] and deps['duckduckgo']:
console.print(" [bright_yellow][3][/] Both [dim](recommended)[/]")
console.print()
else:
print(f"\n{C.GREEN}✓{C.RESET} {len(keywords)} keyword(s) entered\n")
print(f"{C.WHITE}Search engine:{C.RESET}")
if deps['google']:
print_menu_item("1", "Google (no API key, uses delays to avoid blocking)", "")
else:
print(f" {C.DIM}[1] Google (not available - install googlesearch-python){C.RESET}")
if deps['duckduckgo']:
print_menu_item("2", "DuckDuckGo (no API key, more reliable)", "")
else:
print(f" {C.DIM}[2] DuckDuckGo (not available - install duckduckgo_search){C.RESET}")
if deps['google'] and deps['duckduckgo']:
print_menu_item("3", "Both (searches both, combines results)", "")
print()
# Default to what's available
default_engine = "3" if (deps['google'] and deps['duckduckgo']) else ("1" if deps['google'] else "2")
if CYBER_UI_AVAILABLE:
engine_choice = cyber_prompt("Choice", default_engine)
else:
engine_choice = get_input(f"Choice", default_engine)
if engine_choice is None:
if CYBER_UI_AVAILABLE:
cyber_info("Cancelled.")
cyber_prompt("Press Enter to return to main menu")
else:
print_info("Cancelled.")
get_input("\nPress Enter to return to main menu...")
return
use_google = engine_choice in ('1', '3') and deps['google']
use_duckduckgo = engine_choice in ('2', '3') and deps['duckduckgo']
if not use_google and not use_duckduckgo:
if CYBER_UI_AVAILABLE:
cyber_error("No search engine selected.")
cyber_prompt("Press Enter to return to main menu")
else:
print_error("No search engine selected.")
get_input("\nPress Enter to return to main menu...")
return
# Max results per keyword
if CYBER_UI_AVAILABLE:
max_results = cyber_prompt("Max results per keyword", "50")
else:
max_results = get_input("Max results per keyword", "50")
if max_results is None:
if CYBER_UI_AVAILABLE:
cyber_info("Cancelled.")
cyber_prompt("Press Enter to return to main menu")
else:
print_info("Cancelled.")
get_input("\nPress Enter to return to main menu...")
return
try:
max_results = int(max_results)
except ValueError:
max_results = 50
# Run the scraper
domains = run_domain_scrape(keywords, use_google, use_duckduckgo, max_results)