The lab
here is how portswigger describes it
This lab leaks its source code via backup files in a hidden directory. To solve the lab, identify and submit the database password, which is hard-coded in the leaked source code.
the server is keeping a backup copy of its source in a directory it would rather we did not find, and that backup still holds a hard-coded database password. the directory is not linked in the site, but robots.txt names it while trying to keep crawlers out, which just advertises it to us. once we are in the directory the .bak file hands us the raw source, and the password is sitting in the connection string.
why this leaks#
two small habits combine badly here. first, editors and deploy scripts leave backup copies like ProductTemplate.java.bak next to the real files, and a .bak extension is not executed by the server, it is served as plain text, so the source is readable instead of running. second, robots.txt is meant to tell crawlers which paths to avoid, but it is a public file, so listing /backup there to hide it does the opposite, it tells any curious person exactly where to look. put together, a secret meant to live only in compiled server-side code ends up readable over http.
Step 1 - read robots.txt#
we browse to /robots.txt and it reveals a /backup directory it is trying to keep crawlers out of:
/robots.txt

Step 2 - browse the backup directory#
we browse to the directory and find the backup file:
/backup/ProductTemplate.java.bak

Step 3 - read the hard-coded password#
because .bak is served as plain text we get the raw java source. in it the connection builder contains a hard-coded password for a Postgres database. we copy that password.

Step 4 - submit the password#
we go back to the lab, click Submit solution, and enter the database password.

with this, the lab is solved!
