SwagShop

Reconnaissance: NMAP

┌──(kali💀kali)-[~]
└─$ sudo nmap -sC -sV -O 10.10.10.140   

22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 b6:55:2b:d2:4e:8f:a3:81:72:61:37:9a:12:f6:24:ec (RSA)
|   256 2e:30:00:7a:92:f0:89:30:59:c1:77:56:ad:51:c0:ba (ECDSA)
|_  256 4c:50:d5:f2:70:c5:fd:c4:b2:f0:bc:42:20:32:64:34 (ED25519)

80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Did not follow redirect to http://swagshop.htb/
Aggressive OS guesses: Linux 4.15 - 5.8 (96%), Linux 5.3 - 5.4 (95%), Linux 2.6.32 (95%), Linux 5.0 - 5.5 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (95%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 5.0 (93%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 44.23 seconds

Enumeration: SSH 22/tcp

OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)

Enumeration: HTTP 80/tcp

I always start off with enumerating HTTP first. Visit the web application.

Gobuster:

Nikto:

Magento

It’s running Magento, which is an open-source e-commerce platform written in PHP. Considering that it is an off the shelf software, we’ll probably find reported vulnerabilities that are associated to it. But first, we need to get a version number. Notice that at the bottom of the page, it has a copyright detailing the year 2014, which is 6 years ago, so it’s very likely to be vulnerable. Just like there is a scanner for WordPress applications (WPScan), there is one for Magento applications that is called Mega scan. Let’s use it to run a scan on the application.

Mage Scan: Scan a Magento site for information

-vvv: increase the verbosity to level 3 scan:all: run all scans

It reports the version number being 1.9.0.0 or 1.9.0.1 and they’re using the Community edition. There are no installed modules, so if we find any public vulnerabilities that are associated to modules, we can discard them. As for the unreachable path check, the last two paths don’t give us anything useful. However, the first path, gives us an xml file that leaks the swagshop mysql database username and password.

This might come in handy later. Next, let’s run searchsploit.

The first three exploits don’t match our version, so we’ll ignore them. The next two might be useful. Since Mage Scan didn’t report plugins, we’ll ignore the plugin vulnerabilities. The two after that might be relevant to our version. Lastly, we’ll also ignore the eBay Magento exploits.

We narrowed down our exploits to four possible options: 39838,37811,19793 and 37977. We’ll start off with looking into exploit number 37977 because it doesn’t require authentication and it is an RCE vulnerability.

Shell as www-data

Copy the exploit to our current directory.

-m: mirror an exploit to the current working directory.

After skimming through the code of the exploit,it seems to be chaining several SQL injection vulnerabilities together that eventually create an administrative account on the system with the username/password forme/forme.

To get the code working on our application, we need to make a few changes:

  1. Remove all the uncommented comments & explanation (or you’ll get compilation errors)

  2. Change the target variable to http://10.10.10.140/

  3. Change the username/password to random/random (optional). Run the exploit.

It didn’t work and it doesn’t give us much of an explanation why. So let’s redirect all the traffic from the script to Burp. To do that, perform the following steps.

  • In Burp, visit Proxy > Options > Proxy Listeners > Add. In the Binding tab, set the Bind port to 8081 and and in the Request Handling tab, set the Redirect to host option to 10.10.10.140 and the Redirect to Port option to 80. Make sure to select the newly added listener once you’re done.

  • Go back to the script and change the target to http://localhost:8081

  • In Burp set intercept to be on.

This way all the traffic of the script will go through Burp first. Run the script again and send the request to Repeater. In Repeater, execute the request. As shown in the above image, the script is failing because it’s not finding the URL. Let’s try it in our browser.

http://localhost:8081/admin

Doesn’t work. Let’s visit other links in the website and see how the URL changes. If we click on the Hack the Box sticker we get the following link.

http://10.10.10.140/index.php/5-x-hack-the-box-sticker.html

It seems to be appending index.php to all the URLs. Let’s add that in our script. So now our target would be:

http://localhost:8081/index.php

Username: root, Password: fMVWh7bDHpgZkyfqQXreTjU9 Key: b355a9e0cd018d3f7f03607141518419 FrontName: admin

I noticed that we have admin panel at http://swagshop.htb/index.php/admin and not at http://swagshop.htb/admin. I changed the script a bit to:

Let’s login into Magneto using the following credentials:

http://swagshop.htb/index.php/admin/dashboard/index/key/036b971b8fcdc35f6c2d665a253c1550/

Now, we are in the Magento Admin Panel. There are a bunch of different methods in which we can get the shell but we decided to use the “Froghopper” Attack. It is a File Upload attack. It got its name from the pepe frog image that was used as a meme to get the shell by the author of the exploit. The files uploaded are not accessible in their raw form which will prevent us from executing them. This can be bypassed by allowing Symlinks in Developer Settings (System > Configuration > developer > Template Settings)

Magneto have built-in feature to restrict the malicious extensions of the files that can cause harm. Hence all it allows are PNG, JPG, GIF etc. The protection mechanism checks for the header and the extension but not for the contents of the file being uploaded. This means that we can craft payload in such a way that we are able to upload it to the target system. Hence, we took the reverse shell script and added GIF98 on top of it to be able to upload it.

Now we create a new category, named Demo. It needs to be active for the payload to work. Then upload the reverse shell script with double extension as shown in the image below.

Now proceed to the Newsletter Section and Click on Add New Template. In the Newsletter Template fill in the form with dummy details and then in the text filed add the path of template i.e., the reverse shell script as shown below.

Now getting back to the Newsletter Template Section, we see that our newly created newsletter is visible. Before executing it, we run a listener on the port mentioned in the reverse shell. After that, we proceed to Preview the Newsletter template as shown in the image below.

Privesc to root

We checked the sudo permissions and found that we can run vi with root privileges but inside /var/www/html/. We use the vi for editing the index.php inside the /var/www/html.

Read Flag:

The fastest path to the flag is just to open it with vi. Based on the sudo output above, I’ll run:

Shell: Great! Searching in gtfobins I found this.

Last updated