> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/web-exploitation/login.md).

# login

### Login PicoCTF Writeup

“After getting access to the web page, I only saw a login pagenothing else. So I started Gobuster and found that index.js was available. Then I opened it"&#x20;

### The file contained the following obfuscated authentication logic:

```javascript
(async()=>{
await new Promise((e=>window.addEventListener("load",e))),
document.querySelector("form").addEventListener("submit",(e=>{
e.preventDefault();
const r={u:"input[name=username]",p:"input[name=password]"},
t={};
for(const e in r)
t[e]=btoa(document.querySelector(r[e]).value).replace(/=/g,"");

return "YWRtaW4"!==t.u
? alert("Incorrect Username")
: "cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ"!==t.p
? alert("Incorrect Password")
: void alert(`Correct Password! Your flag is ${atob(t.p)}.`)
}))
})();
```

***

### 🔎 Step 3 – Understanding the Logic

Key observations:

* The username and password are encoded using `btoa()` (Base64 encoding).
* Any `=` padding characters are removed using `.replace(/=/g,"")`.
* The encoded values are compared against hardcoded Base64 strings.
* If both values match, the password is decoded using `atob()` and displayed as the flag.

***

### Hardcoded Username (Base64)

```
YWRtaW4
```

Since Base64 requires proper padding, we add `=`:

```
YWRtaW4=
```

Decode it:

```bash
echo YWRtaW4= | base64 -d
```

Result:

```
admin
```

***

### Hardcoded Password (Base64)

```
cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ
```

Add padding:

```
cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ==
```

Decode it:

```bash
echo cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ== | base64 -d
```

Result:

```
picoCTF{53rv3r_53rv3r_53rv3r_53rv3r_53rv3r}
```

🔥 That is the flag.

***

### 🎯 Final Credentials

* **Username:** `admin`
* **Password:** `picoCTF{53rv3r_53rv3r_53rv3r_53rv3r_53rv3r}`

<img src="https://github.com/user-attachments/assets/51f2ed3f-74e8-43c6-90d6-c86ac67b0a0d" alt="image" height="361" width="736">

Done


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/web-exploitation/login.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
