Lab 09 Using Components With Known Vulnerabilities - Muamaidbengt/juice-shop GitHub Wiki
After you've logged in to the Juice Shop, it uses Json Web Tokens (JWTs) to authenticate any subsequent requests. The tokens consist of 3 separate parts. First is the header describing the token. After the header, the payload part typically contains a unique identifier for your session, along with various other information that pertains to you as a user of the site, but isn't secret. The last part may contain a cryptographic signature, created by the issuer (in this case, the juice shop). Ideally, when a system utilizes JWTs it should inspect the signature and completely disregard any tokens without a valid signature (from a trusted party). The sections are Base64Url-encoded, and separated by punctuation characters (.), so the structure is <header>.<payload>.<signature>.
Knowing that the shop uses JWTs is useful, since there might be vulnerabilities in related libraries. Let's see if the Juice Shop contains the JWT component with a known vulnerability.
- You'll need 3 browser windows open simultaneously for this lab.
- Log in to the Juice Shop as any user.
- Use the developer tools of your web browser to check for any cookies used by the site.
- Notice there's a cookie named
token. Copy the value of it. - Go to jwt.io and paste the token into the left-hand side. Notice how the contents of the token appear in the right hand side, including the signature (although it doesn't seem to be valid). Will the site still accept a token without a signature? Let's find out.
- Go to base64encode.org and create a header that indicates that the JWT contains no signature by entering
{
"alg": "none",
"typ": "JWT"
}
- Copy the resulting Base64-encoded text into a new text file.
- Remove any trailing
=characters (since it is just padding). - Enter a single dot/punctuation character
.after the text, indicating that the JWT payload part begins.
- From the decoded token in jwt.io, copy the payload into base64encode.org.
- Change the email address to
[email protected]and the id to a different integer. - Copy the resulting Base64-encoded text and insert it after the dot in your text file.
- Remove any trailing
=characters. - Add a new dot after the text, indicating that the JWT signature part begins, but leave the signature part empty.
- You now have a complete (but unsigned) JWT. Since it is unsigned, it should end immediately after the 2nd punctuation mark
..
- In the developer tools for the Juice Shop, replace the value of the
tokencookie with your forged JWT token - Reload the page.
- Check if you have access to content that requires an authenticated user (e.g. by adding an item to the cart).
- What is the risk to the Juice Shop in this scenario?
- What is the risk to a general Web app in this type of scenario?