Repository navigation
Expand file tree
/
Copy pathbuild-report.sh
More file actions
executable file
·50 lines (40 loc) · 1.9 KB
/
Copy pathbuild-report.sh
File metadata and controls
executable file
·50 lines (40 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
# Phase 6 of the Linux project in one go: builds sections 1 to 5 of the
# incident report straight from the log, so the evidence is copied exactly
# as the tools printed it. Section 6 is yours to write by hand afterwards.
#
# Usage: bash scripts/build-report.sh [path/to/auth.log] [path/to/report.txt]
# Default: ~/auth.log -> ~/incident-report.txt
#
# In the course you run these lines one at a time. That is still the way to
# learn it. This script is the cheat sheet version, to check your own work.
set -euo pipefail
LOG="${1:-$HOME/auth.log}"
REPORT="${2:-$HOME/incident-report.txt}"
ATTACKER="203.0.113.47"
if [ ! -f "$LOG" ]; then
echo "No log at $LOG. Download it first (Phase 4, first step)." >&2
exit 1
fi
# The only single > in the whole report. Everything after it is >>.
echo "INCIDENT REPORT - SSH brute force and account compromise" > "$REPORT"
echo "Prepared: $(date)" >> "$REPORT"
echo "" >> "$REPORT"
echo "1. SCALE - failed login attempts:" >> "$REPORT"
grep -c "Failed password" "$LOG" >> "$REPORT"
echo "" >> "$REPORT"
echo "2. SOURCE - top attacking addresses:" >> "$REPORT"
grep "Failed password" "$LOG" | grep -oE 'from [0-9.]+' | awk '{print $2}' | sort | uniq -c | sort -rn | head -n 3 >> "$REPORT"
echo "" >> "$REPORT"
echo "3. BREACH - successful login from the attacking address:" >> "$REPORT"
grep "$ATTACKER" "$LOG" | grep "Accepted" >> "$REPORT"
echo "" >> "$REPORT"
echo "4. IMPACT - attacker activity after access:" >> "$REPORT"
grep "sudo" "$LOG" >> "$REPORT"
echo "" >> "$REPORT"
echo "5. REMEDIATION - applied to this server:" >> "$REPORT"
echo "- Password and root login disabled for SSH (tested: password login refused)" >> "$REPORT"
echo "- Firewall enabled: deny all inbound, allow 22/tcp only" >> "$REPORT"
echo "- All packages patched to current versions" >> "$REPORT"
echo "Report written to $REPORT"
echo "Now add section 6 in your own words: nano $REPORT"