-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuppetmaster.py
More file actions
496 lines (448 loc) · 22.7 KB
/
Copy pathpuppetmaster.py
File metadata and controls
496 lines (448 loc) · 22.7 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
╔═══════════════════════════════════════════════════════════════════════════════╗
║ ║
║ ██████╗ ██╗ ██╗██████╗ ██████╗ ███████╗████████╗ ║
║ ██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝╚══██╔══╝ ║
║ ██████╔╝██║ ██║██████╔╝██████╔╝█████╗ ██║ ║
║ ██╔═══╝ ██║ ██║██╔═══╝ ██╔═══╝ ██╔══╝ ██║ ║
║ ██║ ╚██████╔╝██║ ██║ ███████╗ ██║ ║
║ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝ ╚═╝ ║
║ ║
║ ███╗ ███╗ █████╗ ███████╗████████╗███████╗██████╗ ║
║ ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗ ║
║ ██╔████╔██║███████║███████╗ ██║ █████╗ ██████╔╝ ║
║ ██║╚██╔╝██║██╔══██║╚════██║ ██║ ██╔══╝ ██╔══██╗ ║
║ ██║ ╚═╝ ██║██║ ██║███████║ ██║ ███████╗██║ ██║ ║
║ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ║
║ ║
║ SpiderFoot Sock Puppet Detector ║
║ "good morning coffee with a bacon egg and cheese" ║
║ ║
╚═══════════════════════════════════════════════════════════════════════════════╝
PUPPETMASTER - The orchestrator for SpiderFoot Sock Puppet Detection
This tool analyzes SpiderFoot scan exports to identify coordinated networks
of domains (sock puppets) that are likely controlled by the same entity.
Author: Built with Claude
License: MIT
"""
import os
import sys
import time
# Enable readline for arrow key support in input() prompts
try:
import readline # noqa: F401 - imported for side effects
except ImportError:
pass # readline not available on Windows
# =============================================================================
# KALI LINUX INTEGRATION
# =============================================================================
# Try to import Kali module for enhanced features
try:
from kali.integration import (
kali_startup_check,
is_enhanced_mode,
print_enhanced_menu,
handle_enhanced_menu_choice,
get_kali_status_line,
should_show_kali_menu,
kali_expand_domains,
)
KALI_MODULE_AVAILABLE = True
except ImportError:
KALI_MODULE_AVAILABLE = False
def is_enhanced_mode(): return False
def should_show_kali_menu(): return False
def get_kali_status_line(): return ""
def kali_expand_domains(domains, **kwargs): return domains
# =============================================================================
# CYBERPUNK HUD UI
# =============================================================================
# Try to import the new Cyberpunk HUD
try:
from ui.integration import run_cyberpunk_hud_menu, map_hud_key_to_choice
CYBERPUNK_HUD_AVAILABLE = True
_HUD_IMPORT_ERROR = None
except ImportError as e:
CYBERPUNK_HUD_AVAILABLE = False
_HUD_IMPORT_ERROR = str(e)
# Try to import cyberpunk UI components for submenus
try:
from ui.cyberpunk_ui import (
cyber_header, cyber_menu, cyber_info, cyber_success,
cyber_warning, cyber_error, cyber_prompt, cyber_confirm,
cyber_status, cyber_divider, cyber_table, CyberProgress, cyber_wait,
get_console,
# Themed banners for submenus
cyber_banner_discovery, cyber_banner_import, cyber_banner_spider,
cyber_banner_queue, cyber_banner_analysis, cyber_banner_wildcard,
cyber_banner_help, cyber_banner_config, cyber_banner_results,
cyber_banner_kali, cyber_banner_workflow
)
CYBER_UI_AVAILABLE = True
except ImportError:
CYBER_UI_AVAILABLE = False
# Toggle for Cyberpunk UI
USE_CYBERPUNK_HUD = True
# Backwards compatibility
GAMING_HUD_AVAILABLE = CYBERPUNK_HUD_AVAILABLE
USE_GAMING_HUD = USE_CYBERPUNK_HUD
# =============================================================================
# CONFIG FILE - Remember user's output directories
# =============================================================================
from pm_config import CONFIG_FILE, load_config, save_config, remember_output_dir, get_remembered_output_dirs
# =============================================================================
# COLOR CODES
# =============================================================================
from utils.colors import C
# =============================================================================
# EXTRACTED MODULES
# =============================================================================
from pm_background import (
is_background_scan_running, get_background_scan_stats, stop_background_thread,
)
from pm_paths import is_safe_path, sanitize_path, get_data_directory, get_output_directory
from pm_ui_helpers import (
clear_screen, print_banner, print_section, print_menu_item,
print_success, print_error, print_warning, print_info,
get_input, confirm,
)
from pm_environment import setup_environment, ensure_running_in_venv
from pm_infrastructure import launch_in_tmux, launch_glances
from pm_spiderfoot import (
launch_spiderfoot_gui, spiderfoot_control_center_menu, _kill_spiderfoot_menu,
)
from pm_help import (
show_help, show_help_overview, install_spiderfoot_interactive,
show_spiderfoot_install_guide, show_help_signals, show_help_outputs,
)
from pm_results import show_config, find_results_directories, view_previous_results
from pm_domain_discovery import (
run_domain_scrape, interactive_domain_removal,
scrape_domains_menu, show_scrape_results_menu, load_domains_menu,
_run_delete_domain_lists,
)
from pm_c2 import distributed_scanning_menu, _c2_start_distributed_scan
from pm_scan_monitoring import (
check_scan_status_menu, manage_domain_queue_menu,
)
from pm_analysis import run_analysis, run_wildcard_analyzer
# Web GUI launcher (Flask-backed; degrades gracefully if Flask not installed)
try:
from pm_web_launcher import launch_web_gui
_WEB_GUI_AVAILABLE = True
except ImportError:
_WEB_GUI_AVAILABLE = False
def launch_web_gui(*args, **kwargs):
raise ImportError("Flask not installed — pip install flask")
# =============================================================================
# MAIN MENU
# =============================================================================
def show_main_menu():
"""Display the main menu"""
clear_screen()
print_banner()
# Check if background scan is running
if is_background_scan_running():
stats = get_background_scan_stats()
progress = stats['completed'] + stats['failed']
current = stats.get('current_domain', 'unknown')
if len(current) > 30:
current = current[:27] + "..."
print(f"""
{C.BRIGHT_YELLOW}╔═══════════════════════════════════════════════════════════════════════════════╗
║ 🔄 SPIDERFOOT SCAN IN PROGRESS — {progress}/{stats['total']} complete ║
║ Currently scanning: {current:<30} Use [4] to view details ║
╚═══════════════════════════════════════════════════════════════════════════════╝{C.RESET}
""")
# Check if domains are ready for scanning
config = load_config()
if config.get('domains_ready_for_scan'):
domain_count = config.get('domains_ready_count', 0)
print(f"""
{C.BRIGHT_GREEN}╔═══════════════════════════════════════════════════════════════════════════════╗
║ ✓ {domain_count} DOMAINS LOADED — Proceed to option [3] to start SpiderFoot scans! ║
╚═══════════════════════════════════════════════════════════════════════════════╝{C.RESET}
""")
# Clear the flag after showing
config['domains_ready_for_scan'] = False
save_config(config)
# Show Kali mode banner if active
if KALI_MODULE_AVAILABLE and is_enhanced_mode():
kali_status = get_kali_status_line()
print(f"""
{C.BRIGHT_RED}╔═══════════════════════════════════════════════════════════════════════════════╗
║ 🐉 KALI LINUX ENHANCED MODE ACTIVE
║ {kali_status:<69} ║
║ Option [1] auto-expands domains with Kali tools after scraping! ║
╚═════════════════════════════════════════════════════════════════════════════════════════════╝{C.RESET}
""")
print(f"""
{C.WHITE}{C.BOLD}Welcome to PUPPETMASTER!{C.RESET}
{C.DIM}End-to-end sock puppet detection pipeline{C.RESET}
{C.WHITE}What does this tool do?{C.RESET}
{C.DIM}━━━━━━━━━━━━━━━━━━━━━━━{C.RESET}
Discovers, scans, and analyzes domains to expose "sock puppet" networks —
websites that {C.UNDERLINE}appear{C.RESET}{C.DIM} independent but are secretly controlled by the same operator.
{C.WHITE}The Pipeline:{C.RESET}
{C.DIM}━━━━━━━━━━━━━{C.RESET}
{C.BRIGHT_CYAN}1. Discover{C.RESET} Scrape search engines for domains you suspect are sock puppets
{C.BRIGHT_CYAN}2. Scan{C.RESET} Run SpiderFoot OSINT scans on scrapd list (batch or interactive GUI)
{C.BRIGHT_CYAN}3. Analyze{C.RESET} Analyze spiderfoot scans to detect if there are any sock puppet clusters
{C.WHITE}What We Find:{C.RESET}
{C.DIM}━━━━━━━━━━━━━{C.RESET}
{C.BRIGHT_RED}•{C.RESET} Same Google Analytics/AdSense IDs {C.DIM}← definitive proof{C.RESET}
{C.BRIGHT_YELLOW}•{C.RESET} Same WHOIS, nameservers, SSL certs {C.DIM}← strong evidence{C.RESET}
{C.BRIGHT_GREEN}One shared unique identifier = same operator.{C.RESET}
{C.WHITE}New here?{C.RESET} Press {C.BRIGHT_YELLOW}[8]{C.RESET} for the full guide.
{C.BRIGHT_YELLOW}Long scans?{C.RESET} Press {C.WHITE}[9]{C.RESET} to run in {C.WHITE}tmux{C.RESET} (survives SSH disconnects)
""")
print_section("Main Menu", C.BRIGHT_YELLOW)
# Discovery & Scanning Section
print(f" {C.BRIGHT_CYAN}DISCOVERY & SCANNING{C.RESET}")
print_menu_item("1", "Scrape domains via keywords", "🔍")
print_menu_item("2", "Load domains from file", "📂")
print_menu_item("D", "Delete/Modify domain lists", "🗑️")
print_menu_item("3", "SpiderFoot Control Center (scans, GUI, DB)", "🕷️")
print_menu_item("4", "Check scan queue status", "📋")
print()
# Analysis Section
print(f" {C.BRIGHT_GREEN}ANALYSIS{C.RESET}")
print_menu_item("5", "Run Puppet Analysis on SpiderFoot scans", "🎭")
print_menu_item("6", "View previous results", "📊")
print_menu_item("11", "Signal//Noise Wildcard DNS Analyzer", "📡")
print()
# Settings Section
print(f" {C.BRIGHT_MAGENTA}SETTINGS{C.RESET}")
print_menu_item("7", "Configuration", "⚙️")
print_menu_item("8", "Help & Documentation", "❓")
print_menu_item("9", "Launch in tmux (for long scans)", "🖥️")
print_menu_item("10", "System monitor (via Glances)", "📊")
print()
# Security Section
print(f" {C.BRIGHT_RED}SECURITY{C.RESET}")
print_menu_item("S", "Security Audit (rootkit detection)", "🛡️")
print()
# Web GUI Section
print(f" {C.BRIGHT_CYAN}WEB GUI{C.RESET}")
print_menu_item("W", "Launch Web GUI (browser interface)", "🌐")
print()
# Kali Enhanced Mode Section (only shown when Kali is detected)
if should_show_kali_menu():
print_enhanced_menu(print_func=print, colors=C)
print_menu_item("q", "Quit", "👋")
print()
# =============================================================================
# MAIN ENTRY POINT
# =============================================================================
def main():
"""Main entry point"""
# Parse command-line arguments for menu routing
# --start-menu c2 : Start directly in the C2 distributed scanning menu (used by tmux auto-launch)
start_menu = None
if '--start-menu' in sys.argv:
try:
idx = sys.argv.index('--start-menu')
if idx + 1 < len(sys.argv):
start_menu = sys.argv[idx + 1]
except (ValueError, IndexError):
pass
# Check if we should be running in an existing venv
ensure_running_in_venv()
# Initial setup
clear_screen()
print_banner()
# Check environment
if not setup_environment():
print_error("Environment setup failed. Please resolve the issues above and try again.")
sys.exit(1)
# Kali Linux detection and bootstrap
if KALI_MODULE_AVAILABLE:
print_section("OS Detection", C.BRIGHT_BLUE)
is_kali, os_info = kali_startup_check(print_func=print)
if is_kali:
print_success("Kali Linux enhanced mode enabled!")
time.sleep(1)
else:
print_info(f"Running on {os_info.os_name} - standard mode")
time.sleep(1)
time.sleep(1)
# Report UI mode
print_section("UI Mode", C.BRIGHT_MAGENTA)
if USE_CYBERPUNK_HUD and CYBERPUNK_HUD_AVAILABLE:
if sys.stdin.isatty():
print_success("Cyberpunk HUD enabled (TTY detected)")
else:
print_warning("Cyberpunk HUD disabled (no TTY - using classic menu)")
else:
if not CYBERPUNK_HUD_AVAILABLE:
print_info("Classic menu (Cyberpunk HUD not available - 'rich' not installed?)")
else:
print_info("Classic menu (Cyberpunk HUD disabled)")
time.sleep(1)
# Clear any buffered input from startup (prevents accidental quit)
try:
import termios
termios.tcflush(sys.stdin, termios.TCIFLUSH)
except Exception:
pass # Ignore on Windows or if stdin isn't a terminal
# Handle --start-menu argument (used by tmux auto-launch)
# This allows puppetmaster to resume in a specific menu after tmux session creation
if start_menu == "c2":
# Go directly to the "Start Distributed Scan" intensity selection screen
try:
from discovery.worker_config import DistributedConfigManager
config_manager = DistributedConfigManager()
_c2_start_distributed_scan(config_manager)
except Exception as e:
print_error(f"Failed to start distributed scan: {e}")
get_input("\nPress Enter to continue to main menu...")
# After scan starts (or fails), go to C2 menu so user can check progress
distributed_scanning_menu()
# After returning from C2 menu, continue to main menu loop
# Main menu loop
while True:
# Use Cyberpunk HUD if available and enabled
if USE_CYBERPUNK_HUD and CYBERPUNK_HUD_AVAILABLE:
try:
# Get scan mode function if Kali is available
get_scan_mode = None
if KALI_MODULE_AVAILABLE:
try:
from kali.integration import get_current_scan_mode
get_scan_mode = get_current_scan_mode
except ImportError:
pass
hud_key = run_cyberpunk_hud_menu(
load_config=load_config,
is_background_scan_running=is_background_scan_running,
get_background_scan_stats=get_background_scan_stats,
should_show_kali_menu=should_show_kali_menu,
is_enhanced_mode=is_enhanced_mode if KALI_MODULE_AVAILABLE else None,
get_kali_status_line=get_kali_status_line if KALI_MODULE_AVAILABLE else None,
get_scan_mode=get_scan_mode,
)
choice = map_hud_key_to_choice(hud_key)
except Exception as e:
# Fallback to classic menu on error - show WHY it failed
clear_screen()
print_banner()
print()
print_warning(f"Cyberpunk HUD unavailable: {e}")
print_info("Falling back to classic menu. Press Enter to continue...")
try:
input()
except (EOFError, KeyboardInterrupt):
pass
show_main_menu()
choice = get_input("Select an option")
if choice is None:
choice = 'q'
else:
choice = choice.lower()
else:
# Classic menu
show_main_menu()
choice = get_input("Select an option")
# Handle Ctrl+C at main menu = exit gracefully
if choice is None:
choice = 'q'
else:
choice = choice.lower()
# Discovery & Scanning
if choice == '1':
scrape_domains_menu()
elif choice == '2':
load_domains_menu()
elif choice == 'd':
_run_delete_domain_lists()
elif choice == '3':
spiderfoot_control_center_menu() # Unified SpiderFoot Control Center
elif choice == '4':
check_scan_status_menu()
# Analysis
elif choice == '5':
run_analysis()
elif choice == '6':
view_previous_results()
# Settings
elif choice == '7':
show_config()
elif choice == '8':
show_help()
elif choice == '9':
launch_in_tmux()
elif choice == '10':
launch_glances()
elif choice == '11':
run_wildcard_analyzer()
elif choice == '12':
manage_domain_queue_menu() # Domain queue manager
# Security Audit
elif choice == 's':
try:
from security import security_audit_menu
security_audit_menu()
except ImportError as e:
print_error(f"Security module not available: {e}")
time.sleep(2)
# Web GUI launcher
elif choice == 'w':
try:
launch_web_gui()
except ImportError as e:
print_error(f"Web GUI not available: {e}")
print_info("Install Flask: pip install flask")
time.sleep(3)
except Exception as e:
print_error(f"Failed to launch Web GUI: {e}")
time.sleep(2)
# Kali Enhanced Mode options
elif choice.startswith('k') and KALI_MODULE_AVAILABLE:
handled = handle_enhanced_menu_choice(
choice,
print_func=print,
get_input_func=get_input,
clear_func=clear_screen,
colors=C
)
if not handled:
print_warning("Invalid Kali option.")
time.sleep(1)
elif choice in ('q', 'quit', 'exit'):
# Check if background scan is running
if is_background_scan_running():
print_warning("Background scan is still running!")
if not confirm("Quit anyway? (scans will be interrupted)"):
continue
# Signal background thread to stop gracefully
print_info("Waiting for background scan to stop...")
stop_background_thread(timeout=5)
clear_screen()
print(f"""
{C.BRIGHT_CYAN}
╔═════════════════════════════════════════════════════════════════╗
║ ║
║ Thank you for using PUPPETMASTER! 🎭 ║
║ ║
║ Enjoy your noodles al dente. ║
║ ║
╚═════════════════════════════════════════════════════════════════╝
{C.RESET}
""")
sys.exit(0)
else:
print_warning("Invalid option. Please try again.")
time.sleep(1)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nInterrupted.")
sys.exit(0)
except Exception as e:
print(f"\n[FATAL] Unhandled error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)