tryhackme // 2024-12-30 // ID: REF-Cyberheroes

Cyberheroes


Target: 10.201.62.16

Summary: Found a login page (login.html). Inspecting the page revealed client-side JavaScript that checks credentials by reversing a hard-coded string. The username and password can be derived from the script and used to either submit the form or request the flag file directly.


Discovery

Relevant JavaScript (as found in the page)

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 ;
        document.getElementById("todel").innerHTML = "";
        document.getElementById("rm").remove() ;
      }
    };
    xhttp.open("GET", "RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_"+a.value+"_"+b.value+".txt", true);
    xhttp.send();
  }
  else {
    alert("Incorrect Password, try again.. you got this hacker !")
  }
}

What the script does (plain English)

RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_<username>_<password>.txt

(constructed by concatenating the string with a.value and b.value).

Derived credentials

Note: the code uses a single & where you'd normally expect &&. In this context it still evaluates the conditional as intended, but it is sloppy JavaScript.

Fetch the flag directly (recommended)

Because the server fetches a predictable filename, you can request the file directly. Remember to URL-encode special characters (the @ becomes %40).

RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_h3ck3rBoi_SuperSecret@12345.txt
RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_h3ck3rBoi_SuperSecret%4012345.txt
curl -s "http://10.201.62.16/RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_h3ck3rBoi_SuperSecret%4012345.txt"
http://10.201.62.16/RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_h3ck3rBoi_SuperSecret%4012345.txt

If the file exists and is accessible, the server will return the flag contents.

Alternate: use the login form

  1. Open http://10.201.62.16/login.html in your browser.
  2. Enter h3ck3rBoi as username and SuperSecret@12345 as password.
  3. Submit — the page will run the JS and, on success, display the flag inside the page element with id flag (or it will remove some DOM elements as the script indicates).

Quick commands to reproduce locally

echo "54321@terceSrepuS" | rev
# -> SuperSecret@12345
python3 -c "print('54321@terceSrepuS'[::-1])"
# -> SuperSecret@12345
curl -s "http://10.201.62.16/RandomLo0o0o0o0o0o0o0o0o0o0gpath12345_Flag_h3ck3rBoi_SuperSecret%4012345.txt"

Notes & tips