# Authentication Bypasses

## Authentication Bypass via Direct Access

### Direct Access

This code redirects the user to `/index.php` if the session is not active, i.e., if the user is not authenticated. However, the PHP script does not stop execution, resulting in protected information within the page being sent in the response body:

<figure><img src="/files/cN8mBHvagYrv5BSSteUu" alt=""><figcaption></figcaption></figure>

We can easily trick the browser into displaying the admin page by intercepting the response and changing the status code from `302` to `200`. To do this, enable `Intercept` in Burp. Afterward, browse to the `/admin.php` endpoint in the web browser. Next, right-click on the request and select `Do intercept > Response to this request` to intercept the response:

<figure><img src="/files/esVus5ty9ycIYYZmLcFe" alt=""><figcaption></figcaption></figure>

Afterward, forward the request by clicking on `Forward`. Since we intercepted the response, we can now edit it. To force the browser to display the content, we need to change the status code from `302 Found` to `200 OK`:

<figure><img src="/files/2v6Zt9huDXpUk6HC69fL" alt=""><figcaption></figcaption></figure>

To prevent the protected information from being returned in the body of the redirect response, the PHP script needs to exit after issuing the redirect:

```php
if(!$_SESSION['active']) {
	header("Location: index.php");
	exit;
}
```

### PoCs - Questions

* Apply what you learned in this section to bypass authentication to obtain the flag.

By intercepting the peticion request, modify the 302 to 200 OK

***

## Authentication Bypass via Parameter Modification

This type of vulnerability is closely related to authorization issues such as `Insecure Direct Object Reference (IDOR)` vulnerabilities, which are covered in more detail in the [Web Attacks](https://academy.hackthebox.com/module/details/134) module.

### Parameter Modification

Let us take a look at our target web application. This time, we are provided with credentials for the user `htb-stdnt`. After logging in, we are redirected to `/admin.php?user_id=183`:

<figure><img src="/files/Kj4d0QIlVKkeFJzZO8q2" alt=""><figcaption></figcaption></figure>

In our web browser, we can see that we seem to be lacking privileges, as we can only see a part of the available data:

<figure><img src="/files/jlFOkAA42Du1IhqdcTmG" alt=""><figcaption></figcaption></figure>

To investigate the purpose of the `user_id` parameter, let us remove it from our request to `/admin.php`. When doing so, we are redirected back to the login screen at `/index.php`, even though our session provided in the `PHPSESSID` cookie is still valid:

<figure><img src="/files/IZcrHdySxcBKFHmvMOXS" alt=""><figcaption></figcaption></figure>

Thus, we can assume that the parameter `user_id` is related to authentication. We can bypass authentication entirely by accessing the URL `/admin.php?user_id=183` directly:

<figure><img src="/files/epbzWNijeiHHLxEvaD2P" alt=""><figcaption></figcaption></figure>

Based on the parameter name `user_id`, we can infer that the parameter specifies the ID of the user accessing the page. If we can guess or brute-force the user ID of an administrator, we might be able to access the page with administrative privileges, thus revealing the admin information. We can use the techniques discussed in the `Brute-Force Attacks` sections to obtain an administrator ID. Afterward, we can obtain administrative privileges by specifying the admin's user ID in the `user_id` parameter.

### PoCs - Questions

* Apply what you learned in this section to bypass authentication to obtain the flag

To login with us credential and intercept te request, we can see it into dashboard -->

<figure><img src="/files/EB5YwAlJOQUFXX86xCjE" alt=""><figcaption></figcaption></figure>

Fuzzing it number with Intruder. The number of admin is `372`


---

# Agent Instructions: 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:

```
GET https://eldeim.gitbook.io/brain_fuck/notes/certifications/eastereggs/htb-cbbh/broken-authentication/authentication-bypasses.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
