Skip to content

Commit 193abc3

Browse files
committed
java-code-analysis added
1 parent eb92060 commit 193abc3

File tree

16 files changed

+95
-1
lines changed

16 files changed

+95
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ I will describe, how to solve some challenges, that are not presented in [this r
1515
* Web Exploitation
1616
* SOAP
1717
* More SQLi
18-
* Java Code Analysis
18+
* **[Java Code Analysis](Web%20Exploitation/Java%20Code%20Analysis/Java-code-analysis.md)**
1919
* Reverse Engineering
2020
* **[No way out](Reverse%20Engineering/No%20way%20out/No-way-out.md)**
2121

51.3 KB
Loading
56.6 KB
Loading
66.1 KB
Loading
40.6 KB
Loading
19.1 KB
Loading
65.3 KB
Loading
130 KB
Loading
43.9 KB
Loading
104 KB
Loading
135 KB
Loading
49.6 KB
Loading
112 KB
Loading
101 KB
Loading
32.3 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Java Code Analysis!?! #
2+
3+
## Overview ##
4+
5+
300 points
6+
7+
Category: [Web Exploitation](../)
8+
9+
Tags : `#picoCTF 2023` `Web Exploitation`
10+
11+
## Description ##
12+
13+
BookShelf Pico, my premium online book-reading service.
14+
I believe that my website is super secure. I challenge you to prove me wrong by reading the 'Flag' book!
15+
16+
Additional details will be available after launching your challenge instance.
17+
18+
## Solution ##
19+
20+
After start of the instance picoCTF will provide you source code of the site and link to running instance.
21+
22+
Site has login screen:
23+
24+
![Screenshot of the login screen](1.jpg)
25+
26+
And main screen with books.
27+
28+
![Screenshot of the main screen](2.jpg)
29+
30+
We can't access any of them except the first one.
31+
32+
Let's dive into code.
33+
34+
There are some files, that are interesting to us.
35+
36+
![Screenshot of the files](3.jpg)
37+
38+
Inside `JwtService.java` we can see all data, that JwtToken contain, the issuer and that `secretGenerator` gives the secret key.
39+
40+
![Screenshot of the file](4.jpg)
41+
42+
And inside the `SecretGenerator.Java` we see this.
43+
44+
![Screenshot of the file](5.jpg)
45+
46+
So, now we know, that "secret key" is `1234`. We have all the information to encode and decode JWT tokens.
47+
48+
But we need a userId, so let's get back to the login screen.
49+
50+
Now, I'm using `Google chrome` - press F12, open `Network` tab and login with creds from picoCTF: user:`user`, pass:`user`
51+
52+
And we will get the JWT token for our user in the payload of the response:
53+
54+
![Screenshot of the network tab](6.jpg)
55+
56+
Copy it and go to the [this website](https://jwt.io/). Let's decode it like this:
57+
58+
![Screenshot of the jwt](7.jpg)
59+
60+
So, `userId` is `1`.
61+
62+
Now let's encode out JWT token with role `Admin`:
63+
64+
![Screenshot of the jwt](8.jpg)
65+
66+
Inside `controllers` directory we can find `UserController.java`, where we can see this endpoint:
67+
68+
![Screenshot of the src](9.jpg)
69+
70+
Now I will use Postman (because I'm lazy) and send some requests with new JWT to update our role and read the flag.
71+
72+
We need to create new user on the site, because we can't patch default user role.
73+
74+
We need to obtain users list.
75+
76+
First of all - put token into headers.
77+
78+
![Screenshot of the postman](10.jpg)
79+
80+
Request:
81+
82+
![Screenshot of the postman](11.jpg)
83+
84+
Out id is `6`.
85+
86+
Now let's patch our role:
87+
88+
![Screenshot of the postman](12.jpg)
89+
90+
Now we are `Admin` - just login and read the flag:
91+
92+
![Screenshot of the postman](13.jpg)
93+
94+
![Screenshot of the postman](14.jpg)

0 commit comments

Comments
 (0)