26. Privilege Escalation
Chala mitrano, ata ek mahatvacha tappa. Attacker system madhe shirto tevha bahutek to ek saamanya user mhanun aat yeto – limited power. Pan tyala pahije root (Linux) kiwa Administrator (Windows) – purna control. Ha janya cha marg mhanje privilege escalation – kami adhikaratun jast adhikar milavne. Aaj aapan shiku he kase hote (misconfigurations, weak permissions), Linux var linPEAS ne kase shodhaycha, ani – jsa nehmi – ha attack thambavaycha kasa. Sagle fakt Metasploitable 2 ani tumchya lab VM var. Samjla ka? Chala!
What you will learn in this chapter
- What privilege escalation is: vertical vs horizontal
- Common Linux escalation paths: sudo misconfig, SUID binaries, cron jobs, weak permissions, kernel exploits
- Manual enumeration commands you run first
- linPEAS and LinEnum: automated enumeration
- A note on Windows escalation
- Defences: least privilege, patching, correct permissions, auditing
Lab scope for this whole chapter
Practice escalation only on Metasploitable 2 or your own lab VMs where you already have a shell (for example from Chapter 23). Escalating privileges on any system you are not authorised to test is a crime under the IT Act.
Concepts in this chapter
- 26.1What Privilege Escalation Is
- 26.2Manual Linux Enumeration
- 26.3Common Escalation Paths
- 26.4Automated Enumeration: linPEAS and LinEnum
- 26.5A Note on Windows Escalation
- 26.6Defending Against Privilege Escalation
- 26.7Red vs Blue, Project and Real Incidents
The chapter recap is at the end of the last concept page.
Chapter 26: Privilege escalation — practice tasks
Open chapter lessons · Full guided lab: audit sudo rights suid files (not repeated here)
26.1 List your sudo rights
EasyITWhy: Too much sudo is a common finding.
What: See what your user can run as root.
How:
sudo -l- Note any NOPASSWD or wildcards.
Expected output: A short list of allowed commands.
Hint
Prefer named commands over ALL.
Answer / how to check
- If you see (ALL) ALL, tighten it in a lab.
26.2 Find SUID binaries
MediumBankingWhy: Unexpected SUID files are a classic escalate path.
What: List SUID files and spot odd ones.
How:
find / -perm -4000 -type f 2>/dev/null- Compare with a clean Ubuntu list.
Expected output: Known tools like passwd, sudo; no random /tmp binaries.
Hint
Investigate anything under /home or /tmp.
Answer / how to check
- No unknown SUID under /tmp.
26.3 Capabilities check
MediumHealthcareWhy: Capabilities can replace full root.
What: List files with capabilities.
How:
getcap -r / 2>/dev/null- Note any with cap_setuid or cap_sys_admin.
Expected output: Usually few entries (ping, etc.).
Hint
Unexpected caps = finding.
Answer / how to check
- You wrote which binaries have caps.
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.