Home

API Testing — Portswigger Labs (Part 1)

cover pic

Hey Friends.

This blog is based on the new module API testing from Portswigger Academy. I will explain some basic theory in short points. We are mostly focused on practical labs. Let’s get started.

What is API?

API stands for Application Programming Interface. It enables software systems and applications to communicate and share data. API testing is important as vulnerabilities in APIs may undermine core aspects of a website’s confidentiality, integrity, and availability.

Below is a small table demonstrating the Owasp top 10 API vulnerabilities.

API Recon

In this step, we need to collect as much information about the API.

For example:

GET /api/books HTTP/1.1
Host: example.com

The API endpoint for this request is /api/books. This results in an interaction with the API to retrieve a list of books from a library.

API Documentation

APIs are usually documented so that developers know how to use and integrate with them. Documentation can be in both human-readable and machine-readable forms, and it’s typically written in structured formats like JSON or XML. API documentation is often publicly available, particularly if the API is intended for use by external developers.

Discovering API Documentation

If API documentation isn’t openly available, there are ways to access it.

For example, if you find an endpoint like /api/swagger/v1/users/123, you should check the following paths:

/api/swagger/v1
/api/swagger
/api

Practical 1: Exploring an API endpoint using documentation

Challenge Description: To solve the lab, find the exposed API documentation and delete Carlos.

Before starting the challenge, make sure to start Burp Suite. Now, log in to the account using the credentials provided in the challenge description.

screenshot

After logging in to the account, you can see an option to update the email address. Type in a random email address in the field and click on “Update”.

screenshot

After changing the email address, navigate back to Burp and click on “HTTP history” under the proxy tab. Find the request with PATCH /api/user/wiener and send it to the Repeater.

screenshot

On the Repeater window, click on the “Send” button and check the response. You can see the user credentials in the response.

screenshot

Now, try to delete the /wiener from the path of the request and click on “Send” again. You will get an error in response.

screenshot

Remove /user from the path of the request, so the endpoint is now /api, then send the request. Notice that this retrieves API documentation.

screenshot

Right-click on the response and select “Show Response in Browser”. Copy the URL.

screenshot

Open any browser of your choice and paste the URL. You can now see the API documentation. Click on the “DELETE” row.

screenshot

Enter the name as Carlos, then click “Send Request”.

screenshot

After clicking on “Send Request”, notice that the “Lab successful” message pops up.

screenshot

That’s it for today. look forward to continuing our journey together in the next part. See you soon!

Happy Pentesting..!

Reference: https://portswigger.net/web-security/api-testing