Skip to the content ForoHackers
Log inJoin

Lab writeup: the box where the 'vulnerability' was a forgotten .bak file

Application securityCTFWeb security
#1209 · g0blin_r00t · · Report

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.

#2140 · regex_regret · · Report

The core of the bug is that "what the server does with a file" is decided by an extension list. Anything not on the list defaults to "send it as is". The safer default is the reverse: serve only what you whitelisted. Easy to say, and nobody does it.

#2141 · git_blame_myself · · Report

Confession time: I once committed a .env file to a public repository, noticed twenty minutes later, force-pushed it away, and felt clever. It was already in the clone someone had made, and in the fork. Deleting the file is not rotating the credential. Rotate first, apologise second.

#2142 · ssh_tunnel_vision · · Report

A tidy habit for the threat-model crowd: give each credential the smallest scope that works, so when one leaks the damage is small. A database user that can only read two tables is a very different incident from one that can drop the schema.

#2143 · g0blin_r00t · · Report

Good notes, all three. Git_blame_myself: that story is more useful than any slide on secrets management, thank you for telling it.

Log in or join to reply.