Monday, November 16, 2026

PassDetective for finding secrets leaked in shell history

PassDetective for finding secrets leaked in shell history

PassDetective is a Go command-line scanner that reads Zsh, Bash, and Fish history files to surface mistakenly typed passwords and API keys during authorized audits and hygiene reviews.

Toolaydinnyunus/PassDetective — Go CLI that scans shell command history for accidentally exposed passwords and API keys
CategorySecret detection / operational hygiene (Go, ~153 stars, Apache-2.0)
Primary UseAuditing your own ~/.zsh_history, ~/.bash_history, and fish_history files for credentials pasted into commands before sharing shells or reporting
Safe UseEducational and documentary analysis for authorized professionals: run it on machines and accounts you own or are explicitly licensed to assess, such as pentest workstations, CTF boxes, and corporate hardening baselines.
Telemetry NotePurely local read of history files with no network beaconing; defenders can detect it as a Go binary reading shell history paths, and its regex corpus doubles as a blueprint for EDR/auditd file-access rules on history files.

PassDetective, written in Go and hosted at aydinnyunus/PassDetective, addresses one of the most under-appreciated hygiene problems in operational security: secrets that end up in shell history because somebody typed export API_KEY=... or pasted a token straight into a command line and pressed enter. Rather than hunting secrets in repositories or container images like classic secret scanners, it targets the interactive layer — the ~/.zsh_history, ~/.bash_history, and ~/.local/share/fish/fish_history files that accumulate on every operator workstation. For red teamers, pentesters, and administrators who record their terminal sessions or share machines, this is a genuinely useful pre-flight check before a transcript or screenshot leaves the building.

The architecture is straightforward and honest about it: PassDetective is a regex engine pointed at plaintext history files. The README documents a corpus of over 200 regular expressions — sourced from the h33tlit/secret-regex-list project — covering well-structured credential formats across major providers. The visible examples include Slack tokens matching (xox[p|b|o|a]-...), AWS access key IDs matching AKIA[0-9A-Z]{16}, Google API keys matching AIza[0-9A-Za-z\-_]{35}, Stripe live keys matching sk_live_[0-9a-zA-Z]{24}, and PEM private key headers such as -----BEGIN RSA PRIVATE KEY-----.

What makes the pattern set interesting analytically is that it mixes two distinct classes of detection. Formats like AKIA... and AIza... are structural: the provider encodes a recognizable prefix and alphabet, so regex matching is reliable. Others, like the Generic API Key pattern [a|A][p|P][i|I][_]?[k|K][e|E][y|Y].*['|"][0-9a-zA-Z]{32,45}['|"], are heuristic keyword-plus-blob heuristics that will produce false positives on non-secret base64-ish arguments. The Password in URL pattern, matching scheme://user:pass@host constructions, is a classic source of accidental leakage worth its own rule. Operators should treat results as triage, not ground truth.

Installation is refreshingly distribution-friendly. Beyond the canonical go install github.com/aydinnyunus/PassDetective@latest, the tool has been packaged into Kali Linux (sudo apt install PassDetective) and is available as a Nix package via nix-env -iA nixpkgs.passdetective on the unstable channel. Landing in the Kali repository is a meaningful signal: it implies the tool passed that project's packaging review and is positioned as a standard operator utility rather than a niche script. The README also links a blog post covering the Kali inclusion.

The CLI surface is compact. PassDetective extract -all sweeps every supported shell, while granular flags let you scope the run: -z/--zsh, -b/--bash, and -f/--fish select individual shells and can be combined, as in PassDetective extract --zsh --fish. Each selected shell is scanned independently, and the README notes that a shell whose history or config file is missing is reported rather than silently skipped — a small detail that matters when you think a machine has Fish installed and it actually doesn't.

The --secrets modifier changes the run from history dumping to credential-focused scanning, composing with any shell flag so PassDetective extract --secrets --fish inspects only Fish history against the regex corpus. The config files listed alongside each history file (~/.zshrc, ~/.bashrc, ~/.config/fish/config.fish) suggest the tool also understands where shells keep environment exports, which is exactly where long-lived tokens tend to hide in plain sight.

The standout feature for anyone who has ever leaked a secret while reporting on leaked secrets is --redact. Because a scan prints the offending command line, the secret otherwise lands on your screen, in your terminal scrollback, and in anything you paste the output into. Adding -r masks every detected secret on a matching line — including multiple distinct matches on a single line — while keeping the surrounding command readable. This is the difference between a tool you can screenshot into a ticket and one that quietly replicates the problem it exists to find, and it is good design judgment from the author.

In an authorized workflow, the natural placement is at both ends of an engagement. Before you start, baseline your own workstation so typos from prior work don't haunt you; after an engagement, sweep your history before archiving session logs or handing a VM back to a client. Blue teams get equal value: the same regex corpus is effectively a detection engineering reference for building DLP rules and log-based alerts that flag credential-shaped strings in shell telemetry, and file-access monitoring on history paths catches any tool — hostile or friendly — that reads them.

Telemetry-wise, PassDetective is purely local: it reads history and config files and prints to the terminal, with no network callbacks described anywhere in the README. From a defensive perspective, that cuts both ways — the same trivial capability (iterate a regex list over ~/.bash_history) is a standard post-exploitation loot technique, which is precisely why defenders should know the tool, its pattern set, and the fact that unencrypted shell history remains one of the first things an attacker greps for after landing on a box.

The repo metadata rounds out the picture: an Apache-2.0 license, Go as the implementation language, and topic tags spanning bash, zsh, kali-linux, bugbounty, and red-team that match its actual audience. The roadmap is delegated to the GitHub issue tracker rather than a marketing list, and contribution follows the standard fork-branch-PR model. One minor inconsistency worth noting: the badge shields reference an unrelated usestrix/cli repo, a copy-paste artifact from the README template that says more about template hygiene than about the project itself.

Caveats before relying on it: regex-based secret detection is inherently incomplete. Credentials with no structural signature — a raw password passed to mysql -p, a bespoke internal token — will evade pattern matching, and history files with HISTTIMEFORMAT timestamps or Fish's YAML-style format need correct parsing, which the per-shell flag design implies is handled. Treat PassDetective as one layer in a hygiene stack that also includes encrypted secret managers, HISTCONTROL settings, and periodic credential rotation. Within that stack, for its narrow and well-defined job, it is a tidy, defensibly scoped tool worth keeping in /usr/bin.

Official project repository for aydinnyunus/PassDetective.
Download Tool

Educational analysis for authorized security professionals. Use only in controlled, authorized environments.

Sponsored
Share articleFacebookXLinkedIn

Continue exploring

Browse all articles →

0 comentários:

Post a Comment

Note: Only a member of this blog may post a comment.