Practice library / Security operations basics
Lab · Medium · 1.5 hoursFree account
Linux Forensics
Disk acquisition, filesystem timeline, log analysis, and bash history forensics.
On this page 13 sections
- ·Prerequisites
- ·Lab Setup
- 1Hash the image and mount it read-only
- 2Find the brute-force attack
- Locked: Read the login records and the sudo commands
- Locked: Find accounts that should not exist
- Locked: Hunt for persistence
- Locked: Read the shell history
- Locked: Build a timeline
- Locked: Verify the evidence is unchanged
- Locked: Defence and Detection
- Locked: Check Your Work
- Locked: Clean-up
Linux runs a large share of internet servers and cloud workloads, so responders often meet a Linux compromise. Working from the disk image of a compromised web server, you hash and mount the disk read-only, hunt a brute-force login in auth.log, uncover a hidden UID 0 account and cron-based persistence, and rebuild the attacker's timeline from filesystem metadata.
Lab Objectives
- Hash a disk image and mount it read-only so the evidence does not change
- Find a brute-force attack and the first successful login in
auth.log - Find a hidden account with UID 0 in
/etc/passwd - Find persistence in cron, SSH keys and temporary directories
- Rebuild the order of events as a filesystem timeline
- Write down findings with the evidence behind each one
A server that serves web pages is a common target, and the first question after an alert is always the same: what did the attacker do, and when? On Linux the answer is spread over a few places: the logs, the account files, the scheduled jobs and the file timestamps. This lab teaches you to read each of them from a copy of the disk, so that your work does not change the evidence.
You work as a defender. Every command in this lab only reads data.
Prerequisites
Finish the Digital Forensics & Incident Response workbook first. It explains evidence, chain of custody and the order of volatility, which this lab applies.
This lab covers the disk. For the memory of a running system, continue with Memory Forensics with Volatility.
Lab Setup
Use your own Kali machine: a virtual machine is fine. You need these tools; all are in a default Kali install:
sha256sum,mount,grep,awkandfind(packagecoreutils,util-linux,gawk,findutils).last(packageutil-linux) to read the binary login records.
This lab is a guided walk-through of real output. KaliRange gives no sample disk image. To do the steps yourself, bring a raw disk image of a server (web01.img, one ext4 filesystem, named web01 below) that you compromised yourself in your own lab and that you have permission to analyse, and replace the file name and dates in the commands. The example output below shows what such a case looks like.
Analyse only a disk image that you own or have written permission to analyse. On a real case you work on a copy of the evidence, you have written permission, and you keep a record of who handled the image. Never mount an original disk with write access.
Step 1: Hash the image and mount it read-only
Prove the evidence does not change
A hash is a fingerprint of a file. If the hash is the same at the start and at the end, nobody changed the image. Record the hash before you do anything else.
Hash the image and save the value.
cd ~
sha256sum web01.img | tee web01.img.sha256Example output:
2d711642b726b04401627ca9fbac32f5c8530fb1903cc4db02258717921a4881 web01.imgMount the image read-only. The option noload stops the kernel from replaying the ext4 journal, which would write to the image.
sudo mkdir -p /mnt/evidence
sudo mount -o ro,loop,noload web01.img /mnt/evidence
ls /mnt/evidenceExample output:
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr varFrom now on, /mnt/evidence is the root directory of the target. Every path below starts with it.
Step 2: Find the brute-force attack
Read the SSH authentication log
/var/log/auth.log records every SSH login, failed or accepted, and every sudo command. A burst of failures from one address, followed by a success, is the classic sign of a password-guessing attack that worked.
Count the failed logins by source address.
cd /mnt/evidence/var/log
grep 'Failed password' auth.log | awk '{for(i=1;i<=NF;i++) if($i=="from") print $(i+1)}' | sort | uniq -c | sort -rnExample output:
5 10.0.0.50Show every accepted login.
grep 'Accepted' auth.logExample output:
Nov 12 01:58:13 web01 sshd[2221]: Accepted password for deploy from 10.0.0.50 port 40168 ssh2
Nov 12 02:09:22 web01 sshd[2301]: Accepted publickey for deploy from 10.0.0.50 port 40590 ssh2Look at the two lines. The first login used a password, 10 seconds after the last failure. The second login, 11 minutes later, used a public key. The attacker now has a way in that does not need the password. Step 5 shows where that key came from.
Check the time zone of the log. Log times use the local time of the server.
cat /mnt/evidence/etc/timezoneExample output:
Etc/UTCSign in to continue
9 more sections are for signed-in members. It is free: sign in with Google.
This lab is extra practice for the course Security operations basics. Do the lessons first.Open the course