API stands for Application Programming Interface, mainly used as a service to serve its user and it can provide wide range variety of utility depends on how the developer design it. It is not surprise that many application including web and mobile have adapted this technology into their backend architecture. Nevertheless, every developer and hacker should pay attention to its security to ensure it is not abuse by malicious actor.
In this blog i will show you how to test an API by using Python and Postman. To test the API i used Tireful API. It is a web app intentionally developed to be insecure. The purpose of the app to teach developers, QA or security professionals about flaws present in webservices (REST API) due to insecure coding practice. Following are the scenarios implemented.
- Information Disclosure
- Insecure Direct Object Reference
- Access Control
- Throttling
- SQL Injection
- Cross Site Scripting
Setup The API:
i used python environment utility to isolate the installation of the prerequisite library of Tiredful API so it is not interfere with other package in my original python package.to use virtual environment in python, use this command:
~# sudo apt install virtualenv
create a virtualenv:
~# virtualenv -p python env
the following command will create a virtual environment in Python 2 with the environment name of env
run the following command to make sure it is setup properly:
~# ls env/lib
activate the virtual environment with:
~# source env/bin/activate
Now that we have activate our virtual environment, next step is to install all the necessary package to run the Tiredful-API:
After the setup is complete, you can run it with the following command:
It will host the API at localhost:8000
Challenge: Information Disclosure
Postman:
using postman, you can send any request to the API, basically postman have create a very nice GUI that let user have a nice experience to do API testing. You can just put the URL api and press send.
The top bar is the url target and the lower part is the result. As you can see we got a json like response from the API. The challenge in this section is to find an information disclosure from the API this means we have to trigger some error that will cause the API to spill unwanted information from its backend (stacktrace).
I try several string such as special character and it give me some error regarding the map application. This happen due to the debug settings in django, in order to prevent this to happen you should make the debug to False.
and i found out if you put a capital letter to the ISBN it will show a stacktrace log to your response.
Python:
in order to send API request with python you can use python library "requests". The library is pretty easy to use you can customize the packet and also create your own payload.
The script is super simple is just send a GET request and get the response.
Challenge: Insecure Direct Object Reference
Postman:
in order to send a request to the api you need to have an authentication token to platform. To generate it, go to the user token page and enter a listed credential (username and password) to get the token.to use it you need to include "Authentication" tag to the request and the value must follow the format (Bearer <token>)
in the section description the exam-id is in format of:
- MQ== => 1
- Mg== => 2
to send a request you can use the "pm" object with sendRequest method and of course because that in order to interact the api you need to provide an authorization in the header once you done the response will log into the postman console (crtl+alt+c)
the final script going to look like this:
the script is simply loop to 100 and convert the integer to a base64 encode and send it to the backend API and only show to the console if the HTTP response is 200. After the script is run we got two more exam result.
Python:
using python is going to just add couple of line in our script. The following is the python script:we use headers parameter in our script so the authentication tag is send along with the GET request
and the result is going to be like this:
Thank you have a nice day :)
Comments
Post a Comment