Passwords in the logs
The Sorriso & Denti dental practice has forgotten the password of its patient management system, but the sysadmin swears that “passwords are not written down anywhere”. Check the server's login log: someone may have written it where they should not have.
Lab 6 of 9 in the Privilege Escalation path. If you get stuck you have 3 hints, from the vaguest to the most precise: they cost 0, 40 and 100 XP.
What you learn
Objectives complete themselves while you work in the terminal; each one is worth experience points:
- Isolate the attempts with a user name that does not exist (100 XP)
- Sort and count the names with sort and uniq (100 XP)
- Look for the successful logins (100 XP)
- Get into the management system with the right password (150 XP)
Topics: privesc, log, credenziali, audit.
Commands you will use
The terminal is simulated and understands about forty Linux commands. In this lab you will mostly need these:
cat: prints the contents of a file: the most direct way to read configurations, notes and logs.grep: finds the lines that contain a word, even across whole folders with -r. It is the main tool for analysing text and logs.cut: extracts one column from each line using a chosen separator, to isolate a specific field of a log.sort: sorts lines, numerically (-n) or in reverse (-r) too.uniq: removes repeated adjacent lines and counts them with -c: together with sort it builds rankings, such as the most insistent addresses.curl: makes HTTP requests from the terminal and shows the server’s raw answer, headers included.|: the vertical bar | chains commands: the output of the first becomes the input of the next, so small tools form a complete analysis.
The simulated environment
You work in a simulated Linux shell, in the home folder of the user runner: invented files and folders, no network target.
Besides the home folder there is a complete simulated system, with configuration files, logs, users and permissions to examine.
Local services also run on the machine:
- SSH: encrypted remote command-line access; it is protected with keys instead of passwords and without direct root login.
- Web (HTTP): a web server with pages, APIs or admin panels: the most exposed part of almost every organisation.
The defensive lesson
Once the lab is solved, the write-up explains what went wrong and how to protect yourself:
Whoever types the password into the user name field writes it into the log: logs keep invalid names in full, stay around for months and are read by many technicians. Anyone with read access to the log finds the password together with the name of the user who, right afterwards, logged in from the same address. Defensive lesson: do not log invalid user names in clear text (or mask them), limit who can read the logs, change at once any password that has ended up in a log, and protect logins with keys or a second factor.
Before and after this lab
To unlock it you must have solved:
- Forgotten secrets (Privilege Escalation, medium)
- Pipes and filters (Linux Fundamentals, medium)
After this lab you can move on to:
- Too many capabilities (Privilege Escalation, medium)
The Privilege Escalation path
Privilege Escalation is an audit path here: you are on a server as a normal user and you check whether some misconfiguration lets you gain more privileges than you should have. You examine sudo rules, programs with the SUID bit, credentials forgotten in the history and in files, and secrets passed as process arguments. These are the same checks that people who harden systems run, and each lab ends with the principle that sums them all up: least privilege.