# Vampi

## General info, Get it and deploy it

* [Official repo](https://github.com/erev0s/VAmPI)

### Infos

#### List of Vulnerabilities

> This is the list from the documentation\
> To keep track, I will check everytime I find one

* [x] SQLi Injection
* [x] Unauthorized Password Change
* [x] Broken Object Level Authorization
* [x] Mass Assignment
* [x] Excessive Data Exposure through debug endpoint
* [x] User and Password Enumeration
* [x] RegexDOS (Denial of Service)
* [x] Lack of Resources & Rate Limiting

### Deploy it

To deploy it I used Docker

* `docker run -p 5000:5000 erev0s/vampi:latest`

![Deployed](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-2f048234d1435c0ac4d90db0abc26edffb5d1c73%2F2024-01-08-07-47-09.png?alt=media)

#### Use Swagger editor

* Go [here](https://editor.swagger.io/)
* Get the yaml in your local machine from [here](https://github.com/erev0s/VAmPI/blob/master/openapi_specs/openapi3.yml) or `wget https://raw.githubusercontent.com/erev0s/VAmPI/master/openapi_specs/openapi3.yml`
* Then you can play in the browser with the request and you get a full list of requests\
  ![swagger editor](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-e5218084674e5b0b49ee02fd01e54f611134bf22%2F2024-01-08-08-00-16.png?alt=media)

## Hack it

* First thing we would usually do is to enumerate a little, however, we do have the doc here so it seems to be enough for now. We can dive in.
* Launch burp or zap (I will be using burp)
* I am going to look around a little and then try to exploit the vulnerabilities mentionned in the list from the doc (that I pasted above)

If we access <http://127.0.0.1:5000/> we get this page

![Home page](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-beb97de496fa4a6f36241032b9f0025b120dbb17%2F2024-01-08-07-51-04.png?alt=media)

We already have some data but let's still try the request to create the db just to see what happens.

![createdb](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-084f996d115325b46906fb89a4a531a1128faa9b%2F2024-01-08-08-51-49.png?alt=media)

### Create a user

We can do this with a post request on the endpoint `/users/v1/register`

![Creat a user](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-591908c0d813ffc002dfeafd9bcdd76bec78d886%2F2024-01-08-09-21-11.png?alt=media)

### Vulnerability: Create an admin user = Mass assignment

We are not suppose to be able to create an admin user but if we use the previous endpoint but add in the json the parameter `"admin": true,` we are able to create our admin user.

![Create admin user](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-cb6ecbb53414da37881391e49a9855d02eb2cbda%2F2024-01-08-09-24-31.png?alt=media)

We can see that our user is indeed created.

![Admin user created](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-b93f5fb5e59397800d24ef3bb20c08c0d9dd8892%2F2024-01-08-10-10-24.png?alt=media)

### Login

Once we created a user we can use it to login by issuing a post request on this endpoint `/users/v1/login`. This way, we will get a token.

![login](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-060ea626700f3e20548f1bfc102a36cbf228a819%2F2024-01-08-10-29-19.png?alt=media)

Then when we will need to do something with a logged in user we will just have to specify the token we just got like this in our request header:

```http
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDQ3Mjc3NDgsImlhdCI6MTcwNDcyNzY4OCwic3ViIjoiY3NieWdiIn0.OyXjErURxhzD62lZpmRaHmvONniGZyjq6KlTQoq6fqs
```

### Vulnerability: Excessive Data Exposure through debug endpoint

We have a request to list the users and we have an even more interesting request `/users/v1/_debug` that gives also the users passwords.\
So this is definitely excessive data exposure

![users debug](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-c23e835471bf39ea43b7dc79bc28e3361dc997b8%2F2024-01-08-08-58-31.png?alt=media)

### User enumeration

When trying to login with a non existent user we have the response "Username does not exist".

![user does not exist](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-bb08e8b752e0a4b91090524d9e3a7a7f7ca2ece5%2F2024-01-08-09-29-46.png?alt=media)

Another way to enumerate user is to try to find a specific user using the endpoint `/users/v1/{username}` with a get request.

* When a user exists we get this

![user exists](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-cc3576ba0e3ea492349c63abb30d293ae0b10256%2F2024-01-08-10-43-56.png?alt=media)

* When it does not we get this:

![user does not exist](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-6252999166df35b7fe1aa60262fd700d138c340e%2F2024-01-08-10-44-46.png?alt=media)

### Password enumeration

We have a way of knowing if a password is correct or not. This vulnerability is really helpful for bruteforce attacks.

If we try to login with an existing user but with a wrong password, we get a specific message "Password is not correct for the given username.".

![password enumeration](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-d10d18176d5381e02bc993cdd6eb8d0ea5da1fd1%2F2024-01-08-09-33-34.png?alt=media)

### Unauthorized Password Change

When issuing a PUT request on this endpoint, we can change our password `/users/v1/<username>/password`.\
But can we change another user password.\
Let's try to change the password of `admin` user with my token of the csbygb non admin user.\
It works!

* Request to change the password of admin with csbygb user's token

![change password of another user](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-b0bd6e78ada8e6598484f477a48b7977f57f5316%2F2024-01-08-10-37-49.png?alt=media)

* The password of admin has changed

![admin user's password changed](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-2f56ad1527cc1714344d7aa3417c463a42cd4543%2F2024-01-08-10-39-00.png?alt=media)

### SQL Injection

If we add a quote in the request to get the users we get a sql error

![SQL error](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-c6f7226c52601d493b3a9808cc817ada2cd627ba%2F2024-01-08-10-53-40.png?alt=media)

```sql
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unrecognized token: "'John.Doe''"
[SQL: SELECT * FROM users WHERE username = 'John.Doe'']
(Background on this error at: https://sqlalche.me/e/20/e3q8)
```

* So here we know now that the database is sqlite At this point we can continue with sqlmap and this will dump the db `sqlmap -u http://localhost:5000/users/v1/csbygb* --dbms=sqlite --dump`

![Dumped database](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-69d718790b901449ad896230158d702bdbd6094a%2F2024-01-08-11-57-00.png?alt=media)

### Vulnerability: BOLA

We can find books that do not belong to us. Using the book title as the ID with this endpoint `/books/v1/{book-title}`

So here with the token of my user csbygb I am able to access a book that belongs to the user name1.

![bola](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-9abd5ba1438e183ee139d20b70afa1c21ee32c05%2F2024-01-08-13-21-10.png?alt=media)

### Lack of Resources & Rate Limiting

Here we are able to send a lot of request without being blocked in anyway by the application.\
For example we can send plenty of requests to bruteforce the login.\
I am going to use burp (pro version) intruder for this. I send the login request to the intruder, I set up variables on username and password.

![set variables](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-f66e273f441d4c8ada1be50e6a67597372385fdd%2F2024-01-08-13-28-31.png?alt=media)

So here we were able to send more than 800 request without being blocked

![no rate limiting](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-6663569271b8325b5cd292884e81b68f39a75e4e%2F2024-01-08-13-40-19.png?alt=media)

### ReDos

> For the reference of this vulnerability on OWASP, you can find it [here](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS)

So we could try one of the regex provided in the OWASP document.\
We could try this on this endpoint `/users/v1/{username}/email` if we issue a put request here we are suppose to be able to update our email address.\
We need to be logged in for this.\
Using this request we were able to trigger the vulnerability and dos the application.

![Denial of service](https://1679624655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEkk28J0B2BeDMuesRMr1%2Fuploads%2Fgit-blob-da9665d4aa30fc18ca153a01f3b5a30861c6ca27%2F2024-01-08-14-32-08.png?alt=media)

> Avoid to do this in real context except if it is a request or if you have the authorization of you customer. With these types of attack you are actually impacting the availability of the application.

## Resources

* [OWASP API Securiy TOP 10 - 2023](https://owasp.org/API-Security/editions/2023/en/0x00-header/)

### ReDos - Resources

* [The Regular Expression Denial of Service (ReDoS) cheat-sheet - James Davis](https://levelup.gitconnected.com/the-regular-expression-denial-of-service-redos-cheat-sheet-a78d0ed7d865)
* [ReDos on OWASP](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS)
* [Regular expression Denial of Service - ReDoS - Hacktricks](https://book.hacktricks.xyz/pentesting-web/regular-expression-denial-of-service-redos)
