Repository navigation
Expand file tree
/
Copy pathruleflow.py
More file actions
603 lines (513 loc) · 24.3 KB
/
Copy pathruleflow.py
File metadata and controls
603 lines (513 loc) · 24.3 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
#!/usr/bin/env python3
# =============================================================================
# INTERACTIVE HASHCAT RULE PIPELINE (Python Port) - STREAMING OUTPUT
# =============================================================================
"""
Fully cross-platform (Windows/Linux) interactive pipeline for Hashcat rule generation:
1. Rulest v2 - generates candidate rules
2. Concentrator - cleans and expands rules
3. Ranker - ranks rules using either legacy exhaustive or MAB bandit approach
Environment variables (mirrors ruleflow.sh behaviour — set any before running
to skip the interactive prompts for that value):
PIPE_BASE_WORDLIST base wordlist path
PIPE_TARGET_WORDLIST target wordlist path
PIPE_CRACKED_LIST cracked passwords list
PIPE_MODE maximum | balanced | fast | custom (default: balanced)
PIPE_LEGACY y | n (default: n)
PIPE_DEPTH int (default: 3)
PIPE_GEN_GENERATIONS int (default: 300)
PIPE_GENETIC_POP int (default: 600)
PIPE_TARGET_HOURS float (default: 2.0)
PIPE_BLOOM_MB int (default: 800)
PIPE_STAGE0_PROCESSES int (default: 0)
PIPE_TOKEN_STRIP_MAX_PREFIX int (default: 4)
PIPE_TOKEN_STRIP_MAX_SUFFIX int (default: 4)
PIPE_RANKER_K int (default: mode preset)
PIPE_RANKER_MAB_SCREENING int (default: mode preset)
PIPE_RANKER_MAB_FINAL int (default: mode preset)
PIPE_RANKER_PRESET str (default: mode preset)
"""
import os
import sys
import subprocess
import glob
import threading
from typing import List, Optional
# =============================================================================
# FORCE IMMEDIATE OUTPUT (no buffering)
# =============================================================================
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(line_buffering=True)
sys.stderr.reconfigure(line_buffering=True)
print("\n[INFO] ruleflow.py started (streaming output mode)", flush=True)
# =============================================================================
# Widen the terminal on Windows so PowerShell doesn't truncate output
# =============================================================================
if sys.platform == "win32":
try:
import ctypes
kernel32 = ctypes.windll.kernel32
# Get the current console screen buffer info
class _COORD(ctypes.Structure):
_fields_ = [("X", ctypes.c_short), ("Y", ctypes.c_short)]
class _SMALL_RECT(ctypes.Structure):
_fields_ = [("Left", ctypes.c_short), ("Top", ctypes.c_short),
("Right", ctypes.c_short), ("Bottom", ctypes.c_short)]
class _CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
_fields_ = [("dwSize", _COORD), ("dwCursorPosition", _COORD),
("wAttributes", ctypes.c_ushort), ("srWindow", _SMALL_RECT),
("dwMaximumWindowSize", _COORD)]
hStdOut = kernel32.GetStdHandle(-11) # STD_OUTPUT_HANDLE
csbi = _CONSOLE_SCREEN_BUFFER_INFO()
if kernel32.GetConsoleScreenBufferInfo(hStdOut, ctypes.byref(csbi)):
desired_width = 260
cur_width = csbi.dwSize.X
if cur_width < desired_width:
# First widen the buffer, then the window
new_size = _COORD(desired_width, csbi.dwSize.Y)
kernel32.SetConsoleScreenBufferSize(hStdOut, new_size)
rect = csbi.srWindow
rect.Right = rect.Left + desired_width - 1
kernel32.SetConsoleWindowInfo(hStdOut, True, ctypes.byref(rect))
except Exception:
pass # non-fatal; wide output is a convenience, not a requirement
# =============================================================================
# Cross-platform color support (with fallback)
# =============================================================================
try:
from colorama import init, Fore, Style
init(autoreset=True)
HAS_COLOR = True
except ImportError:
HAS_COLOR = False
class Fore:
RED = ''
GREEN = ''
YELLOW = ''
BLUE = ''
MAGENTA = ''
CYAN = ''
WHITE = ''
RESET = ''
class Style:
BRIGHT = ''
DIM = ''
NORMAL = ''
RESET_ALL = ''
# Force UTF-8 on Windows console
if sys.platform == "win32":
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
except AttributeError:
pass
def cprint(text: str, color: str = Fore.WHITE, bright: bool = False, end: str = '\n') -> None:
style = Style.BRIGHT if bright else Style.NORMAL
if HAS_COLOR:
print(f"{style}{color}{text}{Style.RESET_ALL}", end=end, flush=True)
else:
print(text, end=end, flush=True)
def print_header() -> None:
cprint("\n╔════════════════════════════════════════════════════════════════╗", Fore.CYAN, bright=True)
cprint("║ INTERACTIVE HASHCAT RULE PIPELINE (Python) ║", Fore.CYAN, bright=True)
cprint("╚════════════════════════════════════════════════════════════════╝", Fore.CYAN, bright=True)
def print_step(step_num: int, name: str) -> None:
cprint(f"\n[{step_num}/3] {name}...", Fore.BLUE, bright=True)
def print_error(msg: str) -> None:
cprint(f"Error: {msg}", Fore.RED, bright=True)
def print_success(msg: str) -> None:
cprint(f"→ {msg}", Fore.GREEN, bright=True)
def print_info(msg: str) -> None:
cprint(f"→ {msg}", Fore.CYAN)
def print_warning(msg: str) -> None:
cprint(f"→ {msg}", Fore.YELLOW)
# -----------------------------------------------------------------------------
# Helpers
# -----------------------------------------------------------------------------
def _env(key: str) -> Optional[str]:
v = os.environ.get(key, "").strip()
return v if v else None
def get_input(prompt: str, default: Optional[str] = None, env_key: Optional[str] = None) -> str:
if env_key:
env_val = _env(env_key)
if env_val is not None:
cprint(f" {prompt}: {env_val} (from {env_key})", Fore.MAGENTA)
return env_val
display_prompt = f"{prompt} [{default}]: " if default is not None else f"{prompt}: "
sys.stdout.flush()
value = input(display_prompt).strip()
if value == "" and default is not None:
return default
return value
def file_exists(path: str) -> bool:
return os.path.isfile(path) and os.access(path, os.R_OK)
def _build_env() -> dict:
env = os.environ.copy()
env["PYTHONUTF8"] = "1"
env["PYTHONIOENCODING"] = "utf-8"
return env
def _stream_and_wait(proc: subprocess.Popen, description: str, timeout_seconds: int) -> bool:
"""Stream stdout of a running process, enforce timeout, return True on rc==0."""
timed_out = threading.Event()
def _kill():
timed_out.set()
proc.kill()
timer = threading.Timer(timeout_seconds, _kill)
timer.daemon = True
timer.start()
for line in proc.stdout:
print(line, end='', flush=True)
proc.wait()
timer.cancel()
if timed_out.is_set():
print_error(f"{description} killed after {timeout_seconds}s timeout")
return False
if proc.returncode == 0:
print_success(f"{description} completed successfully")
return True
print_error(f"{description} failed with exit code {proc.returncode}")
return False
def _open_console_stdin():
"""
Return a file object connected to the real keyboard even when ruleflow's
own stdin is a pipe or DEVNULL.
Windows : CONIN$ — Win32 console input buffer
Unix : /dev/tty — controlling terminal
Returns None when no real console exists (pure CI / no-TTY environment).
"""
if sys.platform == "win32":
try:
return open("CONIN$", "rb", buffering=0)
except OSError:
return None
else:
try:
return open("/dev/tty", "rb", buffering=0)
except OSError:
return None
def run_command_streaming(cmd: List[str], description: str, timeout_seconds: int = 3600) -> bool:
"""
Run a command with real-time streaming output and a timeout.
stdin is wired to the real console (CONIN$ / /dev/tty) so that
interactive keystrokes (p/r/q in rulest) reach the child process even
though ruleflow's own stdin may be a pipe or DEVNULL.
Falls back to DEVNULL if no real console is available.
CREATE_NO_WINDOW is intentionally NOT set — the child must share the
console so CONIN$ / /dev/tty are reachable from inside it.
"""
cprint(f"\n→ Running: {' '.join(cmd)}", Fore.MAGENTA, bright=True)
cprint(f"→ (output will appear below, timeout after {timeout_seconds} seconds)", Fore.CYAN)
cprint(f"→ (keyboard: p = pause | r = resume | q = save & quit)", Fore.CYAN)
sys.stdout.flush()
console_fh = _open_console_stdin()
stdin_arg = console_fh if console_fh is not None else subprocess.DEVNULL
try:
proc = subprocess.Popen(
cmd,
stdin=stdin_arg,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace",
env=_build_env(),
bufsize=1,
creationflags=0,
)
return _stream_and_wait(proc, description, timeout_seconds)
except FileNotFoundError:
print_error(f"Command not found: {cmd[0]}. Ensure Python and all scripts are in PATH.")
return False
except Exception as e:
print_error(f"Unexpected error running {description}: {e}")
return False
finally:
if console_fh is not None:
try:
console_fh.close()
except OSError:
pass
def run_command_with_stdin(cmd: List[str], description: str,
stdin_input: str, timeout_seconds: int = 3600) -> bool:
"""
Run a command that expects interactive stdin input (e.g. concentrator's menu).
stdin_input is written to the process stdin after launch so menu prompts are
answered non-interactively. stdout/stderr are still streamed to the console.
Returns True on success, False on failure or timeout.
"""
cprint(f"\n→ Running: {' '.join(cmd)}", Fore.MAGENTA, bright=True)
cprint(f"→ (non-interactive stdin supplied, timeout after {timeout_seconds} seconds)", Fore.CYAN)
sys.stdout.flush()
creationflags = subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0
try:
proc = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace",
env=_build_env(),
bufsize=1,
creationflags=creationflags,
)
# Write menu answers then close stdin so the process sees EOF after
# it has consumed the keystrokes. Use a thread so we don't block on
# a process that might buffer its output before printing the prompt.
#
# Sequence for concentrator's interactive menu:
# s → "SAVE current rules" (main menu)
# 1 → "Auto filename" (save sub-menu)
# q → "QUIT" (main menu, after save returns)
#
# We write all answers up-front and leave the pipe open until the
# process exits — closing too early causes an EOFError when concentrator
# tries to read the save sub-menu prompt after stdin is already closed.
def _write_stdin():
try:
for answer in stdin_input.splitlines(keepends=True):
proc.stdin.write(answer)
proc.stdin.flush()
# Do NOT close stdin here; let the process exit on its own.
# The pipe is closed automatically when the process terminates.
except (BrokenPipeError, OSError):
pass # process already exited — harmless
writer = threading.Thread(target=_write_stdin, daemon=True)
writer.start()
return _stream_and_wait(proc, description, timeout_seconds)
except FileNotFoundError:
print_error(f"Command not found: {cmd[0]}. Ensure Python and all scripts are in PATH.")
return False
except Exception as e:
print_error(f"Unexpected error running {description}: {e}")
return False
# =============================================================================
# Main pipeline
# =============================================================================
def main() -> None:
print_header()
# ------------------------------------------------------------------ #
# Step 1 — Input files #
# ------------------------------------------------------------------ #
cprint("\n=== Step 1: Input Files ===", Fore.YELLOW, bright=True)
base_wordlist = get_input("Base wordlist path", env_key="PIPE_BASE_WORDLIST")
target_wordlist = get_input("Target wordlist path", env_key="PIPE_TARGET_WORDLIST")
cracked_list = get_input("Cracked passwords list (required for Ranker)", env_key="PIPE_CRACKED_LIST")
for label, path in [
("Base wordlist", base_wordlist),
("Target wordlist", target_wordlist),
("Cracked list", cracked_list),
]:
if not file_exists(path):
print_error(f"{label} not found: {path}")
sys.exit(1)
# ------------------------------------------------------------------ #
# Step 2 — Pipeline mode #
# ------------------------------------------------------------------ #
cprint("\n=== Step 2: Pipeline Mode ===", Fore.YELLOW, bright=True)
print("1) Maximum Quality")
print("2) Balanced (Recommended)")
print("3) Fast & Light")
print("4) Custom (Full Control)")
mode_choice = get_input("Select mode (1-4)", "2", env_key="PIPE_MODE")
mode_map = {"1": "maximum", "2": "balanced", "3": "fast", "4": "custom",
"maximum": "maximum", "balanced": "balanced",
"fast": "fast", "custom": "custom"}
mode = mode_map.get(mode_choice.lower(), "balanced")
# ------------------------------------------------------------------ #
# Step 3 — Ranking mode #
# ------------------------------------------------------------------ #
cprint("\n=== Step 3: Ranking Mode ===", Fore.YELLOW, bright=True)
legacy_choice = get_input("Use legacy (exhaustive) ranker mode? (y/n)", "n", env_key="PIPE_LEGACY").lower()
legacy_mode = (legacy_choice == "y")
# ------------------------------------------------------------------ #
# Default parameters (same as sh script) #
# ------------------------------------------------------------------ #
depth = 3
gen_generations = 300
genetic_pop = 600
target_hours = 2.0
bloom_mb = 800
stage0_processes = 0
token_strip_max_prefix = 4
token_strip_max_suffix = 4
ranker_k = 18000
ranker_mab_screening = 4
ranker_mab_final = 8
ranker_preset = "medium_memory"
# Mode presets
if mode == "maximum":
ranker_k = 25000; ranker_mab_screening = 5; ranker_mab_final = 10; ranker_preset = "high_memory"
elif mode == "balanced":
ranker_k = 18000; ranker_mab_screening = 4; ranker_mab_final = 8; ranker_preset = "medium_memory"
elif mode == "fast":
ranker_k = 12000; ranker_mab_screening = 3; ranker_mab_final = 5; ranker_preset = "low_memory"
# ------------------------------------------------------------------ #
# Apply environment-variable overrides for numeric params #
# ------------------------------------------------------------------ #
def _ei(key, current):
v = _env(key)
if v and v.isdigit():
return int(v)
return current
def _ef(key, current):
v = _env(key)
if v:
try: return float(v)
except ValueError: pass
return current
def _es(key, current):
v = _env(key)
return v if v else current
depth = _ei("PIPE_DEPTH", depth)
gen_generations = _ei("PIPE_GEN_GENERATIONS", gen_generations)
genetic_pop = _ei("PIPE_GENETIC_POP", genetic_pop)
target_hours = _ef("PIPE_TARGET_HOURS", target_hours)
bloom_mb = _ei("PIPE_BLOOM_MB", bloom_mb)
stage0_processes = _ei("PIPE_STAGE0_PROCESSES", stage0_processes)
token_strip_max_prefix = _ei("PIPE_TOKEN_STRIP_MAX_PREFIX", token_strip_max_prefix)
token_strip_max_suffix = _ei("PIPE_TOKEN_STRIP_MAX_SUFFIX", token_strip_max_suffix)
ranker_k = _ei("PIPE_RANKER_K", ranker_k)
ranker_mab_screening = _ei("PIPE_RANKER_MAB_SCREENING", ranker_mab_screening)
ranker_mab_final = _ei("PIPE_RANKER_MAB_FINAL", ranker_mab_final)
ranker_preset = _es("PIPE_RANKER_PRESET", ranker_preset)
# ------------------------------------------------------------------ #
# Custom / Maximum — interactive overrides #
# ------------------------------------------------------------------ #
if mode in ("custom", "maximum"):
cprint("\n=== Advanced Configuration ===", Fore.CYAN, bright=True)
cprint("--- Rulest Core Settings ---", Fore.YELLOW, bright=True)
v = get_input("Rulest Max Depth [3-4]", str(depth))
if v.isdigit(): depth = int(v)
v = get_input("Genetic Generations [40-120]", str(gen_generations))
if v.isdigit(): gen_generations = int(v)
v = get_input("Genetic Population [100-400]", str(genetic_pop))
if v.isdigit(): genetic_pop = int(v)
v = get_input("Rulest Target Hours [0.5-5.0]", str(target_hours))
try: target_hours = float(v)
except ValueError: pass
cprint("--- Rulest Bloom & Stage 0 ---", Fore.YELLOW, bright=True)
v = get_input("Bloom Filter Size (MB) [400-2000]", str(bloom_mb))
if v.isdigit(): bloom_mb = int(v)
v = get_input("Stage 0 Processes (0=auto)", str(stage0_processes))
if v.isdigit(): stage0_processes = int(v)
v = get_input("Token-Strip Max Prefix Length", str(token_strip_max_prefix))
if v.isdigit(): token_strip_max_prefix = int(v)
v = get_input("Token-Strip Max Suffix Length", str(token_strip_max_suffix))
if v.isdigit(): token_strip_max_suffix = int(v)
cprint("--- Ranker Settings ---", Fore.YELLOW, bright=True)
v = get_input("Final top rules to keep", str(ranker_k))
if v.isdigit(): ranker_k = int(v)
if not legacy_mode:
v = get_input("MAB Screening Trials", str(ranker_mab_screening))
if v.isdigit(): ranker_mab_screening = int(v)
v = get_input("MAB Final Trials", str(ranker_mab_final))
if v.isdigit(): ranker_mab_final = int(v)
v = get_input("Ranker Preset", ranker_preset)
if v.strip(): ranker_preset = v.strip()
# ------------------------------------------------------------------ #
# Execution #
# ------------------------------------------------------------------ #
cprint(f"\nStarting {mode} Pipeline (Rulest → Concentrator → Ranker)...", Fore.GREEN, bright=True)
# 1. Rulest -----------------------------------------------------------
print_step(1, "Rulest")
# Verify rulest_v2.py exists
if not os.path.isfile("rulest_v2.py"):
print_error("rulest_v2.py not found in current directory!")
sys.exit(1)
rulest_cmd = [
sys.executable, "rulest_v2.py",
base_wordlist, target_wordlist,
"-o", "stage1_raw.rule",
"--max-depth", str(depth),
"--token-strip",
"--genetic",
"--genetic-generations", str(gen_generations),
"--genetic-pop", str(genetic_pop),
"--target-hours", str(target_hours),
"--bloom-mb", str(bloom_mb),
"--token-strip-max-prefix", str(token_strip_max_prefix),
"--token-strip-max-suffix", str(token_strip_max_suffix),
"--token-strip-workers", str(stage0_processes),
]
if not run_command_streaming(rulest_cmd, "Rulest", timeout_seconds=7200):
sys.exit(1)
# Verify output
if not os.path.isfile("stage1_raw.rule") or os.path.getsize("stage1_raw.rule") == 0:
print_error("Rulest did not create a non‑empty 'stage1_raw.rule' file.")
sys.exit(1)
print_success("Rulest output verified: stage1_raw.rule")
# 2. Concentrator -----------------------------------------------------
print_step(2, "Concentrator")
if not os.path.isfile("concentrator.py"):
print_error("concentrator.py not found in current directory!")
sys.exit(1)
concentrator_cmd = [
sys.executable, "concentrator.py",
"-p", "stage1_raw.rule",
"-ob", "stage2_cleaned", # hyphen form that argparse normalises to
"-f", "line",
]
# Concentrator always enters its interactive menu after loading rules.
# We drive it non-interactively by feeding:
# s → "SAVE current rules" (writes stage2_cleaned*.rule)
# q → "QUIT"
# A small sleep marker (\n) before each ensures the prompt is flushed
# before we send the next keystroke.
concentrator_stdin = "s\n1\nq\n"
if not run_command_with_stdin(concentrator_cmd, "Concentrator",
stdin_input=concentrator_stdin,
timeout_seconds=1800):
sys.exit(1)
# Pick the newest matching output file (guards against stale files from
# prior runs appearing first in an unsorted glob).
cleaned_rule_files = sorted(
glob.glob("stage2_cleaned*.rule"),
key=os.path.getmtime,
reverse=True,
)
if not cleaned_rule_files:
print_error("Concentrator did not produce any 'stage2_cleaned*.rule' file.")
sys.exit(1)
cleaned_rule = cleaned_rule_files[0]
print_success(f"Using: {cleaned_rule}")
# 3. Ranker -----------------------------------------------------------
print_step(3, "Ranker")
if not os.path.isfile("ranker.py"):
print_error("ranker.py not found in current directory!")
sys.exit(1)
ranker_cmd = [
sys.executable, "ranker.py",
"-w", base_wordlist,
"-r", cleaned_rule,
"-c", cracked_list,
"-o", "stage3_ranking.csv",
"-k", str(ranker_k),
"--preset", ranker_preset,
]
if legacy_mode:
print_warning("Running in LEGACY (exhaustive) mode.")
ranker_cmd.append("--legacy")
else:
print_info(f"Running in MAB mode (screening={ranker_mab_screening}, final={ranker_mab_final}).")
ranker_cmd.extend(["--mab-screening-trials", str(ranker_mab_screening)])
ranker_cmd.extend(["--mab-final-trials", str(ranker_mab_final)])
if not run_command_streaming(ranker_cmd, "Ranker", timeout_seconds=14400):
sys.exit(1)
# ------------------------------------------------------------------ #
# Done #
# ------------------------------------------------------------------ #
cprint("\nPipeline completed successfully!", Fore.GREEN, bright=True)
print_success("Ranking results: stage3_ranking.csv")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
cprint("\n\nPipeline interrupted by user.", Fore.YELLOW, bright=True)
sys.exit(130)
except Exception as e:
print_error(f"Unhandled exception: {e}")
import traceback
traceback.print_exc()
sys.exit(1)