Skip to content

About

TechTwoForty: Linux. The finished Compromised Server project, a template and cheat sheet.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TechTwoForty: Linux

TechTwoForty: Linux

The Compromised Server · the finished project

Course map · Next: Scripting →

Tip

This repo is the finished template for the Linux project. Treat it as your cheat sheet. It shows what you should have when you reach the end of the walkthrough: the incident report, the SSH settings file and the server state. Do the project yourself first, then come here to compare, unstick a step or check your report.

Section 1 of 10 · Linux, Sections 1 to 9
Time About 90 minutes, 6 phases
Runs on Your Ubuntu VM. Nothing here touches your real computer
Deliverable ~/incident-report.txt: names the attacker, proves the break-in, records the fix

The big picture

TechTwoForty Linux: the break-in on the left, your hardened server on the right, the report at the bottom

Drawn in Excalidraw. To edit it, open assets/diagram.excalidraw at excalidraw.com.

What is in this repo

TechTwoForty-Linux/
├── incident-report.txt        The finished deliverable, built from the real log
├── evidence/
│   └── auth-sample.log        The 126-line log you investigate in Phase 4
├── config/
│   └── hardening.conf         What goes in /etc/ssh/sshd_config.d/hardening.conf
└── scripts/
    ├── build-report.sh        Phase 6 in one go: sections 1 to 5 of the report
    └── handover-check.sh      The final handover check, as PASS / FAIL lines

Check your own work on the VM when you think you are finished:

bash scripts/handover-check.sh

It only reads, and changes nothing. It asks for sudo once.

Cheat sheet, phase by phase

Phase 1 · Take stock

Find out what you are holding before you change anything.

whoami && id
fastfetch
ps aux | wc -l
ps aux --sort=-%cpu | head -n 6
sudo ss -tlnp
ls -l /var/log

You should see: your groups, the Ubuntu version, a process count, five busy processes, almost no listening ports (maybe 127.0.0.53), and auth.log in /var/log. An empty ss list is a good result.

Phase 2 · Set the workspace right

A team group, a user, a shared folder only the team can use, and a locked-down key.

sudo groupadd engineers
sudo useradd -m -s /bin/bash -G engineers alice
id alice
sudo mkdir -p /srv/shared && sudo chown root:engineers /srv/shared
sudo chmod 2770 /srv/shared && ls -ld /srv/shared
sudo -u alice touch /srv/shared/alice-was-here.txt
ls -l /srv/shared                 # Permission denied, which is correct
sudo ls -l /srv/shared            # alice-was-here.txt, group engineers
echo "PRETEND PRIVATE KEY - not a real one" > ~/deploy.key
chmod 600 ~/deploy.key && ls -l ~/deploy.key
Check Expected
ls -ld /srv/shared drwxrws--- root engineers
ls -l ~/deploy.key -rw-------
The 2 in 2770 The setgid bit: new files inherit the engineers group

Phase 3 · Patch the machine

sudo apt update
apt list --upgradable | wc -l     # write this number down
sudo apt upgrade -y
apt list --upgradable | wc -l     # 1: just the header line

apt update refreshes the list of what is available. apt upgrade installs it.

Phase 4 · Investigate the break-in

The heart of the project. Every tool is from section 4.

wget https://raw.githubusercontent.com/SoftReb00t/Linux-Project/main/auth-sample.log -O ~/auth.log
wc -l ~/auth.log                                   # 126
grep -c "Failed password" ~/auth.log               # 115
grep "Failed password" ~/auth.log | grep -oE 'from [0-9.]+' | awk '{print $2}' | sort | uniq -c | sort -rn
grep "Accepted" ~/auth.log
grep "203.0.113.47" ~/auth.log | tail -n 5
grep "sudo" ~/auth.log

The answers, from the real log in evidence/auth-sample.log:

Question Answer
How much is failed logins? 115 of 126 lines. Automated attack traffic
Who is doing it? 203.0.113.47 with 102, then 192.0.2.146 with 9, then 10.0.0.9 with 4
Did they get in? Yes. 12:45:09 Accepted password for admin from 203.0.113.47
What did they do? 12:46:02 sudo ... COMMAND=/usr/bin/cat /etc/shadow. Every password hash copied

Important

The sudo line turns "someone logged in" into credential theft. Every password on that machine must be treated as stolen.

Phase 5 · Lock the front door

They got in with a password, so passwords go. Then a firewall in front.

sudo apt install -y openssh-server
sudo ss -tlnp | grep 22
printf 'PermitRootLogin no\nPasswordAuthentication no\nPubkeyAuthentication yes\n' | sudo tee /etc/ssh/sshd_config.d/hardening.conf
sudo sshd -t                       # silence means the config is valid
sudo systemctl restart ssh && sudo systemctl status ssh --no-pager | head -n 5
ssh alice@localhost                # Permission denied (publickey)
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp              # allow SSH BEFORE you enable
sudo ufw enable
sudo ufw status verbose

The finished settings file is in config/hardening.conf. Two locks now: the firewall decides who may knock, SSH decides who may come in.

Phase 6 · Write it up

Build the report from the terminal so the evidence is copied exactly. One > to start the file, then >> every time after.

The full sequence is in scripts/build-report.sh, and the finished result is incident-report.txt. Section 6 is the part no command can write: three or four plain sentences with your conclusion and recommendation.

Final handover check

  • ~/incident-report.txt exists and reads cleanly from top to bottom
  • ls -l /srv/shared shows alice's file with the engineers group
  • ls -l ~/deploy.key shows -rw-------
  • apt list --upgradable | wc -l returns 1
  • ssh alice@localhost is refused without a password prompt
  • sudo ufw status verbose shows deny incoming and one rule for 22/tcp
  • You can explain the whole incident out loud in under a minute

Common mistakes

Mistake What happens The fix
A single > after the first line of the report The report is wiped >> every time after the first line
ufw enable before ufw allow 22/tcp On a remote server you lock yourself out Allow first, then enable
Restarting SSH without sshd -t A typo takes SSH down Test the config, then restart
Downloading the GitHub page instead of the raw file You get HTML, not the log Use the raw.githubusercontent.com address
Switching passwords off on a real server before keys work Locked out for good On a real server, prove key login first

What you can now do

  • Reconnaissance: work out what an unfamiliar machine is, what runs on it and what it exposes
  • Access control: groups, users, setgid folders and correct private key permissions
  • Patch management: count what is out of date, fix it and prove the count went down
  • Log analysis: turn a big auth log into one specific, evidenced answer
  • Incident response: find the intrusion, work out the impact, fix the cause
  • Server hardening: SSH settings and a default-deny firewall, layered and tested
  • Reporting: an incident write-up with evidence and a recommendation

TechTwoForty · Linux · 1 of 10
Course map · Next: Scripting →

About

TechTwoForty: Linux. The finished Compromised Server project, a template and cheat sheet.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages