Skip to content

Security Operations / Host hardening · Step 1 of 10

Lesson: Attack SurfaceSwitch
← Security Operations

Security investigations

Attack Surface

Find the ways into a Linux host and remove the ones you do not need.

A host's attack surface is every place where someone could try to get in or gain more power. It includes network services, user accounts, installed software, scheduled jobs and physical access. A smaller surface means fewer things to patch, watch and get wrong.

Take an inventory

You cannot protect what you do not know about. Start with read-only commands.

$ ss -tuln
Netid State  Local Address:Port  Peer Address:Port
udp   UNCONN 127.0.0.53%lo:53         0.0.0.0:*
tcp   LISTEN       0.0.0.0:22         0.0.0.0:*

Columns are trimmed here. Then list running services on a systemd machine:

$ systemctl list-units --type=service --state=running
cron.service  loaded active running Regular background program processing daemon
ssh.service   loaded active running OpenBSD Secure Shell server

Installed packages are listed with apt list --installed on Debian and Ubuntu, or dnf list --installed on Fedora and RHEL.

Look at accounts and special files

$ awk -F: '$7 !~ /(nologin|false)$/ {print $1, $7}' /etc/passwd
root /bin/bash
sync /bin/sync
maria /bin/bash

This shows accounts whose shell does not obviously refuse logins. It does not prove they can log in.

Files with the setuid bit run with their owner's privileges:

$ find /usr -xdev -perm -4000 -type f
/usr/bin/passwd
/usr/bin/sudo

Many are expected. Compare against a fresh install and ask about any you cannot explain.

Reduce carefully

For each item ask: who needs it, and what breaks without it? If nobody needs a service, stop and disable it, then remove its package once you are sure.

$ sudo systemctl disable --now cups.service

--now stops it as well as preventing it starting at boot. Some services can still be started by a socket or another unit, so check again with ss. Change one thing at a time on a test system first, and note how to reverse it. Do not remove something just because the name is unfamiliar.

Repeat the inventory later. New packages can quietly add services.

Try it

On a Linux machine you own, save the output of ss -tuln and the running service list to a file. Write one reason for every listening port. The processes lab is a safe place to explore what is running.

Check your understanding

Attack Surface

All 3 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.