Ravindra BagaleCourses & study guides मराठी Track your progress

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

  1. 23.1What Metasploit Is
  2. 23.2Starting msfconsole
  3. 23.3Search, Select and Configure a Module
  4. 23.4Running an Exploit and Getting a Session
  5. 23.5Meterpreter and Post-Exploitation
  6. 23.6msfvenom: Generating Payloads (Concept)
  7. 23.7Red vs Blue, Project and Real Incidents
  8. 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

MediumIT

Why: Metasploit is for authorised labs.

What: Exploit a free TryHackMe or Metasploitable VM you own.

How:

  1. Confirm written permission / room scope.
  2. msfconsole
  3. search the lab's suggested module
  4. 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
  1. You have a shell on the lab only.

23.2 Write a one-page exploit report

EasyBanking

Why: Reports matter more than shells.

What: Document the lab exploit.

How:

  1. Write: target, CVE/module, proof (whoami), impact, fix.
  2. Attach a screenshot of the session.

Expected output: A short report with fix steps.

Hint

Impact in plain English.

Answer / how to check
  1. A manager could understand the risk.

23.3 Match module to CVE (paper)

EasyRetail

Why: You must know what you are running.

What: Match each CVE to a Metasploit path in the data file.

Data file: modules.csv

CVEModule (fill)
CVE-2011-2523exploit/unix/ftp/vsftpd_234_backdoor
CVE-2010-2075exploit/unix/ftp/proftpd_133c_backdoor
CVE-2008-0166auxiliary/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:

  1. Look up each CVE name.
  2. 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
  1. 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)

  1. Write the lesson title, date and the exact lab target you are allowed to use.
  2. List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
  3. Run one safe check from the lesson on a lab system only. Paste the command and output.
  4. Write a two-sentence fix you would give a teammate.
  5. 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.