Skip to content

Latest commit

 

History

History
94 lines (48 loc) · 2.35 KB

File metadata and controls

94 lines (48 loc) · 2.35 KB

Java Code Analysis!?!

Overview

300 points

Category: Web Exploitation

Tags : #picoCTF 2023 Web Exploitation

Description

BookShelf Pico, my premium online book-reading service. I believe that my website is super secure. I challenge you to prove me wrong by reading the 'Flag' book!

Additional details will be available after launching your challenge instance.

Solution

After start of the instance picoCTF will provide you source code of the site and link to running instance.

Site has login screen:

Screenshot of the login screen

And main screen with books.

Screenshot of the main screen

We can't access any of them except the first one.

Let's dive into code.

There are some files, that are interesting to us.

Screenshot of the files

Inside JwtService.java we can see all data, that JwtToken contain, the issuer and that secretGenerator gives the secret key.

Screenshot of the file

And inside the SecretGenerator.Java we see this.

Screenshot of the file

So, now we know, that "secret key" is 1234. We have all the information to encode and decode JWT tokens.

But we need a userId, so let's get back to the login screen.

Now, I'm using Google chrome - press F12, open Network tab and login with creds from picoCTF: user:user, pass:user

And we will get the JWT token for our user in the payload of the response:

Screenshot of the network tab

Copy it and go to the this website. Let's decode it like this:

Screenshot of the jwt

So, userId is 1.

Now let's encode our JWT token with role Admin:

Screenshot of the jwt

Inside controllers directory we can find UserController.java, where we can see this endpoint:

Screenshot of the src

Now I will use Postman (because I'm lazy) and send some requests with new JWT to update our role and read the flag.

We need to create new user on the site, because we can't patch default user role.

We need to obtain users list.

First of all - put token into headers.

Screenshot of the postman

Request:

Screenshot of the postman

Our id is 6.

Now let's patch our role:

Screenshot of the postman

Now we are Admin - just login and read the flag:

Screenshot of the postman

Screenshot of the postman