
Hey there! 👋 Ready to dive into the world of JWT hacking for REST APIs? This video walks you through a real-world example, step by step, showing how to find, decode, and manipulate JWTs to gain unauthorized access and even execute code on a server. Let's break down the process in detail, following the video's flow and highlighting all the key learnings and memorable quotes along the way!
The video kicks off with the creator mentioning some off-screen work:
"I went on and did a little bit of things off screen, not very much, I just fetched the next file in line which was this api tabs file."
get_current_user and parse_token."In all of those they are using something called settings.jwt_secret."
The next step is to find the secret used to sign JWTs:
"Now we need to find out where the settings are coming from... it's this settings in core config."
"If we look in app/core/config/settings.py, we should be able to find the secret in there."
"Maybe there is just this settings.py and it gives us back the classes in there... and we get something in the settings.py. Now that's amazing!"
"We have the jwt_secret which is the API key of the os.environ."
"If you remember back the last episode we had this proc self and wiring over here... in here we have the API key."
"Now we have the API key saved. Perfect!"
With the secret in hand, it's time to craft a JWT:
"All we need to do now is generate our JWT. Let me do a quick Google search on how to do that."
"We can use Python and we can use a library... seeing that we are hacking a Python API, why not use Python to hack it? It's just the irony that I like."
The JWT is imported and saved:
"Let's import jwt and then save our JWT that we have here after this bearer part."
The algorithm is checked:
"Let's maybe check with jwt.io again... and we can see the algorithm is HS256."
The decoding process:
"Let's do a quick test and just run this command as we've seen it in the guide... and then we get the exact same thing, we get this access token."
Superuser Access:
"The one that's important is this: 'superuser: true'."
"Let's set this to true. So we now set this."
"Now we need to do the inverse of what we did before. So we first decoded it, now we changed it, and the last part is to re-encode it."
"We get a new token which now has the debug flag in it."
"Let's add this bearer token in here... and now we should refresh the docs."
"Let's just write something in the temp directory because everybody should have access to the temp directory... let's write in here 'hello world'."
"We can now write on the file system."
The creator attempts to create an index.html:
"Let's create a new index.html... and we got an unknown error. I have no idea why, hence the term unknown."
They consider overwriting the main Python file:
"The easiest way would be if we overwrite the main.py and then somehow could reload it. I have no idea how to do that, so let's not go with that way for now."
They look for the web root:
"Maybe it's the home... and we have an index.html... and it's a success."
But:
"If we do, we get the index.html not found. So apparently this isn't the web root."
"What I'm actually trying to do is to create a reverse shell using this upload technique that we now have at our disposal."
"I'm just unsure how to trigger the file... apparently we can't just do that because I just uploaded the index.html and we can't find it."
"Maybe if we just change one of the other files it will lazy load it somehow... if we can smuggle in a reverse shell into this Python script I think we're good to go."
The video ends with a friendly sign-off:
"Thank you for watching, make sure to subscribe and hit the like button, and if you want to learn more about hacking check out my Patreon channel over here. Bye bye!"
jwt library).Hope this breakdown helps you understand how JWT hacking works in practice! 🚀 If you want to learn more, don't forget to check out the creator's other content. Happy hacking! 🐱💻
Get instant summaries with Harvest