filtered = filter_passwords( filtered, min_len=args.min_len, max_len=args.max_len, pattern=args.pattern, only_digits=args.only_digits, only_alpha=args.only_alpha, only_lower=args.only_lower, only_upper=args.only_upper, exclude_special=args.exclude_special, must_contain=args.must_contain, )
def search_passwords(passwords: List[str], query: str, case_sensitive: bool = False) -> List[str]: """Simple substring search.""" if not case_sensitive: query = query.lower() return [p for p in passwords if query in p.lower()] return [p for p in passwords if query in p] Export ---------------------------------------------------------------------- def export_results(passwords: List[str], output_file: Path, fmt: str = "txt"): """Export to txt, json, or csv.""" output_file.parent.mkdir(parents=True, exist_ok=True) if fmt == "txt": output_file.write_text("\n".join(passwords), encoding="utf-8") elif fmt == "json": json.dump(passwords, output_file.open("w", encoding="utf-8"), indent=2) elif fmt == "csv": import csv with open(output_file, "w", newline="", encoding="utf-8") as f: writer = csv.writer(f) writer.writerow(["password"]) writer.writerows([[p] for p in passwords]) else: raise ValueError(f"Unsupported format: fmt") print(f"[✓] Exported len(passwords) passwords to output_file") ---------------------------------------------------------------------- CLI ---------------------------------------------------------------------- def main(): parser = argparse.ArgumentParser( description="SecLists Password Tool – fetch, filter, search, and sample common passwords." ) parser.add_argument( "--list", "-l", choices=list(WORDLISTS.keys()), default=DEFAULT_WORDLIST, help=f"Wordlist to use (default: DEFAULT_WORDLIST)" ) parser.add_argument( "--search", "-s", help="Substring search (case-insensitive by default)" ) parser.add_argument( "--case-sensitive", action="store_true", help="Make --search case-sensitive" ) parser.add_argument( "--pattern", "-p", help="Regex pattern to match" ) parser.add_argument( "--min-len", type=int, help="Minimum password length" ) parser.add_argument( "--max-len", type=int, help="Maximum password length" ) parser.add_argument( "--only-digits", action="store_true", help="Only numeric passwords" ) parser.add_argument( "--only-alpha", action="store_true", help="Only alphabetic passwords" ) parser.add_argument( "--only-lower", action="store_true", help="Only lowercase letters" ) parser.add_argument( "--only-upper", action="store_true", help="Only uppercase letters" ) parser.add_argument( "--exclude-special", action="store_true", help="Exclude any non-alphanumeric characters" ) parser.add_argument( "--must-contain", help="Must contain this substring" ) parser.add_argument( "--sample", "-n", type=int, help="Randomly sample N passwords (after filters)" ) parser.add_argument( "--output", "-o", type=Path, help="Export results to file (txt, json, csv based on extension or --format)" ) parser.add_argument( "--format", choices=["txt", "json", "csv"], help="Export format (default from file extension or txt)" ) parser.add_argument( "--no-cache-dir", action="store_true", help="Do not use default cache (specify custom via --cache-dir)" ) parser.add_argument( "--cache-dir", type=Path, help="Custom cache directory" ) parser.add_argument( "--stats", action="store_true", help="Show statistics of selected passwords" ) parser.add_argument( "--verbose", action="store_true", help="Show additional info" ) seclists password
args = parser.parse_args()
if args.verbose: print(f"[*] Loaded len(all_passwords) passwords from 'args.list'") filtered = filter_passwords( filtered, min_len=args
try: resp = requests.get(url, timeout=15) resp.raise_for_status() cache_file.write_bytes(resp.content) print(f"[✓] Saved to cache_file") return cache_file except Exception as e: raise RuntimeError(f"Failed to download name: e") def load_passwords(name: str, cache_dir: Path = DEFAULT_CACHE_DIR) -> List[str]: """Return list of passwords (stripped, non-empty).""" path = download_wordlist(name, cache_dir) passwords = [] with open(path, "r", encoding="utf-8", errors="ignore") as f: for line in f: pwd = line.strip() if pwd: passwords.append(pwd) return passwords Search / Filter / Sample ---------------------------------------------------------------------- def filter_passwords( passwords: List[str], min_len: Optional[int] = None, max_len: Optional[int] = None, pattern: Optional[str] = None, only_digits: bool = False, only_alpha: bool = False, only_lower: bool = False, only_upper: bool = False, exclude_special: bool = False, must_contain: Optional[str] = None, ) -> List[str]: """Apply various filters to password list.""" result = passwords filtered = filter_passwords( filtered