17. Why Learn All This Before Kali Linux?
17.3 From Linux and SSH to Brute Force, Privilege Escalation and Hardening
Kali swatah Linux aahe – aani bahutek targets pan Linux servers aahet. Part 2 che commands attack aani defence donhi madhe roj lagtat.
| You learnt (Part 2) | Attack side | Defence side |
|---|---|---|
SSH, key pairs, chmod 400 |
Hydra password brute force against SSH | Key-only login, PasswordAuthentication no, fail2ban |
Users, groups, sudo |
Privilege escalation (विशेषाधिकार वाढ) via weak sudo rules |
Least privilege, review sudo -l |
Permissions, SUID, find |
find / -perm -4000 to hunt SUID binaries |
Remove unnecessary SUID bits, correct ownership |
Processes, services, ss |
Finding vulnerable services running as root | Disable unused services |
Logs, grep, awk |
Attackers try to clear logs | Reading /var/log/secure or auth.log to detect attacks |
| cron | Persistence through cron jobs | Auditing crontabs |
| Package management | Exploiting outdated software | sudo yum update / sudo apt upgrade regularly |
sudo grep "Failed password" /var/log/secure | tail # Amazon Linux: failed SSH logins
sudo grep "Failed password" /var/log/auth.log | tail # Ubuntu
sudo -l # what can this user run as root?
Why this matters for security
Tools like linPEAS only list possible weaknesses; you must understand Linux permissions to know which findings are real. The same knowledge makes you a good defender: every hardening step in Part 11 (SSH config, fail2ban, firewall, updates) is a Linux command you already know.
Ravindra Bagale's Tip
If your EC2 instance is on the internet, open /var/log/secure once – even without you doing anything, you'll see many "Failed password" attempts. These are bots. Students panic – don't panic! If SSH is key-only and port 22 is open only to your IP, these attempts are useless. This is the first lesson of "defence".
Ravindra Bagale's Tip – मराठी
तुमचा EC2 internet वर असेल तर /var/log/secure एकदा उघडा – तुम्ही काही न करता पण अनेक "Failed password" attempts दिसतील. हे bots आहेत. Students घाबरतात – घाबरू नका! Key-only SSH आहे आणि port 22 फक्त तुमच्या IP ला open आहे तर हे attempts निरुपयोगी आहेत. हाच "defence" चा पहिला धडा.
Ravindra Bagale's Tip – हिंदी
तुम्हारा EC2 internet पर है तो एक बार /var/log/secure खोलो – तुम्हारे कुछ किए बिना भी कई "Failed password" attempts दिखेंगे. ये bots हैं. Students घबरा जाते हैं – घबराओ मत! SSH key-only है और port 22 सिर्फ़ तुम्हारे IP के लिए open है तो ये attempts बेकार हैं. यही "defence" का पहला सबक है.
Practice task
On your EC2 instance, count failed SSH attempts with grep and wc -l, list the top source IPs with awk and sort | uniq -c, and check sshd_config for PasswordAuthentication.
Extended teaching notes
Why this lesson matters
Hardening is deleting unnecessary risk: fewer packages, fewer open ports, fewer privileged accounts, faster patches, better logs.
Hardening related services
[('SSH', 'Key auth, no root login, Fail2ban or equivalent, SG limited to your IP/VPN.', '', ''), ('SMB / NFS / LDAP / SNMP', 'Do not expose to the internet; patch; strong auth; disable unused versions (e.g. SMBv1).', '', ''), ('SMTP', 'Authenticated relay only; SPF/DKIM/DMARC for your domains.', '', ''), ('DNS', 'Restrict zone transfers; monitor for unexpected records (crt.sh for certs).', '', ''), ('Firewalls', 'Host firewall + cloud SG/NSG; default deny; document every allow.', '', '')]
Real examples
Global: CIS Benchmarks exist for Linux, Windows and clouds. Indian company (sample): a Pune team requires SSH keys only and weekly patch windows for internet-facing hosts.
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.