# vAPI

## ABOUT

vAPI (vulnerable Adversely Programmed Interface) is a self-hostable API that mimics OWASP top 10 API 2019 security risks scenarios through exercises.

## LAB SETUP

The lab used to solve the exercise is composed of an Ubuntu 22.04.2 LTS (Jammy Jellyfish) server (IP address 10.1.1.11) hosting the vAPI application on port 8008, and a Kali attacking machine (IP address 10.1.1.22). The vAPI web site is available at <http://10.1.1.11:8008>, and the documentation at <http://10.1.1.11:8008/vapi>

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/74a2e15b-fc71-48f7-8284-f03f7bcbcdda" alt=""><figcaption></figcaption></figure>

The exercise has been solved using Postman, Burpsuite and `ffuf`

## KEYWORDS

API, OWASP top 10 API, Postman, BOLA, mass assignment, excessive data exposure.

## REFERENCES

<https://github.com/roottusk/vapi>

<https://owasp.org/API-Security/editions/2019/en/0x11-t10/>

## API1. BOLA (Broken Object Level Authentication)

Similar to IDOR in the web applications context, BOLA vulnerabilities are related to API endpoints that receives an ID of an object, and fail to validate if the user is authorized to access or to perform the requested action on the requested object.

In Postman, create a new user `user8:password` by sending a POST request to `/vapi/api1/user`. The user ID is returned in case it is successfully created.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/cae3aecc-b34d-413f-948c-bbee79e0afbf" alt="" width="563"><figcaption></figcaption></figure></div>

The user's data is retrieved by sending a GET request with user ID and an authentication token. According to vAPI documentation, the authentication token is generated encoding base64 the string `username:password`

In our case, the authentication token is:

```bash
> echo -n "user8:password" | base64
dXNlcjg6cGFzc3dvcmQ=
```

Let's check if the authentication token works. Placing it in the request headers we successfully retrieve user details.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/85cdd65b-ceaf-474b-9286-79caf9aa806e" alt="" width="563"><figcaption></figcaption></figure></div>

As said before, the application would be vulnerable to BOLA if we could retrieve any user data just by changing the user ID. We verify that if we try querying user ID 1 we retrieve data for user Michael Scott.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/3faac750-c35c-4301-b048-6e51cdd98709" alt="" width="563"><figcaption></figcaption></figure></div>

The flag appears in the returned data.

## API2. BROKEN USER AUTHENTICATION

Broken authentication vulnerabilities are related to applications that fail to implement protection mechanisms against authentication attacks. Examples of vulnerable applications are those that allow credential stuffing or brute force attack on the same user account, those that fail to implement protection mechanisms such as captcha/account lockout, those that allow weak passwords, those that send authentication tokens and clear passwords in the URL or those that does not validate the authenticity of tokens and accepts unsigned/weakly signed JWT tokens (`"alg":"none"`).

According to documentation, there is some useful information in the `vapi/Resources` directory. In fact, in the location `/vapi/Resources/API2_CredentialStuffing` there is a list of possible credential pairs username/password. We can create two separate wordlists of users and passwords from it.

```bash
> cat API2_CredentialStuffing | cut -d',' -f 1 > usernames
> cat API2_CredentialStuffing | cut -d',' -f 2 > passwords
```

In order to launch a credential stuffing attack, we could use Burpsuite's intruder or `ffuf` (normally faster). To launch an attack with `ffuf`, first we capture a POST request to endpoint `/vapi/api2/user/login` and modify it adding a random credential of the list, we send it and let it fail (it returns 401 unauthorized login unsuccessful).

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/e7902e6d-f7d5-4934-95ac-f131852c7b55" alt=""><figcaption></figcaption></figure>

Right-click on the request and save to file `request.txt`, then modify it with a text editor to mark the fields to be fuzzed `FUZZEMAIL` and `FUZZPASSWORD`

{% code overflow="wrap" %}

```http
POST /vapi/api2/user/login HTTP/1.1
Host: 10.1.1.11:8008
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Cookie: language=en; welcomebanner_status=dismiss; XSRF-TOKEN=eyJpdiI6IlV0MjdTRjVYbW5YMFFOb2RSWStralE9PSIsInZhbHVlIjoiaVkrY1pjOE9VdDlTUjB4cTVWdnBzTG54dTQ4d1VXYUVUdEF3ZXc3cEpXeU9obVVrTENDVWJ6M0dsMmYwYXlhNHF5RExLTnpJbTN0OTNiWWNYT1ZVNWZVbUovUlVKRkJ6YzF2KytLNDFTKzY5MXBYU2Q4WGFKSnUxOEV3T0FoeXgiLCJtYWMiOiJjYjc1ZWM5NDUyNWU3ODI1MWM1ZWYyYzczOGYwZjM1NDBmZmZiNGQ0N2I1NjhmODNjYWM3ZDk3YmFiMGU1MDc4IiwidGFnIjoiIn0%3D; laravel_session=eyJpdiI6IkVENXYvMVFpZUlKUjJNdFZITnZYcmc9PSIsInZhbHVlIjoiTzBxdGJJTTVkaUJveGFaV1BSb05aSjYxZi9HVzMzcVBzTE1qczFzbHpxZ1pQNzBQMnV6akxhR1BxYURuZytWSVJ5ZnJxUktZWkdOUDMwajZLNlBxNkxsa3VFaW5TcjBJVSszMmxXbytQZWNSdyttc0JTYVgza1lGQzlxZG5PZmEiLCJtYWMiOiIwOTM0NjBlMmJiYmY2MWMxODhhYTY1YjEwYTk3ZjIxYzU4ZjY0YzcxN2NmMmM0YzYwZTc1OGRjZTgzNTIzNDEyIiwidGFnIjoiIn0%3D
Upgrade-Insecure-Requests: 1
Content-Length: 54
Content-Type: application/json;charset=UTF-8
 
{
  "email":"FUZZEMAIL",
  "password":"FUZZPASSWORD"
}
```

{% endcode %}

Now launch a pitchfork attack (credential stuffing) with `ffuf`. It combines first username with first password of each wordlist, second username with second password, third with third, and so on.

{% code overflow="wrap" %}

```bash
> ffuf -c -request request.txt -request-proto http -t 100 -fc 401 -w ./usernames:FUZZEMAIL -w ./passwords:FUZZPASSWORD -mode pitchfork
```

{% endcode %}

The attack reports 3 successful credentials (code: 200).

```bash
[Status: 200, Size: 89, Words: 1, Lines: 1, Duration: 8528ms]
    * FUZZEMAIL: savanna48@ortiz.com
    * FUZZPASSWORD: zTyBwV/9
 
[Status: 200, Size: 89, Words: 1, Lines: 1, Duration: 8336ms]
    * FUZZEMAIL: hauck.aletha@yahoo.com
    * FUZZPASSWORD: kU-wDE7r
 
[Status: 200, Size: 89, Words: 1, Lines: 1, Duration: 8425ms]
    * FUZZEMAIL: harber.leif@beatty.info
    * FUZZPASSWORD: kU-wDE7r
```

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/977c39d1-d4e4-4d62-a025-306345c8b76d" alt=""><figcaption></figcaption></figure>

Next step is to test this credential on the `/vapi/api2/user/login` endpoint using a POST request. Logging in with `hauck.aletha@yahoo.com:kU-wDE7r` we receive a successful login message, along with a token.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/a9597329-554e-40a0-b895-51a43e72b22b" alt="" width="563"><figcaption></figcaption></figure></div>

Finally, we send this token to the `/vapi/api2/user/details` endpoint.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/b62e04dd-e76f-4c0c-9b26-cb62b4447544" alt="" width="563"><figcaption></figcaption></figure></div>

The flag appears in the application response.

## API3. EXCESSIVE DATA EXPOSURE

Sometimes, API's are designed in such a way that they return sensitive data to the client, trusting that the client side developers will implement appropriate filters when presenting information to the user. However, an attacker can easily sniff the traffic and see the sensitive data.

Download and install the APK. For this write-up an android-x86 virtual machine running on Virtual Box has been used, Android Studio could also be used. Once installed, run the application and configure your vAPI server.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/c9e936aa-7ae9-46d9-9b7e-e3af9a64ca8e" alt="" width="563"><figcaption></figcaption></figure></div>

Create a new user and login. An application to post comments and replies comes into view.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/e7468b35-bea6-4df6-8b38-aad5f0074387" alt="" width="563"><figcaption></figcaption></figure></div>

Following the OWASP premises for this vulnerability, the API should be leaking user parameters that APK developer is filtering when presenting the comments to the user.

There are 2 methods to discover the information leaked by the endpoint depending on the Android virtual machine configuration used:

* If you use Android Studio Android, it can be configured to use Burpsuite as a proxy. Add a comment and capture the HTTP response.
* If using Android-x86 + Virtual Box, Burpsuite cannot be configured as a proxy. The alternative is to discover the endpoint used by the android app to manage comments and interact directly with it.

Since we are using Android-x86, we will follow the second option. For this, we fuzz for hidden endpoints in API3 and discover a hidden endpoint called `/vapi/api3/comment`

{% code overflow="wrap" %}

```bash
> ffuf -c -w /usr/share/seclists/SecLists-master/Discovery/Web-Content/api/objects.txt -t 100 -fc 500 -u http://10.1.1.11:8008/vapi/api3/FUZZ
```

{% endcode %}

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/43d5d99f-8e65-4a37-9000-45564af58038" alt="" width="563"><figcaption></figcaption></figure></div>

Simulating what the android app does, we query it with a GET request and see what information is leaked.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/ff0933d0-9c0b-460f-af0d-54c354f0309d" alt="" width="563"><figcaption></figcaption></figure></div>

The flag appears in one of the parameters returned, therefore, we verify the endpoint is leaking unnecessary information, which is later filtered by the app developers.

## API4. LACK OF RESOURCES & RATE LIMITING

Applications that do not limit the resources (network, CPU, memory, and storage) assigned to each client request are vulnerable to attacks where the user can send many results in shorts periods of time, and containing payloads of arbitrary size.

Sending a POST request to the `/vapi/api4/login` endpoint initiates an OTP-based login process. A 4-digit OTP is supposed to be sent to the indicated mobile phone.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/005fc8e3-7cc6-44b0-910e-a105421df88e" alt="" width="563"><figcaption></figcaption></figure></div>

Another endpoint `/vapi/api4/login` is used to verify the OTP by means of a POST request containing the received code.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/81fe9f40-ad42-42bf-87e4-5b4c5b0e2036" alt="" width="563"><figcaption></figcaption></figure></div>

Notice the OTP's are only 4-digit, so in theory they could be bruteforced if the application does not block massive amounts of user requests. This could be done with Burpsuite's intruder or `ffuf` (faster). Same as before, capture a request with Burpsuite, and save to a `request.txt` file.

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/4b916805-157e-4166-804a-e9af2e4cfae6" alt=""><figcaption></figcaption></figure>

Using a text editor, mark the field to bruteforce with the text `FUZZ`

{% code overflow="wrap" %}

```http
POST /vapi/api4/otp/verify HTTP/1.1
Host: 10.1.1.11:8008
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Cookie: language=en; welcomebanner_status=dismiss
Upgrade-Insecure-Requests: 1
Content-Length: 20
Content-Type: application/json;charset=UTF-8
 
{
  "otp": "FUZZ"
}
```

{% endcode %}

Next step is to generate a wordlist called `seq` of 9999 OTP's and launch the attack.

```bash
> ffuf -c -request request.txt -request-proto http -t 100 -fc 403 -w ./seq
```

The OTP found is 1872.

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/ccf0d43f-156a-469b-b99a-3288c320e8e7" alt=""><figcaption></figcaption></figure>

Next step is to verify the validity of the OTP by means of a GET request sent to the endpoint `/vapi/api4/otp/verify`

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/ea31861e-b084-4acf-b225-bb432322f929" alt="" width="563"><figcaption></figcaption></figure></div>

The bruteforced OTP is valid and an authentication token is received. Final step is to use the token to disclose user information on the `/vapi/api4/user` endpoint.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/515a7842-50a4-45ee-a5f7-fdd4ba6b44c8" alt="" width="563"><figcaption></figcaption></figure></div>

The flag appears in the HTTP response.

## API5. BFLA (Broken Function Level Authentication)

Applications vulnerable to BFLA are those that fail to verify if the user is authorized to perform certain actions on specific endpoints. For example, regular authenticated users may have access to restricted actions by simply changing the HTTP method (e.g., from GET to DELETE) or by simply guessing the endpoint URL and parameters (e.g., guess the endpoint `/api/v1/admin` from `/api/v1/users`). Whereas BOLA is related to authorization at an object level (e.g. ID's), BFLA is related to authorization issues at a function level (e.g. PUT, DELETE, POST or just changing the URL endpoint from `users` to `admin`).

POST a request to `/vapi/api5/user` to create a new user.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/a2ea1d67-ffa3-48e7-9da7-cf4b356e81d6" alt="" width="563"><figcaption></figcaption></figure></div>

A GET request sent to `/vapi/api5/user/10` allows us to retrieve the user details (10 is the ID we received when creating the user). This endpoint requires an authorization token, if we remember from API1, it is generated encoding base64 the string `username:password`

```bash
> echo -n 'bob:password' | base64
Ym9iOnBhc3N3b3Jk
```

Using this token we can query the user we have just created.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/5ed73971-7ffc-4cb2-b8f6-6e3a31d424c0" alt="" width="563"><figcaption></figcaption></figure></div>

Now, to exploit the BFLA vulnerability, we can either abuse a known endpoint using a method we are not supposed to have access to, or find hidden endpoints which are not supposed to be exposed to us (e.g. send requests to `/v1/admin` when we are supposed to have access only to `/v1/users`).

To find hidden endpoints, we use `ffuf` again.

{% code overflow="wrap" %}

```bash
> ffuf -c -w /usr/share/seclists/SecLists-master/Discovery/Web-Content/api/api-endpoints-res.txt -t 100 -fc 500 -u http://10.1.1.11:8008/vapi/api5/FUZZ
```

{% endcode %}

Which returns a hidden endpoint called `/vapi/api5/users`

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/7bb7dc42-a933-4de4-b0ad-ec075f6a7e51" alt=""><figcaption></figcaption></figure>

This is a hidden endpoint we are not supposed to have access to, since it returns a list of all the users of the database. Moreover, if we send a GET request to it, the endpoint fails to perform function-level authorization checks, since just providing token for `user3` the complete list of users is returned.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/6ce9e530-89a2-4ef4-9ab4-86b6ae26190d" alt="" width="563"><figcaption></figcaption></figure></div>

The flag appears in the HTTP response.

## API6. MASS ASSIGNMENT

Vulnerable applications allow users to update critical parameters directly, they automatically converts client parameters into internal object properties without considering the sensitivity and the exposure level of these properties. For example, when creating an account, a client should be able to exclusively update the username and password by means of a POST request. On the other hand, the client shouldn't be able to manipulate other parameter such as `isAdmin` or similar parameters which may be used by the application to determine the privilege level of the user.

Let's create a new user sending a post to endpoint `/vapi/api6/user`

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/d612bd7d-8cd5-4fbe-a536-f3f63aad7259" alt="" width="563"><figcaption></figcaption></figure></div>

This user can be queried later with a GET request to endpoint `/vapi/api6/user/me`, just adding the authorization token in the header.

As always, this is generated encoding base64 the string `username:password`

```bash
> echo -n 'test:password' | base64
dGVzdDpwYXNzd29yZA==
```

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/df02e720-57cf-497e-8a63-6bfd265d5618" alt="" width="563"><figcaption></figcaption></figure></div>

Notice the application leaks all the parameters of the user, including a previously unknown parameter called `credit`. A mass assignment vulnerability allows attackers to update all user parameters automatically and without considering the sensitivity of each one. Let's try to create a new user and assign him any credits we want; for example, 10000 credits.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/1ddfb13d-0c35-4e1d-9bd2-8fcd2700b81e" alt="" width="563"><figcaption></figcaption></figure></div>

It seems the application accepted the request. We will verify this by querying the new user data. First, generate the token for the new user.

```bash
> echo -n 'test2:password' | base64
dGVzdDI6cGFzc3dvcmQ=
```

Now, query the endpoint for user `test2` and inspect the output.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/4fd5cb82-0b78-4509-a2f1-04aa41503f36" alt="" width="563"><figcaption></figcaption></figure></div>

In fact, the application updated all the parameter, including the `credit` one. The flag appears in the HTTP response.

## API7. SECURITY MISCONFIGURATION

The API is vulnerable if appropriate security hardening is missing or improperly configured. Examples of security misconfigurations include: important security patches are missing, unnecessary features are enabled (e.g., HTTP verbs) or necessary ones are disabled (TLS, HTTPS, CORS policy).

POST a request to endpoint `/vapi/api7/user` to create a new user.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/495832a5-2010-4910-a1f5-ac1464d0a741" alt="" width="563"><figcaption></figcaption></figure></div>

Generate an authentication token.

```bash
> echo -n 'alice:password' | base64
YWxpY2U6cGFzc3dvcmQ=
```

Send a GET request to endpoint `/vapi/api7/user/login` to login with this user.

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/9c27d54d-3a92-456f-b51f-c6311007db1e" alt=""><figcaption></figcaption></figure>

Take note of the `phpessid` cookie, it will be used in the next request. Notice the documentation says something about a CORS vulnerability, these are exploited abusing the `Origin: header`

We will prepare an HTTP request in Postman. For this, first add the `phpessid` cookie.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/a1d1c56c-1d43-478d-9d87-4629d474c3c3" alt="" width="563"><figcaption></figcaption></figure></div>

Then, to exploit the CORS vulnerability we add a new `Origin:` header with an URL, no matter which one, and send the request.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/8b044cd5-2a6f-4bca-9103-32d2bab71b23" alt="" width="563"><figcaption></figcaption></figure></div>

The flag appears in the HTTP response.

## API8. INJECTION

When the API does not sanitize, filter or validate the user's input, it may be vulnerable to injection.

After some trial and error, a functional injection is found in the endpoint `/vapi/api8/user/login`

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/a46d729f-2d2b-444b-8f0e-e7e9b9287d57" alt=""><figcaption></figcaption></figure>

A basic SQLi is enough to bypass login and receive an authentication token.

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/22a3d614-e570-495b-b867-b70c46b15644" alt=""><figcaption></figcaption></figure>

And using this token in a GET request to endpoint `/vapi/api8/user/secret`, the application dumps the flag.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/8a476dcc-b9c2-43fe-b4a4-2042fe71ebe3" alt="" width="563"><figcaption></figcaption></figure></div>

If you want to play a bit more with this vulnerability, you can intercept a request with Burpsuite, save to file, and pass it to `sqlmap`. It will dump the entire application database (the API8 flag is in the table `a_p_i8_users`).

```bash
> sqlmap -r request.txt --dbms=mysql --dump
```

<figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/75484e44-ea83-4b75-b65c-92e5d3952c6c" alt=""><figcaption></figcaption></figure>

## API9. IMPROPER ASSETS MANAGEMENT

This vulnerability is related to outdated features still running in production environments due to a misconfiguration or because there is no plan for retirement or patching. For example, if a new `/V2` endpoint implementing new security features is already in production, it is advisable that older outdated `/V1` endpoints are retired or patched, or at least there is a retirement plan to do so.

Test the `/V2` endpoint with a post request to `/vapi/api9/v2/user/login`

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/e69f18fc-8024-4de9-814f-3ae19b0b5070" alt="" width="563"><figcaption></figcaption></figure></div>

A status code 200 is received; however, no authentication message is returned. It seems we need a valid PIN to login, since it is only 4-digits, we will try to bruteforce it with `ffuf`. As in previous steps, intercept an save a POST request and save to a text file. In the request file, mark as `FUZZ` the PIN field to be bruteforced by `ffuf`

{% code overflow="wrap" %}

```http
POST /vapi/api9/v2/user/login HTTP/1.1
Host: 10.1.1.11:8008
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Cookie: language=en; welcomebanner_status=dismiss; XSRF-TOKEN=eyJpdiI6Ikh0TDNDU0V1VC9HaXFoVENhRDFRYXc9PSIsInZhbHVlIjoianBSSTFIa0gxMmQrREI4cWtnVUo0QmN4eU5Tamk1V1BDOWN5UkVQcmRPeldoenZidzNjYTBOdExTVytsU2E5L1Y5eSs1cEh2SHA4MjdwWEVXaVBQV2s4K1BjMTMySkNnQnV6VndwSlBYMUNpT0xhbkl4QlZrb1N0bCtGcnlCb0oiLCJtYWMiOiJjYWE5NTg4ZWEwMjQzN2Q0ZjM5MzNhMjNlZDhkOWI0MmFhNTc4NTJmOTdiMjQxMWE0YmQzYjI1NTc5NTYwMzNkIiwidGFnIjoiIn0%3D; laravel_session=eyJpdiI6Im90aHQrZkNlQmJkSTduUTZ3OTJaL1E9PSIsInZhbHVlIjoiU3FzY3duNE5xMzBMWGZnNG5HbTRuNTQ4TGc5SzM2QlFNUTZsdlc5Q09GYm1vZnNzV0YrZ1BubWcxNHc3NHp3Y2VJbEZJTndhOGhFcXNIQUFhNEI1YkpuUThYQXpDOFNJampTbUZkNDViam9pSWQrWGpHS3lOZW9XVXhzaERuclgiLCJtYWMiOiIxZWU2MTNhNDIxNGE2OTI4NmViMDFkOTFhYzczZTQzNjdhYjFlZjBiZDI2YjEyM2IyZGEwOWQ3ZjBiYmE5MDJiIiwidGFnIjoiIn0%3D
Upgrade-Insecure-Requests: 1
Content-Length: 54
Content-Type: application/json;charset=UTF-8
 
{
  "username": "richardbranson",
  "pin": "FUZZ"
}
```

{% endcode %}

Generate a wordlist of possible PIN codes (from 0000 to 9999) and save the file as `seq`, then launch the `ffuf` attack.

```bash
> ffuf -request request.txt -c -w ./seq -t 100 -request-proto http
```

Shortly after, we begin receiving status 500 codes, meaning the server is somehow detecting and blocking bruteforce attacks.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/caeee728-461c-4898-926e-bccf48591ced" alt=""><figcaption></figcaption></figure></div>

It seems bruteforce protections have been implemented in the `/V2` endpoint. However, maybe there is an outdated `/V1` endpoint still in place which does not provide any protection. Check if `/V1` endpoint is still present in the host.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/a3fb26fe-de0d-417e-8900-78074c19020e" alt="" width="563"><figcaption></figcaption></figure></div>

We receive a status code 200, meaning the `/V1` endpoint has not been retired after entry into service of `/V2`. We will try to repeat the bruteforce process for the `/V1` endpoint. Modify the `request.txt` file to point to the `/V1` endpoint.

{% code overflow="wrap" %}

```http
POST /vapi/api9/v1/user/login HTTP/1.1
Host: 10.1.1.11:8008
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: close
Cookie: language=en; welcomebanner_status=dismiss; XSRF-TOKEN=eyJpdiI6Ikh0TDNDU0V1VC9HaXFoVENhRDFRYXc9PSIsInZhbHVlIjoianBSSTFIa0gxMmQrREI4cWtnVUo0QmN4eU5Tamk1V1BDOWN5UkVQcmRPeldoenZidzNjYTBOdExTVytsU2E5L1Y5eSs1cEh2SHA4MjdwWEVXaVBQV2s4K1BjMTMySkNnQnV6VndwSlBYMUNpT0xhbkl4QlZrb1N0bCtGcnlCb0oiLCJtYWMiOiJjYWE5NTg4ZWEwMjQzN2Q0ZjM5MzNhMjNlZDhkOWI0MmFhNTc4NTJmOTdiMjQxMWE0YmQzYjI1NTc5NTYwMzNkIiwidGFnIjoiIn0%3D; laravel_session=eyJpdiI6Im90aHQrZkNlQmJkSTduUTZ3OTJaL1E9PSIsInZhbHVlIjoiU3FzY3duNE5xMzBMWGZnNG5HbTRuNTQ4TGc5SzM2QlFNUTZsdlc5Q09GYm1vZnNzV0YrZ1BubWcxNHc3NHp3Y2VJbEZJTndhOGhFcXNIQUFhNEI1YkpuUThYQXpDOFNJampTbUZkNDViam9pSWQrWGpHS3lOZW9XVXhzaERuclgiLCJtYWMiOiIxZWU2MTNhNDIxNGE2OTI4NmViMDFkOTFhYzczZTQzNjdhYjFlZjBiZDI2YjEyM2IyZGEwOWQ3ZjBiYmE5MDJiIiwidGFnIjoiIn0%3D
Upgrade-Insecure-Requests: 1
Content-Length: 54
Content-Type: application/json;charset=UTF-8
 
{
  "username": "richardbranson",
  "pin": "FUZZ"
}
```

{% endcode %}

And re-launch the attack with `ffuf`, filtering requests with size 0.

```bash
> ffuf -request request.txt -c -w ./seq -t 100 -fs 0 -request-proto http
```

This time we find a working PIN 1655 returning status 200. So it seems the bruteforce protection was not implemented in `/V1` endpoint.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/d2cc30e9-ee22-463c-a3cb-03ee07525a83" alt="" width="563"><figcaption></figcaption></figure></div>

All that's left is logging in using PIN 1655.

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/e732b474-6952-4145-ab87-f3e89692ea98" alt="" width="563"><figcaption></figcaption></figure></div>

The flag appears in the HTTP response.

## API10. INSUFFICIENT LOGGING & MONITORING

Vulnerable applications does not produce any logs, or the logging level is not set correctly, or log messages do not include enough detail.

Just query the endpoint, the flag will be returned. Nothing was logged!

<div align="left"><figure><img src="https://github.com/g1vi/AllTheWriteUps/assets/120142960/3973d0a2-82a5-4f4c-aebd-7cb0aa98a1ca" alt="" width="563"><figcaption></figcaption></figure></div>


---

# 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://allthewriteups.gitbook.io/book/api/vapi.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.
