Finding a Root Database Password Left in Shell History

Élévation de Privilèges & Post-Exploitation Niveau 2/5 ~3 min 2026-07-24

Le défi

Vous avez un shell en tant qu'utilisateur 'deploy' sur un serveur de build. L'ancien admin a lance une commande de base de donnees et a laisse le mot de passe root directement sur la ligne de commande. Consultez l'historique du shell, trouvez cette commande et soumettez le mot de passe root de la base.

Ce que tu vas apprendre

  • Use the history command to review a user's past commands
  • Recognise that inline -p passwords are stored in plaintext history
  • Extract the password that follows -p with no space
  • Explain why command-line secrets persist long after the command ran
  • Apply safer ways to authenticate to MySQL without a CLI password

Compétences testées

Shell history reviewCredential discoveryLinux post-exploitationRecognising insecure command patterns

Prérequis

  • Comfortable running the history command in a shell
  • Know that mysql -p<password> passes a password on the command line

Comment ça marche

Interactive shells keep a record of what was typed. Bash writes each command to ~/.bash_history, and the history builtin prints that list. The feature is meant to save you re-typing commands, but it has a side effect: anything you pass as an argument - including a password - is recorded verbatim and lingers long after the command finished running.

The classic offender is the MySQL client. Writing mysql -uroot -pR00t!Db_2026 shop hands the password to the program on the command line. There is no space between -p and the value, so the whole token is the credential. That line is now in the history file, readable by anyone who later operates as that user. A handful of other tools have the same flaw, which is why many of them now warn that supplying a password on the command line is insecure.

From an attacker's point of view this is one of the cheapest wins available. You do not need to read a config file, escalate privileges, or break any crypto - you just run history and read. Because sudo is a dead end in this scenario, the history is exactly the kind of low-effort, high-value artifact a real operator checks first after landing on a host.

Erreurs fréquentes

  • Hunting through files for the password. It was never written to a file here - the value only ever appeared on a command line, so history is the right tool, not cat.
  • Reaching for sudo. sudo is a dead end in this scenario; the win is reading what is already readable, not escalating.
  • Misreading where the password starts. The value follows -p with no space - R00t!Db_2026 - not the database name shop that comes after it.
  • Assuming history is cleared. Operators rarely scrub their history; the line usually survives until someone deliberately wipes it.

Comment s'en protéger

The root cause is putting a secret on a command line at all. Safer patterns keep the password out of both the process list and the history file:

  • Use mysql -uroot -p with no value so the client prompts interactively - the password is never typed as an argument.
  • Store credentials in a protected ~/.my.cnf with chmod 600, or use mysql_config_editor to keep them in an encrypted login path.
  • Prefer socket or token-based authentication so a static password is not needed for routine queries.
  • Periodically clear sensitive history and set HISTCONTROL=ignorespace to keep secret-bearing commands out of the history file.

If a password has appeared in history or a process list, consider it leaked and rotate it - clearing the history afterwards does not undo a read that may have already happened.

Solution complète

Les membres Pro et Max débloquent la solution complète étape par étape.

Passer Pro

Statistiques de la communauté

105 résolutions
81% taux de réussite
M2F14M3 Premier sang

Hacks du jour associés

17 000+ Hackers 100+ Labs & Cours Gratuit
Commencer Gratuitement