TRANSCRIPTEnglish

How Token Scope Confusion Leads to Privilege Escalation?

13m 21s2,159 words319 segmentsEnglish

FULL TRANSCRIPT

0:00

Hello hackers, [music]

0:01

welcome back to the new video and in

0:03

this video we are going to talk about

0:06

token scopes and how it can lead to

0:08

privilege escalation when they're

0:10

improperly generated or validated. So

0:15

these bugs are real and you can find it

0:17

in the wild. Actually, this is kind of

0:20

inspired from a tweet or post I saw on

0:25

X. So here's that post and I thought to

0:30

research a bit more on this so I can

0:32

share it with you as well how this

0:34

actually works and how you can find this

0:36

bug [music] while bug hunting or

0:38

pentesting. So before we jump into that

0:41

we need to clear our basics. What is

0:44

token?

0:46

A token is a secure digital credential

0:49

used to verify a user's identity and

0:52

grant them access to protected resources

0:54

without requiring them to reenter

0:56

credentials for every single request. It

0:59

basically means that instead of uh

1:02

typing the username and password again

1:05

and again to access different features

1:07

in a web application, a user is simply

1:10

granted a token after single

1:12

verification and that token is used in

1:15

every single request. So it would be

1:18

much easier for the client and the

1:20

server to verify the user and it's uh

1:23

easy as well. So that's how usually

1:25

token works. In simple words, I would

1:28

say token basically says this user has

1:31

already been authenticated and here is

1:33

what they're allowed to do. Now, a token

1:36

has different kinds of claims and token

1:38

scope is one of the claim inside that

1:41

[music] access token. You can also call

1:43

it token or access token. So, the scope

1:45

inside an access token defines what

1:47

action the token is allowed to perform.

1:50

Let's say if a user is only allowed to

1:52

read and write then the token will have

1:57

read write [music] permissions but it

1:59

won't have any other permissions like

2:02

delete permission. You getting me? And

2:04

this is actually really important part

2:06

[music] of the token because it

2:08

literally defines what a user is allowed

2:10

to do and what not. And [music] as a

2:12

hacker, we're going to test how we can

2:15

escalate our privileges or how we can

2:18

test if there are something else we can

2:19

do like if we can delete something, we

2:22

can write something even though we are

2:23

not allowed to do so. I mean that's what

2:26

all hacking is about checking something

2:27

we are not allowed to do. Okay. So it

2:31

usually includes something like this

2:32

scope SCP permissions. Okay. There are

2:35

like three different names of it but all

2:37

of them do the same thing. So usually

2:40

scope you will see something like read

2:42

colon profile or write colon post. So it

2:45

means they can read profile and they can

2:47

write posts and there is a expiration

2:50

time for each access token as well. So

2:54

obviously if you're been testing and if

2:55

you see that there is uh no expiration

2:58

time then that itself is also a bug and

3:01

it would be low. But yeah

3:05

so let's talk about the steps of how

3:07

tokens work.

3:10

Okay, back in notion cuz we love notion.

3:14

So we have a diagram here and here you

3:17

can see is the traditional cookie based

3:19

authentication.

3:21

First the browser sends a request a post

3:24

request containing username and password

3:26

to authenticate the user and then the

3:28

server sends back a response by setting

3:32

a cookie for the user and it gives

3:34

something like set cookie session and

3:36

send some random value. You must have

3:38

seen it in uh traditional web

3:40

applications. And then the user is able

3:43

to access authenticated endpoints such

3:46

as / API/ user by using their cookie.

3:49

And then they're able to get back

3:52

response with 300 okay and their

3:54

information. So that's how traditional

3:56

cookie based authentication works. But

3:58

now we have modern based authentication.

4:01

In this case, the browser again sends a

4:03

post request with username and password

4:06

to authenticate the user and then the

4:08

server responds. But this time the

4:10

server responds with a token. In this

4:12

case, a JWT token. Okay? And we know JWT

4:16

token contains multiple claims, some

4:18

expiration time and scopes and

4:20

everything. We talked about scopes cuz

4:22

in this video we are going to exploit

4:24

scopes anyway. So you got the point and

4:26

that's how the server is able to give

4:29

particular permissions to a user. Okay.

4:33

Now the user will use that token in

4:36

every HTTP request to access

4:38

authenticated endpoints in this case/

4:41

API/ user and then they will simply get

4:44

200 okay response. So that's how it

4:46

works. So after looking at this diagram

4:49

this will make more sense. We have a

4:52

first step request. So user attempts to

4:54

access a protected resource by logging

4:55

in with their credential, username and

4:57

password and then second step is

4:59

verification. The server validates the

5:01

credential. If they are correct, the

5:03

server generates a unique

5:04

cryptographically signed token. The

5:06

third step we have the server sends the

5:08

token back to the client. Example, the

5:10

user's web browser or mobile app where

5:12

it is stored securely. And then for all

5:15

the feature requests to the protected

5:17

parts of the application, the client

5:18

includes this token in HTTP header.

5:21

Right? And then for each request, the

5:24

server validates the token signature and

5:26

expiration time. So as long as the token

5:29

is valid, it will work for the user. And

5:31

when the token expired, they just simply

5:33

have to login again with the username

5:35

and password. But this is still much

5:37

better, right? They don't have to like

5:39

provide their credential for each

5:42

request. So now you know how this works.

5:45

Really simple and easy. So I have

5:48

created a custom lab and in this lab I'm

5:50

going to demonstrate you how scopes can

5:52

be exploited but it's kind of like a

5:55

different one like I have already

5:57

created a lot of videos on JW attacks

5:59

but this is not JWD attack this is

6:02

different this is about how token scope

6:05

is not properly validated and how it can

6:09

lead to authorization issue focus on my

6:11

point here it's not an authentication

6:13

issue user is getting authenticated just

6:16

fine It's about authorization. The level

6:18

of privileges they have is getting

6:20

affected. Okay. So, keep that in mind.

6:23

Okay. So, now let's get to the practical

6:25

part so you can actually understand

6:27

what's going on.

6:30

Okay. So, now we are in my browser and

6:32

as you can see this uh application is

6:35

running on my local host port 3000. I

6:38

created this. So, yeah. Anyways, so we

6:42

have this login function and there are

6:45

two ways the user can login either using

6:47

a web client or using a mobile client

6:50

and that's where the vulnerability

6:52

arise. Actually I'll tell you how. But

6:54

before we first jump into that I want to

6:56

tell you that this has a dummy database

6:59

in the back end and it has few users. So

7:02

I'm just going to log in with a user to

7:05

simply show you how this actually works.

7:07

So let me open up my network tab so I

7:09

can see what kind of requests are going

7:11

through.

7:13

I don't even have to use burp suite for

7:15

this cuz network tabs is enough in this

7:18

case cuz we're not manipulating

7:20

anything.

7:21

So we have uh Alice

7:24

username and then we have password.

7:29

Okay. So we are using the web client to

7:32

login. So let's click on login

7:36

and as you can see we are redirected to

7:39

profile.html and over here we can see

7:41

our username and then we can see the

7:44

some posts like a simple uh social media

7:46

application. So if I go here you can see

7:50

there is API me endpoint. So obviously

7:53

this is an authenticated endpoint and in

7:55

the response we can see our own details

7:57

like username, role and scope, read

8:00

profile and other post. So let me go to

8:03

headers and let me show you something

8:04

interesting. So we have authorization

8:08

header and we have this value beer

8:10

token. This is basically JWT. Okay. So

8:14

when we clicked on login the server

8:16

provided us with this token so we can

8:19

access the application. Now let me go to

8:23

JWT decoder.

8:34

Great.

8:36

So over here we can see claims. Okay,

8:40

claims table. I like this little table.

8:43

So we have sub value, the subject of the

8:45

JWD, the user and then we have ro. Ro is

8:49

user. Then we have scope read profile

8:51

means we can read our own profile. Okay,

8:53

that makes sense. And then we have other

8:56

things like expiration time and IAT and

8:58

stuff. So anyways, let's go back to

9:00

JSON. And

9:02

yeah, from here we can easily see how

9:04

the scopes looks like. Now let's go back

9:06

to the application. Everything looks

9:09

simple, right? The application is giving

9:11

us a proper scope and we don't see

9:12

anything

9:14

extra and yeah things are working fine.

9:16

But let's log out for now.

9:20

And now we are going to use the same

9:22

username and password again. So we had

9:26

Alice

9:28

and then password

9:31

but this time we are going to use the

9:32

mobile client. So what happens is uh we

9:36

know that a lot of uh companies have

9:38

their web application and their mobile

9:40

application right. So there are

9:42

different kinds of clients they use but

9:44

the thing is when they are implementing

9:47

authorization or authentication checks

9:49

sometimes they implement it correctly on

9:52

the web client but not so correctly on

9:55

the mobile client and it can lead to

9:57

issues. So it's kind of like

9:58

misconfiguration or improper validation

10:01

you can say. So in this case we are the

10:04

same user but we're just going to use

10:05

the mobile client to login. So let's

10:07

click on login.

10:11

Okay, everything kind of looks the same.

10:13

My profile and I got my post. But I see

10:16

another feature over here. And we just

10:18

unlocked new feature which we didn't see

10:19

when we logged in through the web

10:21

client. And we can delete user. So this

10:25

is a delete user feature and it was

10:28

supposed to be only for admins. So let

10:30

me go back to this um / API/meoint

10:34

again. And in the response you can see I

10:37

have some extra scope. I have reprofile

10:40

that is similar to the previous one. But

10:41

then I have delete users and this is

10:44

extra. Okay, we don't need it. The user

10:47

a normal user isn't supposed to have

10:48

this. As you can see, our role is still

10:50

user. It's not admin. But we somehow

10:53

have an extra privilege to delete user.

10:57

So this is crazy and this is what I'm

10:59

talking about. This is improper

11:00

implementation of the token. And this is

11:03

about like you didn't change or

11:05

manipulate anything using burp suit or

11:07

something. you just simply analyze how

11:09

the application is working and you found

11:11

out that somehow you have an extra role

11:13

but obviously when you are exploring

11:15

like a real application there's going to

11:17

be like thousands of features so you

11:20

have to analyze everything through a

11:22

normal user perspective first and then

11:24

you can analyze it and then you can

11:26

check if there is any other feature that

11:28

you're not supposed to see by playing

11:31

around with different features. For

11:33

example, in this case, uh we just simply

11:35

switched to mobile client and we were

11:37

able to find out a new feature that just

11:40

literally appeared for us. And I think

11:42

this is what happened in the post. Uh he

11:46

was talking about that expost

11:50

like it said that uh the scope

11:52

separation wasn't clearly enforced and

11:54

privilege escalation was possible. So

11:56

you should apply the least privilege

11:58

scopes and obviously the least privilege

12:00

scope was not applied in the mobile

12:03

client in this case

12:05

and that post also mentioned that the

12:07

scope of differently generated tokens

12:10

triggered functions with higher

12:11

privilege user roles and that's exactly

12:14

what happened here.

12:16

We just triggered a functionality that

12:18

was meant to be a highprivileged user

12:20

even though we are low and we are able

12:23

to see that feature and can simply

12:25

delete the user by clicking on this

12:26

button as you can see. So obviously this

12:30

is an authorization bug. So yeah that's

12:34

how it works. Let me know your thoughts

12:36

in the comment section. And I think this

12:38

was really fun cuz usually we manipulate

12:40

JW tokens and find secret and stuff to

12:43

manipulate it. But sometimes we forget

12:45

that something simple as this and

12:47

misconfigured

12:49

uh implementations

12:51

could be an issue as well. People

12:53

usually miss this kind of stuff. But

12:55

yeah, that's crazy.

12:58

So that's it. That's what I wanted to

13:01

talk about in this video. Hope you

13:03

enjoyed watching it. Let me know if

13:05

there is something else you want me to

13:06

talk about in the next video. And yeah,

13:09

I'll see you in the next one.

13:12

[music]

13:18

>> [music]

UNLOCK MORE

Sign up free to access premium features

INTERACTIVE VIEWER

Watch the video with synced subtitles, adjustable overlay, and full playback control.

SIGN UP FREE TO UNLOCK

AI SUMMARY

Get an instant AI-generated summary of the video content, key points, and takeaways.

SIGN UP FREE TO UNLOCK

TRANSLATE

Translate the transcript to 100+ languages with one click. Download in any format.

SIGN UP FREE TO UNLOCK

MIND MAP

Visualize the transcript as an interactive mind map. Understand structure at a glance.

SIGN UP FREE TO UNLOCK

CHAT WITH TRANSCRIPT

Ask questions about the video content. Get answers powered by AI directly from the transcript.

SIGN UP FREE TO UNLOCK

GET MORE FROM YOUR TRANSCRIPTS

Sign up for free and unlock interactive viewer, AI summaries, translations, mind maps, and more. No credit card required.