TryHackMe: OWASP Juice Shop – Walkthrough

September 15, 2023
Posted in Web
September 15, 2023 Jasper

Hi! In this walkthrough we will look at OWASP’s juice shop, and specifically at the most common vulnerabilities found in web applications.

I am making these walkthroughs to keep myself motivated to learn cyber security, and ensure that I remember the knowledge gained by THMs rooms. Join me on learning cyber security. I will try and explain concepts as I go, to differentiate myself from other walkthroughs.

Room URL: https://tryhackme.com/room/owaspjuiceshop

Prerequisites:
Web Fundamentals (https://tryhackme.com/room/webfundamentals), Burp Suite Basics (https://tryhackme.com/room/burpsuitebasics), Burp Suite Repeater (https://tryhackme.com/room/burpsuiterepeater)

Although not noted as a prerequisite, I would definitely recommend the OWAP Top 10 room as well: https://tryhackme.com/room/owasptop10


Task 1 (Open for Business!)

Within this room, we will look at OWASP’s TOP 10 vulnerabilities in web applications. You will find these in all types of web applications. But for today we will be looking at OWASP’s own creation, Juice Shop!

Juice Shop is a large application so we will not be covering every topic from the top 10. We will, however, cover the following topics which we recommend you take a look at as you progress through this room.

Injection

Broken Authentication

Sensitive Data Exposure

Broken Access Control

Cross-Site Scripting XSS

Questions

Deploy the VM attached to this task to get started! You can access this machine by using your browser-based machine, or if you’re connected through OpenVPN.

Answer: No answer needed

Once the machine has loaded, access it by copying and pasting its IP into your browser; if you’re using the browser-based machine, paste the machines IP into a browser on that machine.

Answer: No answer needed


Task 2 (Let’s go on an OWASP adventure!)

Before we get into the actual hacking part, it’s good to have a look around. In Burp, set the Intercept mode to off and then browse around the site. This allows Burp to log different requests from the server that may be helpful later.

This is called walking through the application, which is also a form of reconnaissance!

Questions

Question #1: What’s the Administrator’s email address?

Product reviews show the user’s email adress. If you click on the first product you will get to see the admin’s email 🙂

Answer: admin@juice-sh.op

Question #2: What parameter is used for searching?

Click on the magnifying glass in the top right of the application will pop out a search bar. Now pay attention to the URL which will now update with the text we just entered.

We can now see the search parameter after the page url is the letter q.

Answer: q

Question #3: What show does Jim reference in his review?

Jim reviewed the Green Smoothie product. Here he mentions a replicator.

Google “replicator” and you will find out that it is from Star Trek. Bonus bonus if you knew this 🙂

Answer: star trek


Task 3 (Inject the juice)

This task will be focusing on injection vulnerabilities. Injection vulnerabilities are quite dangerous to a company as they can potentially cause downtime and/or loss of data. Identifying injection points within a web application is usually quite simple, as most of them will return an error. There are many types of injection attacks, some of them are:

  • SQL Injection
    SQL Injection is when an attacker enters a malicious or malformed query to either retrieve or tamper data from a database. And in some cases, log into accounts.
  • Command Injection
    Command Injection is when web applications take input or user-controlled data and run them as system commands. An attacker may tamper with this data to execute their own system commands.
  • Email Injection
    Email injection is a security vulnerability that allows malicious users to send email messages without prior authorization by the email server. These occur when the attacker adds extra data to fields, which are not interpreted by the server correctly.

In this task we will be using SQL Injection.

Questions

Question #1: Log into the administrator account!

After we navigate to the login page, enter some data into the email and password fields. Before clicking submit, make sure Intercept mode is on. This will allow us to see the data been sent to the server!

We will now change the “test” next to the email to: ‘ or 1=1 — and forward it to the server.

Why does this work?

  1. The character will close the brackets in the SQL query
  2. ‘OR’ in a SQL statement will return true if either side of it is true. As 1=1 is always true, the whole statement is true. Thus it will tell the server that the email is valid, and log us into user id 0, which happens to be the administrator account.
  3. The — character is used in SQL to comment out data, any restrictions on the login will no longer work as they are interpreted as a comment.

We got admin access!

Answer: 32a5e0f21372bcc1000a6088b93b458e41f0e02a

Question #2: Log into the Bender account!

Similar to what we did in Question #1, we will now log into Bender’s account! Capture the login request again, but this time we will put: bender@juice-sh.op’ — as the email.

Now, forward that to the server!

But why don’t we put the 1=1?

Well, as the email address is valid (which will return true), we do not need to force it to be true. Thus we are able to use ‘ — to bypass the login system. Note the 1=1 can be used when the email or username is not known or invalid.

We are logged in once more!

Answer: fb364762a3c102b2db932069c0e6b78e738d4066


Task 4 (Who broke my lock?)

In this task, we will look at exploiting authentication through different flaws. When talking about flaws within authentication, we include mechanisms that are vulnerable to manipulation. These mechanisms, listed below, are what we will be exploiting.

  • Weak passwords in high privileged accounts
  • Forgotten password pages

Questions

Question #1: Bruteforce the Administrator account’s password!

We have used SQL Injection to log into the Administrator account but we still don’t know the password. Let’s try a brute-force attack! We will once again capture a login request, but instead of sending it through the proxy, we will send it to Intruder.

Go to Positions and then select the Clear § button. In the password field place two § inside the quotes. To clarify, the § § is not two sperate inputs but rather Burp’s implementation of quotations e.g. “”. The request should look like the image below.

For the payload, we will be using the best1050.txt from Seclists. (Which can be installed via: apt-get install seclists). You can load the list from /usr/share/seclists/Passwords/Common-Credentials/best1050.txt.

NOTE: I used an Attacker Box and had trouble with the previous step. apt-get install seclists did not work and the above directory did not exist. I figured out the location: /root/Tools/wordlists/SecLists/Passwords/Common-Credentials/best1050.txt.

You should select the following Runtime file as Payload type.

Once the file is loaded into Burp, start the attack. You will want to filter for the request by status. A failed request will receive a 401 Unauthorized, whereas a successful request will return a 200 OK.

We found the password. Now let’s login to the account with the password.

Answer: c2110d06dc6f81c67cd8099ff0ba601241f1ac0e

Question #2: Reset Jim’s password!

Believe it or not, the reset password mechanism can also be exploited! When inputted into the email field in the Forgot Password page, Jim’s security question is set to “Your eldest siblings middle name?”.

Note: Jim’s email is jim@juice-sh.op

In Task 2, we found that Jim might have something to do with Star Trek. Googling “Jim Star Trek” gives us a wiki page for Jame T. Kirk from Star Trek.Looking through the wiki page we find that he has a brother. Looks like his brother’s middle name is Samuel

Inputting that into the Forgot Password page allows you to successfully change his password. You can change it to anything you want!

Answer: 094fbc9b48e525150ba97d05b942bbf114987257


Task 5 (AH! Don’t look!)

A web application should store and transmit sensitive data safely and securely. But in some cases, the developer may not correctly protect their sensitive data, making it vulnerable.

Most of the time, data protection is not applied consistently across the web application making certain pages accessible to the public. Other times information is leaked to the public without the knowledge of the developer, making the web application vulnerable to an attack.

Questions

Question #1: Access the Confidential Document!

Navigate to the About Us page, and hover over the “Check out our terms of use”. You will see that it links to http://10.10.38.60/ftp/legal.md. Navigating to that /ftp/ directory reveals that it is exposed to the public!

We will download the acquisitions.md and save it. It looks like there are other files of interest here as well. After downloading it, navigate to the home page to receive the flag!

Answer:

Question #2: Log into MC SafeSearch’s account!

After watching the video there are certain parts of the song that stand out.

He notes that his password is “Mr. Noodles” but he has replaced some “vowels into zeros”, meaning that he just replaced the o’s into 0’s.

We now know the password to the mc.safesearch@juice-sh.op account is “Mr. N00dles

Answer: 66bdcffad9e698fd534003fbb3cc7e2b7b55d7f0

Question #3: Download the Backup file!

We will now go back to the http://10.10.38.60/ftp/ folder and try to download package.json.bak. But it seems we are met with a 403 which says that only .md and .pdf files can be downloaded.

To get around this, we will use a character bypass called “Poison Null Byte”. A Poison Null Byte looks like this: %00. Note: as we can download it using the url, we will need to encode this into a url encoded format.

The Poison Null Byte will now look like this: %2500. Adding this and then a .md to the end will bypass the 403 error!

Why does this work?

A Poison Null Byte is actually a NULL terminator. By placing a NULL character in the string at a certain byte, the string will tell the server to terminate at that point, nulling the rest of the string.

Go back to the homepage and you will get. your flag:

Answer: bfc1e6b4a16579e85e06fee4c36ff8c02fb13795

Task 6 (Who’s flying this thing?)

Modern-day systems will allow for multiple users to have access to different pages. Administrators most commonly use an administration page to edit, add and remove different elements of a website.

When Broken Access Control exploits or bugs are found, it will be categorised into one of two types:

  • Horizontal Privilege Escalation
    Occurs when a user can perform an action or access data of another user with the same level of permissions.
  • Vertical Privilege Escalation
    Occurs when a user can perform an action or access data of another user with a higher level of permissions.

Questions

Question #1: Access the administration page!

First, we are going to open the Debugger on Firefox. This can be done by navigating to it in the Web Developers menu.

We are then going to refresh the page and look for a javascript file for main-es2015.js. We will then go to that page at: http://10.10.38.60/main-es2015.js. To get this into a format we can read, click the { } button at the bottom

Now search for the term “admin”. You will come across a couple of different words containing “admin” but the one we are looking for is “path: administration”

This hints towards a page called “/#/administration” as can be seen by the about path a couple lines below, but going there while not logged in doesn’t work.

As this is an Administrator page, it makes sense that we need to be in the Admin account in order to view it. So login to the admin account and visit the /administration page.

Answer: 946a799363226a24822008503f5d1324536629a0

Question #2: View another user’s shopping basket!

Login to the Admin account and click on ‘Your Basket’. Make sure Burp is running so you can capture the request! Forward each request until you see: GET /rest/basket/1 HTTP/1.1

Now, we are going to change the number 1 after /basket/ to 2

It will now show you the basket of UserID 2. You can do this for other UserIDs as well, provided that they have one!

Answer: Answer: 41b997a36cc33fbe4f0ba018474e19ae5ce52121

Question #3: Remove all 5-star reviews!

Navigate to the http://10.10.38.60/#/administration page again and click the bin icon next to the review with 5 stars!

We get another flag!

Answer: 50c97bcce0b895e446d61c83a21df371ac2266ef

Task 7 (Where did that come from?)

XSS or Cross-site scripting is a vulnerability that allows attackers to run Javascript in web applications. These are one of the most found bugs in web applications. Their complexity ranges from easy to extremely hard, as each web application parses the queries in a different way.

There are three major types of XSS attacks:

DOM XSS (Document Object Model-based Cross-site Scripting) uses the HTML environment to execute malicious javascript. This type of attack commonly uses the <script></script> HTML tag.

Persistent XSS is Javascript that is run when the server loads the page containing it. These can occur when the server does not sanitise the user data when it is uploaded to a page. These are commonly found on blog posts.

Reflected XSS is Javascript that is run on the client-side end of the web application. These are most commonly found when the server doesn’t sanitise search data.

Questions

Question #1: Perform a DOM XSS!

We will be using the iframe element with a javascript alert tag:

<iframe src=”javascript:alert(`xss`)”>

Inputting this into the search bar will trigger the alert.

Note that we are using iframe which is a common HTML element found in many web applications, there are others which also produce the same result.

This type of XSS is also called XFS (Cross-Frame Scripting), is one of the most common forms of detecting XSS within web applications. Websites that allow the user to modify the iframe or other DOM elements will most likely be vulnerable to XSS.

Why does this work?

It is common practice that the search bar will send a request to the server in which it will then send back the related information, but this is where the flaw lies. Without correct input sanitation, we are able to perform an XSS attack against the search bar.

Enter <iframe src=”javascript:alert(`xss`)”> in the search bar and you will get the flag.

Answer: 9aaf4bbea5c30d00a1f5bbcfce4db6d4b0efe0bf

Question #2: Perform a persistent XSS!

First, login to the admin account. We are going to navigate to the “Last Login IP” page for this attack.

It should say the last IP Address is 0.0.0.0 or 10.x.x.x As it logs the ‘last’ login IP we will now logout so that it logs the ‘new’ IP.

Make sure that Burp intercept is on, so it will catch the logout request. We will then head over to the Headers tab where we will add a new header:

True-Client-IP: <iframe src=”javascript:alert(`xss`)”>

Then forward the request to the server!
When signing back into the admin account and navigating to the Last Login IP page again, we will see the XSS alert!

And the key!

Why do we have to send this Header?

The True-Client-IP header is similar to the X-Forwarded-For header, both tell the server or proxy what the IP of the client is. Due to there being no sanitation in the header we are able to perform an XSS attack.

Answer: 149aa8ce13d7a4a8a931472308e269c94dc5f156

Question #3: Perform a reflected XSS!

Login into the admin account and navigate to the ‘Order History’ page.

From there you will see a “Truck” icon, clicking on that will bring you to the track result page. You will also see that there is an id paired with the order.

We will use the iframe XSS, <iframe src=”javascript:alert(`xss`)”>, in the place of the 5267-f73dcd000abcc353 in the url!

After submitting the URL, refresh the page and you will then get an alert saying XSS!

Why does this work?

The server will have a lookup table or database (depending on the type of server) for each tracking ID. As the ‘id’ parameter is not sanitised before it is sent to the server, we are able to perform an XSS attack. In other words: the javascript we entered got directly displayed on the page, and therefore it get s triggered.

Answer: 23cefee1527bde039295b2616eeb29e1edc660a0

Task 8 (AH! Don’t look!)

If you wish to tackle some of the harder challenges that were not covered within this room, check out the /#/score-board/ section on Juice-shop. Here you can see your completed tasks as well as other tasks in varying difficulty.

Questions

Access the /#/score-board/ page

Answer: 7efd3174f9dd5baa03a7882027f2824d2f72d86e

We are done! Thank you for joining me on the ride. 🙂


Like my articles?

You are welcome to give my article a clap or two 🙂
I would be so grateful if you support me by buying me a cup of coffee:

I learned a lot through HackTheBox’s Academy. If you want to sign up, you can get extra cubes, and support me in the process, if you use the following link: