23. Exploitation with Metasploit
Chala mitrano, aaj tya toolchi vel aali jyacha naav aikun sagle utsahit hotat – Metasploit. Pan ek goshta pakki lakshat theva: Metasploit mhanje "button daba, hack ho jato" asa nahi. To ek framework aahe – shodhlelya vulnerability cha (Chapter 20) fayda ghenyacha ek vyavasthit marg. Aapan aadhi to kasa kaam karto te samju, mag Metasploitable 2 var ek khara exploit chalvun baghu, aani sarvat mahatvacha – defender ha attack logs madhe kasa pakadto te pahu. Sagle fakt tumchya lab var. Samjla ka? Chala!
What you will learn in this chapter
- What the Metasploit Framework is and its main parts (exploit, payload, module, session)
- Starting msfconsole and the core commands
- Searching, selecting and configuring a module
- Running an exploit against Metasploitable 2 and getting a session
- Meterpreter basics and post-exploitation (lab only)
- msfvenom for generating standalone payloads (concept)
- How defenders detect and stop this
Lab scope for this whole chapter
Every command here targets only Metasploitable 2 (192.168.56.20) on your host-only lab. Running an exploit against any machine you do not own is a serious crime (IT Act s. 66, and s. 70 for protected systems). Take a snapshot before you start.
Concepts in this chapter
- 23.1What Metasploit Is
- 23.2Starting msfconsole
- 23.3Search, Select and Configure a Module
- 23.4Running an Exploit and Getting a Session
- 23.5Meterpreter and Post-Exploitation
- 23.6msfvenom: Generating Payloads (Concept)
- 23.7Red vs Blue, Project and Real Incidents
- 23.8Persistence: How Attackers Keep Access
The chapter recap is at the end of the last concept page.
Chapter 23: Exploitation with Metasploit — practice tasks
Open chapter lessons · Full guided lab: plan safe practice lab scope (not repeated here)
23.1 Launch Metasploit against a legal lab only
MediumITWhy: Metasploit is for authorised labs.
What: Exploit a free TryHackMe or Metasploitable VM you own.
How:
- Confirm written permission / room scope.
msfconsole- search the lab's suggested module
- set RHOSTS to your lab IP; run.
Expected output: Session opens on the lab VM.
Hint
Never point Metasploit at the internet.
Answer / how to check
- You have a shell on the lab only.
23.2 Write a one-page exploit report
EasyBankingWhy: Reports matter more than shells.
What: Document the lab exploit.
How:
- Write: target, CVE/module, proof (whoami), impact, fix.
- Attach a screenshot of the session.
Expected output: A short report with fix steps.
Hint
Impact in plain English.
Answer / how to check
- A manager could understand the risk.
23.3 Match module to CVE (paper)
EasyRetailWhy: You must know what you are running.
What: Match each CVE to a Metasploit path in the data file.
Data file: modules.csv
| CVE | Module (fill) |
|---|---|
| CVE-2011-2523 | exploit/unix/ftp/vsftpd_234_backdoor |
| CVE-2010-2075 | exploit/unix/ftp/proftpd_133c_backdoor |
| CVE-2008-0166 | auxiliary/scanner/ssh/ssh_enumerate_users (example) |
About this file: Made-up matching exercise. Each row is one CVE. Columns: CVE = ID; Module = Metasploit path to fill or check.
How:
- Look up each CVE name.
- Match the module path.
Expected output: CVE-2011-2523 → vsftpd_234_backdoor; others as listed.
Hint
search CVE-xxxx inside msfconsole.
Answer / how to check
- Every row has a correct path.
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.