Lab 4 of 8 · Incident response
Catch a simulated attack and write the report
Simulate a password-guessing attack against your own login service, detect it, contain it by blocking the address, and write the incident report.
- Time
- 60–90 minutes
- Cost
- Free.
What you learn
When an alert fires, a calm, repeatable process matters more than heroics: confirm it, contain it, fix the cause, and write down what happened so it does not happen again.
- The incident response lifecycle (prepare, detect, contain, eradicate, recover, learn)
- Triage: is this alert real?
- Containment without destroying evidence
- Writing a clear incident report and timeline
In the AI era: AI can draft a timeline from logs in seconds. The analyst's job is to check every line against the evidence before anyone acts on it.
Before you start
Finish lab 3.
Only test systems you own or that are built for practice. Scanning or attacking anyone else's system without written permission is illegal in most countries.
Step by step
1 Start the service
Use the first terminal and keep it running.
flask --app login_app run --port 50012 Create some normal traffic
Real logs are mostly normal. In a second terminal, add a successful login and one typo.
curl -s -X POST http://127.0.0.1:5001/login -H "content-type: application/json" -H "X-Forwarded-For: 192.0.2.10" -d '{"user": "alex", "password": "correct-horse-battery-staple"}' curl -s -X POST http://127.0.0.1:5001/login -H "content-type: application/json" -H "X-Forwarded-For: 192.0.2.10" -d '{"user": "alex", "password": "correct-horse-battery"}'3 Simulate the attack
This pretends to be an attacker at 203.0.113.50 (an address reserved for documentation) trying common passwords against your own service.
for guess in 123456 password qwerty letmein admin welcome monkey dragon; do curl -s -o /dev/null -w "%{http_code} " -X POST http://127.0.0.1:5001/login -H "content-type: application/json" -H "X-Forwarded-For: 203.0.113.50" -d "{\"user\": \"alex\", \"password\": \"$guess\"}" done; echoYou should see:401eight times.4 Detect it
Run your rule from lab 3 over the log.
python detect.pyYou should see:One
brute_force_loginalert for203.0.113.50, and none for 192.0.2.10.5 Triage: did the attacker get in?
Check for any successful login from the attacker's address. This is the most important question in the whole incident.
grep '"ip": "203.0.113.50"' logs/auth.log | grep -c login_failure grep '"ip": "203.0.113.50"' logs/auth.log | grep -c login_success || trueYou should see:8failures and0successes: the account was not compromised.6 Contain: block the address
Stop the service with Ctrl+C, restart it with the attacker blocked, and confirm the block works. Keep the log file: it is evidence.
BLOCKED_IPS=203.0.113.50 flask --app login_app run --port 5001 # in the second terminal: curl -s -X POST http://127.0.0.1:5001/login -H "content-type: application/json" -H "X-Forwarded-For: 203.0.113.50" -d '{"user": "alex", "password": "123456"}'You should see:{"error":"blocked"}.7 Write the incident report
Fill in every section from your own logs and alert. Use exact times from
logs/auth.log.# Incident 001: password guessing against the login service | Field | Value | |-------|-------| | Severity | High (no compromise) | | Status | Contained | | Detected by | Rule brute_force_login (detect.py) | | Affected account | alex | | Source address | 203.0.113.50 | ## Summary In two or three sentences: what happened, what the impact was, what was done. ## Timeline (UTC) | Time | Event | |------|-------| | ... | First failed login from 203.0.113.50 | | ... | Alert raised (5th failure within 60 seconds) | | ... | Triage: 8 failures, 0 successes | | ... | Address blocked | ## Root cause The login service allows unlimited attempts. ## What went well / what to improve - ... ## Follow-up actions - [ ] Add rate limiting per address and per account - [ ] Require multi-factor authentication - [ ] Alert on any success after a burst of failures8 Commit and push
An incident report is one of the strongest portfolio pieces for a SOC analyst role.
git add reports git commit -m "Add incident report for simulated brute-force attack" git push
You are done when
Your rule caught the attack and ignored the normal user's typo.
You proved there was no successful login from the attacker.
The block works and your report has a timeline built from real log times.
We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.