Skip main navigation

Exploitation: Practical Application

In this video, Pedro Silva demonstrates how to use JSON web tokens to identify vulnerabilities associated with using certain tokens.
6.2
Welcome back to Using Components with Known Vulnerabilities session. In this second part, we’ll exploit a known vulnerability in our target application. We will jump straight to our intentionally vulnerable application and then move on to the mitigation part.
28.1
We can now retrieve our JSON Web Token from browser’s cookies or local storage.
41.1
Next, we will decode our JSON web token.
59.9
JSON web tokens have three sections, all of them base64 encoded and split by a dot. The first section is called header, and it includes information about token type and the algorithm used to compute token signature.
80.5
The second section is called payload, and it holds the actual data or claims.
87.9
The third and last section is the signature.
93.7
Tokens can be signed by the server using a key so the server is able to verify that the token is legitimate when it is sent back by the client in subsequent requests. The signature is calculated by base64 URL encoding the header and payload, concatenating them with a period as a separator, and passing the resulting value to an algorithm, such as the SHA-256 with a secret. The name of the algorithm used to compute the signature is what goes into the JSON web token headen so that the same algorithm can be used to verify a token’s authenticity. This was a quick overview of JSON web tokens.
133.4
But you’re better reading more about this since JSON web tokens are very popular and its use widespread.
144.5
So now let’s talk about the JWT common library’s vulnerability we will try to exploit. JWT libraries have to implement at least two mandatory signing algorithms, none and HFS 256. The none algorithm is a curious addition to JWT. It is intended to be used for situations where the integrity of the token has already been verified. Some libraries treat the tokens signed with the none algorithm as a valid token with a verified signature. You must be seeing where this is going. We will replace the alg property in the JWT header of our token by none. Then change some date in the payload section and remove the signature. If Juice Shop is vulnerable, our temporary JWT should be accepted.
192.9
Let’s copy and paste the JWT header into our terminal to decode it.
210.2
Now we copied the decoded header, modified the alg property, and encoded back using base64 command line tool.
230.1
Let’s copy and paste a new header into our text editor, appending a dot to separate it from the payload section we will append here later.
245.8
We need to do the same with the payload. Let’s copy and paste it into our terminal so that we can decode it.
262.6
Now we copy and paste the decoded payload, modified email property to something that should not exist in Juice Shop database, and encode the modified JSON payload using base64.
298.3
Again, let’s copy and paste the outcome into our text editor.
311.2
We won’t add a signature, since our token is not signed according to our new JWT header.
319.8
Now we are going to replace the token in our browser’s cookies and local storage with our crafted JSON web token.
337
Let’s now access some pages and see whether Juice Shop accepts our crafted JSON web token.
348.9
As you can see, the complaint form shows the email address we replaced in the JSON web token. Let’s see if we can post a message.
366.8
It looks like we have done it. Let’s check the customer feedback feature.
374.5
It also shows the email address we replaced in the JSON web token. Let’s also post some feedback.
427.1
Based on what we have experienced, that JSON web token library used by Juice Shop is vulnerable. Next we will discuss what makes the application vulnerable and how to prevent it.

This video demonstrates how to use JSON web tokens to identify vulnerabilities associated with using certain tokens.

You will follow a demonstration using OWASP Juice Shop that illustrates how to interpret a JSON web token using JWT and with your terminal, and it shows how to use this to identify the vulnerabilities in the OWASP Juice Shop system.

This article is from the free online

Advanced Cyber Security Training: OWASP Top 10 and Web Application Fundamentals

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education