45. Practice Exercises with Hints
45.3 Linux on EC2 – Commands You Must Type Blind
Amazon Linux habit: sudo yum install, sudo service <name> start|stop|restart|status. Permissions, users, logs, processes – Blue daily bread.
| Exercise | Task | Hint |
|---|---|---|
| E1 | Install and start Nginx on Amazon Linux; prove status | sudo yum install nginx -y then sudo service nginx start and sudo service nginx status |
| E2 | Create user amir, add to wheel carefully, set chmod 400 on SSH key on client |
Never chmod 777 keys; ssh -i key.pem ec2-user@... from your PC |
| E3 | Find failed SSH logins in logs (path may vary) | /var/log/secure on Amazon Linux; sudo grep -i failed /var/log/secure \| tail |
| E4 | Explain why chmod 777 /var/www/html is a student favourite mistake |
World-writable web root = defacement / webshell drop easy |
| E5 | Write a one-line cron that runs a backup script at 02:00 (lab) | 0 2 * * * /home/ec2-user/backup.sh – test script path first |
| E6 | ss -tulnp or netstat – list listening ports; mark unexpected |
Blue baseline: know what should listen |
| Red team (attacker) does | Blue team (defender) detects / stops |
|---|---|
| Brutes SSH on open port 22 from internet | Key-only SSH; fail2ban; SG allow your IP; no password auth |
| Looks for world-writable web dirs after foothold | Correct ownership; no 777; file integrity / package verify |
Ravindra Bagale's Tip
Students write systemctl start and get confused with the Amazon Linux notes. In this book, service control = sudo service. For enabling at boot, sudo systemctl enable is OK. Keep this in mind.
Ravindra Bagale's Tip – मराठी
Students systemctl start लिहून Amazon Linux notes मध्ये गोंधळतात. या book मध्ये service control = sudo service. Boot enable साठी sudo systemctl enable OK. लक्षात ठेवा.
Ravindra Bagale's Tip – हिंदी
Students systemctl start लिखकर Amazon Linux notes में उलझ जाते हैं. इस book में service control = sudo service. Boot enable के लिए sudo systemctl enable OK. ध्यान रखो.
Lab
On OWN Free Tier Amazon Linux: install httpd, sudo service httpd start, open SG 80 from your IP, browse Elastic IP. Then sudo service httpd stop and confirm site down. Notes: 6 command lines + screenshot.
Extended teaching notes
Why this lesson matters
Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.
Apply the fix across stacks
Same class of bug, same idea in every language.
Java / Spring Boot
Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.
ASP.NET Core
EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.
Node.js / Express
helmet, parameterised SQL, npm audit, avoid eval and shell concat.
Python / Django / Flask / FastAPI
ORM, autoescape, pip-audit, Bandit; never shell=True with user input.
PHP / Laravel
PDO/Eloquent, Blade escaping, composer audit.
Go / Ruby
database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.
nginx / Apache / Tomcat
Hide versions, TLS, security headers, least-open ports.
MySQL / PostgreSQL / MongoDB / Redis
Private networks, auth on, least-privilege users, no 0.0.0.0/0.
AWS / Azure / GCP
Roles not long-lived keys, private data stores, cloud audit logs on.
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.