DEV Community

Victor
Victor

Posted on

CyberHeroes — Client-Side Authentication Bypass

1. Introduction

In this write-up, I will document my experience completing the CyberHeroes room on TryHackMe.

The challenge is based on a simple web application with a login page. The objective is to find a way to authenticate successfully and access protected content.

At first, the application looked straightforward. However, instead of immediately trying common username and password combinations, I decided to inspect how the login mechanism worked.

This led me to discover that the application exposed its authentication logic directly in client-side JavaScript.

The main concepts covered in this challenge are:

  • Web application reconnaissance
  • HTML and JavaScript source-code analysis
  • Hardcoded credentials
  • Reversible password obfuscation
  • Client-side authentication weaknesses
  • Authentication bypass

2. Initial Reconnaissance

After joining the room, I deployed the vulnerable machine and started the AttackBox.

Once the machine was ready, I copied its IP address and accessed the web application through my browser:

http://MACHINE_IP
Enter fullscreen mode Exit fullscreen mode

The website displayed a simple homepage with several navigation options, including a login page.

I started by exploring the available pages to understand the application's functionality.

Nothing particularly interesting appeared on the homepage, so I moved to the login section.

3. Discovering the Login Page

The login page contained a basic authentication form with two input fields:

  • Username
  • Password

My first thought was to test a few common credentials. However, I did not want to waste time guessing passwords when there might be useful information available in the application itself.

I decided to inspect the page source.

In the browser, I pressed:

Ctrl + U
Enter fullscreen mode Exit fullscreen mode

Alternatively, I could right-click the page and select View Page Source.

While reviewing the HTML, I noticed an embedded JavaScript function responsible for handling the authentication process.

This was the most important discovery in the challenge.

4. Analyzing the JavaScript Authentication Logic

Inside the page source, I found a JavaScript function called authenticate().

The function retrieved the values entered into the username and password fields, then compared them against values defined directly in the script.

The relevant logic followed this structure:

function authenticate() {
    const username = document.getElementById('uname');
    const password = document.getElementById('pass');

    const RevereString = str =>
        [...str].reverse().join('');

    if (
        username.value == "REDACTED_USERNAME" &&
        password.value == RevereString("REDACTED_STRING")
    ) {
        // Authentication success
    } else {
        alert("Incorrect Password");
    }
}
Enter fullscreen mode Exit fullscreen mode

Note: This is a simplified and redacted representation of the authentication logic.

There were two important observations.

4.1 Hardcoded username

The expected username was directly embedded in the JavaScript source code.

This means that anyone who could access the login page could inspect the script and discover the expected username.

The application was exposing authentication-related information to every visitor.

4.2 Reversible password transformation

The password was not stored as a conventional secure password hash.

Instead, the JavaScript function used:

[...str].reverse().join('')
Enter fullscreen mode Exit fullscreen mode

This expression performs three operations:

  1. [...str] converts the string into an array of characters.
  2. .reverse() reverses the order of those characters.
  3. .join('') combines the characters back into a string.

For example:

const example = "olleh";

console.log([...example].reverse().join(''));
Enter fullscreen mode Exit fullscreen mode

Output:

hello
Enter fullscreen mode Exit fullscreen mode

This is a reversible transformation, not encryption or secure password hashing.

Because the application included the original string in its JavaScript source, I could recover the expected password without brute-forcing anything.

5. Recovering the Credentials

After understanding the JavaScript logic, I used Linux's built-in rev command to reverse the exposed string.

The command was:

echo "REDACTED_STRING" | rev
Enter fullscreen mode Exit fullscreen mode

The rev utility reverses the characters in each line of input.

This gave me the value required by the login form.

At this point, I had identified both authentication values from the client-side source code.

The important lesson here is that I did not need to exploit a complicated vulnerability or perform a password brute-force attack. The information was already available to anyone who inspected the application.

6. Authenticating to the Application

With the credentials recovered, I returned to the login page.

I entered the discovered username and password into their respective fields and submitted the form.

The authentication process succeeded, and the application proceeded to retrieve the protected content.

I also noticed an interesting detail in the JavaScript: successful authentication triggered an HTTP request using XMLHttpRequest.

The relevant logic followed this structure:

var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        document.getElementById("flag").innerHTML =
            this.responseText;
    }
};

xhttp.open("GET", "DYNAMIC_RESOURCE_PATH", true);
xhttp.send();
Enter fullscreen mode Exit fullscreen mode

This revealed another important part of the application's behaviour.

The browser was not simply checking the credentials and displaying a new page. It was constructing a resource path and requesting the protected content from the server.

This gave me a clearer understanding of the complete authentication workflow.

7. Understanding the Vulnerability

The main weakness demonstrated by this room is client-side authentication using exposed credentials and reversible password obfuscation.

The application placed authentication logic in JavaScript that was delivered to the user's browser.

This creates several security problems.

7.1 Client-side code is accessible

JavaScript running in a browser is not secret.

Users can inspect:

  • HTML source code
  • JavaScript functions
  • API endpoints
  • Request parameters
  • Client-side validation logic
  • Embedded configuration values

Therefore, authentication decisions should never depend on secrets hidden inside frontend code.

7.2 Obfuscation is not encryption

Reversing a string may make a value look less obvious, but it does not provide meaningful security.

An attacker can easily reproduce the same transformation using JavaScript, Python, or standard Linux utilities.

Obfuscation should never be treated as a replacement for cryptographic protection.

7.3 Authentication must be enforced server-side

The server must independently verify the user's identity and permissions.

Even if a frontend hides a button or rejects an invalid login attempt, an attacker can modify JavaScript or send HTTP requests directly.

A secure application must never trust the browser to make the final authentication decision.

8. Recommended Security Improvements

If I were reviewing this application from a defensive security perspective, I would recommend the following changes.

Weakness Recommended mitigation
Credentials embedded in JavaScript Remove authentication secrets from frontend code
Client-side authentication checks Perform authentication on the backend
Reversible password transformation Store passwords using Argon2id or bcrypt
No reliable server-side authorization Validate user permissions for every protected resource
Sensitive resource paths exposed through predictable logic Enforce authorization on the requested resource
Insufficient authentication monitoring Log authentication attempts and monitor suspicious activity

A secure authentication workflow should look like this:

  1. The user submits credentials through an HTTPS connection.
  2. The frontend sends the credentials to the backend.
  3. The backend verifies the password against a securely stored password hash.
  4. The backend creates an authenticated session or issues an appropriate token.
  5. Every protected endpoint validates the session or token and checks authorization.
  6. The application returns only the resources the authenticated user is permitted to access.

The key principle is that the backend must remain the authority for authentication and authorization.

9. Key Takeaways

This room reinforced several important web security lessons for me.

1. Always inspect the source code.

A website may look simple, but its HTML and JavaScript can reveal useful information about how it works.

2. Never trust client-side authentication.

Frontend validation improves the user experience, but it cannot enforce security by itself.

3. Obfuscation is not encryption.

A reversible transformation provides no meaningful protection for passwords or other secrets.

4. Understand the complete HTTP workflow.

Inspecting the JavaScript helped me understand how the application constructed requests and retrieved protected resources.

5. Avoid unnecessary brute forcing.

Before attempting automated attacks, understand the application's behaviour. Sometimes a careful source-code review reveals the weakness much faster.

10. Conclusion

The CyberHeroes room was a straightforward but valuable exercise in web application security.

What I found most interesting was how a simple login page exposed the entire authentication mechanism through client-side JavaScript.

By reviewing the source code, understanding the string-reversal function, and tracing the subsequent HTTP request, I was able to identify the authentication weakness without relying on brute-force techniques.

My biggest takeaway is that security-sensitive operations must never rely on code or secrets exposed to the client.

This is a fundamental principle of secure web application development and an important concept to remember when performing web penetration testing.


Author: Victor Hoang

Platform: TryHackMe

Room: CyberHeroes

Category: Authentication Bypass

Top comments (0)