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 client-side authentication vulnerabilities and teaches you how to analyze JavaScript code to bypass login mechanisms.
When approaching a web authentication challenge, it's important to first understand what we're working with. Client-side authentication is often vulnerable because all the code runs in the user's browser where it can be examined.
Navigate to the target URL using your web browser:
https://hack-the-login.hdna.me
Upon visiting the site, you'll see a simple login form with fields for username and password. Rather than attempting to guess credentials or brute force the login, a more efficient approach is to examine how the authentication mechanism works behind the scenes.
In web applications, client-side code is typically stored in JavaScript files. These files contain the logic that runs in the user's browser and can often reveal how authentication is implemented.
When dealing with client-side authentication, examining the source code is crucial. Unlike server-side authentication where the logic is hidden from users, client-side code is fully accessible in the browser.
To view the HTML source code of the page:
In the HTML, you'll notice a reference to a JavaScript file called script.js
:
<script src="script.js"></script>
This script tag tells us that the page is loading a JavaScript file that likely contains the authentication logic. Since the authentication happens on the client side, this file might contain valuable information about how the system validates credentials.
To view the JavaScript file:
script.js
in the file treeAlternatively, you can directly access the JavaScript file by appending "/script.js" to the URL:
https://hack-the-login.hdna.me/script.js
Examining JavaScript files is a common technique in web application security testing. It allows us to understand the application's behavior and potentially identify security vulnerabilities.
After accessing the script.js
file, we can analyze the authentication mechanism. Here's the content of the file:
document.getElementById('loginForm').addEventListener('submit', function(e) { e.preventDefault(); const username = document.getElementById('username').value; const password = document.getElementById('password').value; const messageDiv = document.getElementById('message'); // Simple authentication check if (username === "admin" && password === "SecretPassword123!") { messageDiv.textContent = "Authentication successful! Retrieving flag..."; messageDiv.className = "success"; // Read the flag from the random folder fetch('7d9f3b2e1c8a5f6d4e0/flag.txt') .then(response => response.text()) .then(flag => { messageDiv.textContent = `Success! Flag: ${flag}`; }) .catch(error => { messageDiv.textContent = "Error reading flag file"; messageDiv.className = ""; }); } else { messageDiv.textContent = "Invalid username or password"; messageDiv.className = ""; } });
Analyzing the Code:
Let's break down what this JavaScript code is doing:
e.preventDefault()
Key Findings:
admin
and SecretPassword123!
7d9f3b2e1c8a5f6d4e0/flag.txt
This is a classic example of insecure client-side authentication. The credentials are stored in plaintext within the JavaScript file that anyone can view. Additionally, the path to the flag file is also exposed in the code.
Based on our analysis of the JavaScript code, we've discovered both the login credentials and the location of the flag file. This gives us two different methods to retrieve the flag:
Since we now know the correct credentials, we can simply use them to log in:
admin
in the username fieldSecretPassword123!
in the password field
This method follows the intended flow of the application but uses the credentials we discovered by examining the source code.
Since we know the exact path to the flag file from the JavaScript code, we can bypass the login process entirely and access the file directly:
https://hack-the-login.hdna.me/7d9f3b2e1c8a5f6d4e0/flag.txt
This method demonstrates that the "security" provided by the random-looking directory name (7d9f3b2e1c8a5f6d4e0) is ineffective when the path is exposed in client-side code.
By navigating directly to this URL, the browser will display the flag without requiring any authentication.
Both methods work because of fundamental security flaws in the application's design:
After successfully bypassing the authentication using either method described above, you'll see the flag displayed. The flag will be in a UUID format, which looks something like this:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Make sure to copy the flag exactly as it appears - UUIDs are case-sensitive and include all dashes. This is the solution to the lab that you'll need to submit to complete the challenge.
This lab demonstrates several important security concepts:
Real-World Relevance: While this lab presents a simplified scenario, similar vulnerabilities exist in real-world applications. Developers sometimes implement authentication on the client side for convenience or due to lack of security awareness. Security professionals regularly examine client-side code to identify such vulnerabilities during security assessments.
Sign-in to your account to access your hacking courses and cyber security labs.
Access all hacking courses and cyber security labs.