Penetration testing (pen testing) is a simulated cyberattack against computer systems, networks, applications, or APIs to identify security vulnerabilities that could be exploited by attackers. Pen testers (ethical hackers) use the same tools and techniques as malicious actors but operate with explicit authorization. Pen testing helps organizations discover weaknesses before attackers do, prioritize remediation, and comply with regulatory requirements (PCI DSS, HIPAA, SOC2, ISO 27001).
Market Size: Global penetration testing market size: $2.5 billion (2024). 85% of organizations conduct external pen tests annually. 70% conduct internal network pen tests. Average cost of pen test: $10,000-$50,000 (external), $20,000-$100,000 (internal).
Common penetration testing types:
Passive information gathering: DNS enumeration (dig, nslookup), WHOIS, Google dorks, Shodan, social media OSINT, data breaches (HaveIBeenPwned). No direct interaction with target.
Active scanning: Nmap port scans, service version detection, vulnerability scanning (Nessus, OpenVAS), directory brute-forcing (gobuster, dirb), subdomain enumeration.
Exploit vulnerabilities (Metasploit, manual exploitation). Gain initial foothold (reverse shell, web shell). Examples: SQL injection, XSS, RCE, buffer overflow, credential reuse.
Privilege escalation (user → root/administrator), lateral movement (pivoting), persistence (backdoors, scheduled tasks), data exfiltration (sensitive data).
Document findings: vulnerabilities, risk ratings (CVSS), exploitation steps, impact, remediation recommendations, evidence (screenshots, logs). Deliver executive summary and technical report.
Tester has no prior knowledge of target (only domain name/IP range). Simulates external attacker. Most realistic but time-consuming. Requires extensive reconnaissance.
Tester has some internal knowledge (credentials, architecture diagrams, API documentation). Simulates insider threat or compromised user. Most common.
Tester has complete access: source code, credentials, network diagrams, configuration files. Most thorough, efficient. Used for compliance (PCI DSS).
Network discovery and port scanning. SYN scan (-sS), service version detection (-sV), OS detection (-O), script engine (NSE). nmap -sS -sV -p- -T4 target.com
Exploit development and execution. Payloads (Meterpreter), post-exploitation modules, auxiliary scanners. msfconsole, search
Web proxy for intercepting/modifying HTTP/HTTPS traffic. Scanner, Intruder (fuzzing), Repeater (manual testing), Collaborator (out-of-band detection).
Automated vulnerability scanning. Nessus Professional ($3,990/year). OpenVAS (free, open-source). Detect CVEs, misconfigurations, missing patches.
Network protocol analyzer. Capture live traffic, analyze PCAP files, filter protocols, follow TCP streams, detect anomalies.
Discover hidden directories, files, and subdomains. Wordlist-based brute force. gobuster dir -u https://target.com -w /usr/share/wordlists/dirb/common.txt
Online password cracking. Supports SSH, FTP, HTTP, RDP, SMTP, MySQL, PostgreSQL. hydra -l admin -P passwords.txt ssh://192.168.1.100
Automated SQL injection detection and exploitation. Database fingerprinting, data extraction, command execution. sqlmap -u "http://target.com?id=1" --dbs
// External network penetration testing example
# Phase 1: Reconnaissance (Passive)
whois target.com
dig +short target.com
theHarvester -d target.com -b google
# Phase 2: Scanning (Active)
nmap -sS -sV -O -p- -T4 target.com
nmap -sU -p 53,161,500,4500 target.com
# Phase 3: Vulnerability Scanning
nmap --script vuln target.com
nikto -h https://target.com
# Phase 4: Exploitation (Web Application)
gobuster dir -u https://target.com -w /usr/share/wordlists/dirb/common.txt
sqlmap -u "https://target.com/page?id=1" --dbs
# Phase 5: Post-Exploitation (if successful)
# (with authorization only)
python3 -c 'import pty; pty.spawn("/bin/bash")' # Upgrade shell
sudo -l # Check sudo permissions
find / -perm -4000 2>/dev/null # SUID binaries
# Phase 6: Cleanup & Reporting
# Remove backdoors, clear logs, restore configurations
# Document findings, CVSS scores, remediation steps
This demonstration simulates an Nmap TCP SYN scan on a target IP address:
This is a simulated demonstration. Real penetration testing requires written authorization. Unauthorized scanning violates CFAA (US) and Computer Misuse Act (UK).
// Penetration testing report (standard template)
1. Executive Summary
- Testing objectives, scope, timeline
- Overall risk rating (Critical, High, Medium, Low)
- Key findings summary (top 5 vulnerabilities)
- Remediation roadmap
2. Technical Report
- Methodology (PTES, OWASP, NIST)
- Scope (IP ranges, domains, applications)
- Tools used (Nmap, Metasploit, Burp Suite, Nessus)
3. Findings
- Vulnerability ID (VULN-001)
- Title: SQL Injection in login parameter
- CVSS Score: 8.3 (High)
- Affected Asset: https://target.com/login
- Description: Time-based blind SQL injection
- Impact: Database compromise, data theft
- Proof of Concept (PoC): ' AND SLEEP(5) --
- Remediation: Parameterized queries (PreparedStatement)
- References: CWE-89, OWASP A03:2021
4. Appendix
- Scan logs (Nmap, Nessus)
- Screenshots (exploitation evidence)
- Remediation timeline
- Pentester qualifications (OSCP, GPEN, GWAPT)
Penetration testing is illegal without explicit written authorization. Unauthorized scanning violates CFAA (US), Computer Misuse Act 1990 (UK), and similar laws worldwide.
Penetration testing must be conducted with explicit written authorization from the target organization. Unauthorized testing (including port scanning, vulnerability scanning, exploitation) violates:
Important: This guide is for educational and defensive purposes only. Always obtain written authorization before conducting penetration testing. Use dedicated testing environments (labs, CTF platforms) for practice (HackTheBox, TryHackMe, PentesterLab).
Industry-standard penetration testing certification. 24-hour practical exam (buffer overflow, web, privilege escalation). Requires Offensive Security course (PEN-200).
SANS SEC560 certification. Multiple choice + practical exam (CyberLive). Covers scanning, exploitation, post-exploitation, reporting.
EC-Council certification. 125 multiple choice questions. Covers footprinting, scanning, enumeration, system hacking, web hacking.
TCM Security certification. 5-day practical exam (OSINT, external, internal, Active Directory). More affordable than OSCP.
Industry framework for penetration testing methodology (pre-engagement, reconnaissance, scanning, exploitation, post-exploitation, reporting).
Web application penetration testing methodology (93 test cases). Covers OWASP Top 10.
Legal penetration testing practice platforms. Realistic vulnerable machines (Windows, Linux, Active Directory).