githubEdit

API Pentesting

Application Programming Interface (API) is for communicating with each computer. There are several types such as Web API, REST API, RESTful API.

API Subdomains Discovery

Reference: https://infosecwriteups.com/how-to-discover-api-subdomains-api-hacking-41ef91d00846arrow-up-right

api.example.com

# with another subdomain
sub.api.example.com
api.sub.example.com

# Versions
v1.api.example.com
v2.api.example.com
api.v1.example.com
api.v2.example.com

Google Dorks

site:*.api.example.com
site:api.*.example.com

# Random domains
site:*.api.*.*
site:api.*.*.*
site:*.api.*.com
site:api.*.*.com
site:*.api.*.gov
site:api.*.*.gov

Automation

Below fuzz target web server directly so be careful when doing that.

Change HTTP Request Methods

Change Content-Type

When trying to access or modify values in API, changing the Content-Type header may abuse the system.

Endpoint Discovery

Try to enumerate endpoints while changing HTTP methods like GET, POST, OPTIONS, etc.

Automation

This wordlistarrow-up-right{:target="_blank"} is useful for endpoints.

GET Parameters

Parameter Fuzzing

Sending Unexpected Data

We might be able to find anything by sending unexpected data on POST or PUT method.

XSS

If we can send post (or put) requests to API endpoints, we may be able to insert payloads and the result will be reflected as the output. XSSarrow-up-right can be used for this exploitation.

SQL Injection

Node.js Remote Code Execution (RCE)

If the website uses the Node (e.g. Express), we may be able to execute the JavaScript function.

Reverse Shell

We may be able to execute reverse shell using "child_process". First off, start listener for getting a shell in local machine.

Then send request to the website with the parameter which executes reverse shell using child_process.

We should see that we get a shell in local terminal.

Same Session Across Multiple Versions and Instances

For example, assumed the website has two endpoints such as "/api/v1/user/login", "/api/v2/user/login". "v1" uses "X-Token" and "v2" uses "X-Session". After login to "v1", you may be able to get access "v2" using the session key/value of "v1".

XXE

If the website displays the response in XML, we might be able to XXE.

References

Tools

General

REST

GraphQL

Tools

Resources

Common bugs

Tips

Last updated