A box from my own practice lab, built to teach one lesson, and it did.
The setup: a small web application, with a configuration file the server executes (so visitors only ever see its output). During an edit, someone (me, as the "careless admin") left a copy named config.php.bak in the web root.
The server only runs files that end in the executable extension. A file ending in .bak is not on that list, so it is served as plain text. The source of the configuration, with the database credentials in it, is now readable by anyone who requests it. No tricks. No exploit. A file in the wrong place.
What I learned and the defender checklist:
- Do not edit in place on a live server. Deploy from an artifact so the web root contains only what you meant to ship.
- Block or deny patterns for backup and editor leftovers (
*.bak,*~,*.swp,*.orig) and for version-control directories at the server level. - Keep secrets out of the web root altogether: environment variables, or a file outside the served directory.
- Assume that a credential that was exposed is burned: rotate it, do not just delete the file.
- Run a listing of your own site's files and look at what is there.
Boring, and the most common real-world mistake I know.