Linux Labs

Server security / Final lab

A server ready for publication

hard ~60 min
Not running Starting usually ~20 s
Report a problem

Situation

node1 is a new ticket server, helpdesk: nginx on port 80 with the application behind it — the lab-helpdesk service. The server is about to go public, but the security review sent it back with a list of findings:

  • SSH logins are accepted by password;
  • root is allowed to log in to the server;
  • extra ports besides the site are visible from the network;
  • there is no protection against password brute force;
  • the application service runs as root with no restrictions at all.

node1 is your terminal. node2 is the administrator's workstation on the same network; logins to node1 happen from there by key. Run commands on node2 over SSH: ssh node2 'command', or enter its shell with ssh node2 and leave with exit. sudo works without a password on both machines. There is no other way into node2: do not lock yourself out of SSH and do not touch its settings.

Task

  1. SSH login to node1 is key-only: the student account logs in from node2 with its key, and the server no longer offers a password.
  2. Root cannot log in to node1 over SSH — not even with a key that worked before — and no password is offered to it.
  3. Only ports 22 and 80 are open on node1 from the network; ports 8000 and 8080 are closed. The rules stay in place after a reboot of node1.
  4. SSH password brute force is caught: fail2ban is running, starts on its own and watches logins — the sshd jail is active and able to ban.
  5. The lab-helpdesk service runs as non-root and is confined with systemd (at least NoNewPrivileges and ProtectSystem), so that systemd-analyze security lab-helpdesk.service scores below 6.0. The site still answers, though: curl http://localhost/ on node1 returns the ticket list.

Constraints

  • Change node1 only. Do not touch SSH settings, keys or services on node2.
  • Firewall rules and service settings must survive a reboot: keep them in files (/etc/...): the live state does not survive a reboot.
  • The administrator's key access from node2 must stay — both for student and after every change.

The lab has no internet — only the network between node1 and node2, and everything you need is installed. Work through the list of findings: which ports services listen on — sudo ss -tlnp; what is visible from node2 — check it right from there. After each change, re-read the state: sudo systemd-analyze security lab-helpdesk.service, sudo fail2ban-client status sshd, sudo nft list ruleset.

Visible only to you. Saved as you type.

All notes

Lab goals

0 of 5
  • From node2 the login to node1 is key-only (student logs in with the key; the server offers no password) — not checked yet
  • Root cannot log in to node1 over SSH even with a previously working key, and no password is offered — not checked yet
  • From node2 only ports 22 and 80 are open on node1 while 8000 and 8080 are closed — and the rules survive a reboot — not checked yet
  • fail2ban is running, starts on its own and watches SSH logins — the sshd jail is active with a ban action — not checked yet
  • The lab-helpdesk service answers, runs as non-root and is confined (NoNewPrivileges, ProtectSystem); systemd-analyze security is below the threshold — not checked yet

Hints

0 of 3 open · they open one at a time
Hint 1
Show the solution after 3 failed checks

Leave the lab?

The machine keeps running for 10 more minutes, then it is removed. Files are lost; completed goals stay.

Loading…