Lab exercises: System administration & privileges
On this page
- Exercise 1: Read the account files
- Exercise 2: Create a user and group
- Exercise 3: The -aG trap
- Exercise 4: Octal and symbolic permissions
- Exercise 5: Ownership
- Exercise 6: SUID audit (privilege-escalation reconnaissance)
- Exercise 7: Simulated privesc via a SUID binary (safe, self-contained)
- Exercise 8: sudoers enumeration
- Exercise 9: Process management
- Exercise 10: Service management
- Cleanup: remove everything this lab created
- Scorecard
These exercises create throwaway users, groups, and files, then walk through
permission changes, a simulated SUIDA special permission bit that makes a program run as the file's owner, often root, whoever starts it. A SUID program with a flaw is a classic privilege escalation path. privilege-escalation audit, and service
management. Run them as the normal user kali in the practice lab
(./scripts/setup-lab-env.sh user-shell, sudoRuns a single command as another user, usually root, if /etc/sudoers allows it, and logs that it happened. password kali) or on a
disposable Kali VM, never on a machine you care about. A cleanup section at the
end removes everything, and ./scripts/setup-lab-env.sh reset gives you a
fresh lab box.
Your prompt should end in
$, not#. If it ends in#you are root, and exercise 1 will fail. You'll needsudo. Confirm first:sudo -v && echo "sudo OK"
Exercise 1: Read the account files#
Goal: Locate your own line in /etc/passwd and confirm /etc/shadow is a
privilege boundary.
grep "^$(whoami):" /etc/passwd
sudo grep "^$(whoami):" /etc/shadow # works with sudo
cat /etc/shadow # Permission denied, expected
Self-grade:
if cat /etc/shadow >/dev/null 2>&1; then
echo "FAIL: /etc/shadow is readable by you, that's a misconfiguration!"
else
echo "PASS: /etc/shadow is protected from non-root users"
fi
Exercise 2: Create a user and group#
Goal: Create user analyst with a home dir and bash shell, plus a
pentesters group, and put analyst in it.
sudo groupadd pentesters
sudo useradd -m -s /bin/bash analyst
echo 'analyst:Lab-Passw0rd!' | sudo chpasswd # scriptable password set
sudo usermod -aG pentesters analyst
id analyst
Self-grade:
id analyst | grep -q "pentesters" && \
[ -d /home/analyst ] && \
echo PASS || echo "FAIL: check user creation / group / home dir"
Exercise 3: The -aG trap#
Goal: Understand why usermod -G without -a is dangerous, do this
safely by observing, not by breaking your own account.
# analyst is currently in: analyst, pentesters
id analyst
# Add to 'sudo' the CORRECT way (append):
sudo usermod -aG sudo analyst
id analyst
# Observe: analyst is now in analyst, pentesters, AND sudo.
# If we had run 'usermod -G sudo analyst' (no -a), analyst would be in ONLY
# sudo, silently removed from pentesters. Never omit -a.
Self-grade:
groups analyst | grep -q pentesters && groups analyst | grep -q sudo \
&& echo "PASS: both groups retained (you used -aG)" \
|| echo "FAIL: analyst lost a group, did you forget -a?"
Exercise 4: Octal and symbolic permissions#
Goal: Create files and set precise modes both ways.
cd /tmp
touch key.pem public.txt deploy.sh
chmod 600 key.pem # rw-------
chmod 644 public.txt # rw-r--r--
chmod +x deploy.sh # add execute for all
ls -l key.pem public.txt deploy.sh
stat -c '%A %n' key.pem public.txt deploy.sh
Self-grade:
k=$(stat -c '%a' key.pem); p=$(stat -c '%a' public.txt)
[ "$k" = "600" ] && [ "$p" = "644" ] && echo PASS || echo "FAIL: modes are $k / $p"
Exercise 5: Ownership#
Goal: Give a file to analyst:pentesters.
cd /tmp
sudo touch shared-report.txt
sudo chown analyst:pentesters shared-report.txt
ls -l shared-report.txt
Self-grade:
owner=$(stat -c '%U:%G' shared-report.txt)
[ "$owner" = "analyst:pentesters" ] && echo PASS || echo "FAIL: owner is $owner"
Exercise 6: SUID audit (privilege-escalation reconnaissance)#
Goal: Enumerate SUID binaries and reason about which are dangerous.
# Baseline the SUID set (defenders do this on a clean box)
find / -perm -4000 -type f 2>/dev/null | tee /tmp/suid.list
wc -l /tmp/suid.list
# Expected legitimate entries include: passwd, sudo, su, mount, umount, chsh
grep -E "passwd|sudo|su$" /tmp/suid.list
Self-grade:
grep -q "/usr/bin/sudo" /tmp/suid.list \
&& echo "PASS: found expected SUID binaries, now compare against GTFOBins" \
|| echo "FAIL: sudo should be SUID; re-run the find"
Think it through: if find, vim, nmap, bash, or cp appeared as
SUID-root, an attacker could leverage it to become root. Look each one up on
GTFOBins to see the exact exploitation payload.
Exercise 7: Simulated privesc via a SUID binary (safe, self-contained)#
Goal: Demonstrate the concept in a sandbox so you understand why SUID
misconfiguration is fatal. We make a harmless copy of bash SUID-root, show it
grants a root shell, then remove it immediately.
Only in the lab box or your own Kali VM, never on a shared or production machine. For the few minutes it exists, any local user can become root with it.
We use
/optrather than/tmpbecause many systems mount/tmpwith thenosuidoption, which makes the kernel silently ignore the SUID bit (check withfindmnt -no OPTIONS /tmp). That's also a real defense worth knowing: mounting world-writable directoriesnosuidkills this whole technique.
# Setup (as root): create a deliberately-vulnerable SUID bash copy
sudo cp /bin/bash /opt/rootbash
sudo chmod 4755 /opt/rootbash # SUID + rwxr-xr-x
ls -l /opt/rootbash # note the 's' in -rwsr-xr-x
# Exploit (as a NORMAL user): -p preserves the elevated privileges
/opt/rootbash -p -c 'id' # prints uid=1000 ... euid=0(root)!
Expected:
uid=1000(kali) gid=1000(kali) euid=0(root) groups=1000(kali),27(sudo)
The euid=0(root) proves you executed code as root from an unprivileged account, exactly what an attacker wants.
Self-grade:
/opt/rootbash -p -c 'id -u' 2>/dev/null | grep -q '^0$' \
&& echo "PASS: SUID bash yielded euid 0, lesson learned" \
|| echo "FAIL: setup didn't take (check chmod 4755)"
Clean up this landmine immediately:
sudo rm -f /opt/rootbash
echo "Removed the SUID bash. Never leave one of these on a real system."
Exercise 8: sudoers enumeration#
Goal: See what your accounts can do via sudo.
sudo -l # your rights
sudo -l -U analyst # analyst's rights (run as root)
cat /etc/sudoers.d/* 2>/dev/null
Self-grade (manual): Confirm you can explain, in one sentence each, what the run-as user, allowed hosts, and command list mean in any rule shown.
Exercise 9: Process management#
Goal: Start a background process, find it, signal it politely, then force it.
sleep 600 & # background a long sleep; note the [job] PID
jobs -l # list background jobs with PIDs
ps aux | grep "[s]leep 600" # the [s] trick hides grep from its own results
PID=$(pgrep -n -f "sleep 600") # -n = newest match, in case an old one is around
echo "sleep PID is $PID"
kill "$PID" # SIGTERM
Self-grade:
sleep 0.5
kill -0 "$PID" 2>/dev/null && echo "FAIL: still running" || echo "PASS: process terminated"
Exercise 10: Service management#
Goal: Query, start, and inspect a service. This uses ssh, which the lab box
has installed (on your own Kali, sudo apt install openssh-server first).
On a full Kali VM, systemdThe service manager on most Linux systems, controlled with systemctl (start, stop, enable services) and journalctl (logs). manages services:
systemctl status ssh --no-pager || true
sudo systemctl start ssh
systemctl is-active ssh
journalctl -u ssh --since "5 min ago" --no-pager | tail -n 5
The lab box is a container with no systemd, so systemctl there prints
System has not been booted with systemd as init system (PID 1). Can't operate.
Use the older service wrapper instead, which runs the same start script:
service --status-all # [ + ] running, [ - ] stopped
sudo service ssh start
service ssh status
Expected output in the lab:
[ - ] procps
[ - ] ssh
[ - ] sudo
Starting OpenBSD Secure Shell server: sshd.
sshd is running.
Self-grade (works on both):
if [ -d /run/systemd/system ]; then
systemctl is-active ssh 2>/dev/null | grep -qx "active" && echo "PASS: ssh is active" || echo "FAIL: run sudo systemctl start ssh"
else
service ssh status >/dev/null 2>&1 && echo "PASS: ssh is running" || echo "FAIL: run sudo service ssh start"
fi
Cleanup: remove everything this lab created#
sudo systemctl stop ssh 2>/dev/null || sudo service ssh stop 2>/dev/null
sudo userdel -r analyst 2>/dev/null
sudo groupdel pentesters 2>/dev/null
sudo rm -f /tmp/key.pem /tmp/public.txt /tmp/deploy.sh /tmp/shared-report.txt \
/opt/rootbash /tmp/suid.list
echo "Lab 02 artifacts removed."
Scorecard#
| # | Skill demonstrated |
|---|---|
| 1 | Reading /etc/passwd / /etc/shadow; the privilege boundary |
| 2 | useradd -m -s, groupadd, chpasswd, usermod -aG |
| 3 | Why -aG (append) not -G (replace) |
| 4 | Octal + symbolic chmod |
| 5 | chown user:group |
| 6 | SUID enumeration + baselining |
| 7 | Concrete SUID privesc (and safe cleanup) |
| 8 | sudo -l sudoers enumeration |
| 9 | Background jobs, pgrep, kill |
| 10 | systemctl / journalctl, or service without systemd |
All PASS and you're ready for module 03, Network recon & Nmap.