Security basics · Lesson 1 · 25 min

Think like an attacker, act like a defender

Security people have a habit: before they defend a server, they look at it the way an attacker would. What can someone reach from outside? What's running that nobody remembers? Who can log in? You can't protect what you don't know is there, so this lesson is about seeing your own server clearly, and then making it smaller and safer.

You will learn

  • The rule that comes before everything else: permission
  • Threat modelling in four questions
  • Your server's attack surface, and the commands that map it on both families
  • The defender's habits: less is safer, least privilege, layers

Permission comes first

Everything in this path happens on machines you own or are responsible for: your server, your practice lab, a VM on your own computer. Looking for weaknesses in someone else's computer without written permission is illegal in most countries, even if you "only looked" and changed nothing. Laws like the USA's Computer Fraud and Abuse Act and the UK's Computer Misuse Act are written exactly for that.

Professionals who test other people's systems (penetration testers) always have a signed agreement first that says exactly what they may test, when, and how. No agreement, no testing. That's the whole difference between a security job and a crime.

The rule for this path

Only test what you own or have written permission to test. At school or work, the network belongs to someone else: ask first, in writing.

Threat modelling in four questions

You can't protect everything from everyone, so professionals start with four questions (from Adam Shostack's threat-modelling framework):

  1. What are we working on? A small web server for a club, with a members list.
  2. What can go wrong? A guessed password, a forgotten service leaking the members list, an old account nobody watches.
  3. What are we going to do about it? Keys only for SSH, turn off what isn't needed, remove old accounts, keep it patched.
  4. Did we do a good job? Check again, from the outside, the way an attacker would.

Notice question 2 is about likely problems, not movie hackers. Most real break-ins use something boring: a reused password, an old account, a test server someone forgot to switch off.

Your attack surface

Your attack surface is everything on the server that someone could reach or abuse. The smaller it is, the less can go wrong. Here's how to map it:

QuestionRocky / RHELUbuntu / Debian
What's listening for connections?sudo ss -tlnp same on both
Which services are running?systemctl list-units --type=service --state=running same on both
Which accounts can log in?getent passwd | awk -F: '$7 !~ /(nologin|false)$/ {print $1}' same on both
Who is an admin (can use sudo)?getent group wheelgetent group sudo
Anything out of date?dnf updateinfo list --securityapt list --upgradable

In ss -tlnp, look at the Local Address column. 127.0.0.1:… or 127.0.0.53%lo:… means only the server itself can connect. 0.0.0.0:… or [::]:… means every network the server is on can reach it. The -p part names the program, which is why it needs sudo.

The defender's habits

Lock, don't delete (at first)

For an account you're not sure about, lock it instead of deleting it: sudo usermod -L NAME (no password logins), sudo usermod -s /sbin/nologin NAME (no shell), and take away admin rights. If someone complains, you can give it back. Once you're sure, sudo userdel -r NAME removes it for good.

Try it: the previous admin's leftovers 🔎

You've just taken over this server. The previous admin said "it's all fine". Map the attack surface, find what doesn't belong, and shrink it.

Quick check

1. Your school's network has a server you think is badly configured. What should you do?

2. ss -tlnp shows 0.0.0.0:3306. What does that tell you?

3. You find a service nobody needs. What fully removes it from the attack surface?

Finished the missions and the quiz? Mark it done to track your progress.