API Security by APISec University
API Security by APISec University
##Introduction to API Reconnaissance
How an API is meant to be consumed will determine how easily it can be found.
- >
are meant to be easily found and used by end-users. Public APIs may be entirely public without authentication or be meant for use by authenticated users. Authentication for a public API primarily depends on the sensitivity of the data that is handled. If a public API only handles public information then there is no need for authentication, in most other instances authentication will be required. Public APIs are meant to be consumed by end-users. In order to facilitate this, API providers share documentation that serves as an instruction manual for a given API. This documentation should be end-user friendly and relatively straightforward to find.Public APIs - >
are intended to be used exclusively by partners of the provider. These might be harder to find if you are not a partner. Partner APIs may be documented, but documentation is often limited to the partner.Partner APIs - >
are intended for use, privately, within an organization. These APIs are often documented less than partner APIS, if at all, and if any documentation exists it is even harder to find.Private APIs
In all instances where API documentation is unavailable, we will need to know
.how to reverse engineer API requests
##Web API Indicators
. Typically, the API provider will market their API to developers who want to be consumers. So, it will often be very easy to find APIs, just by using a web application as an end-user. The goal here is to find APIs to attack and this can be accomplished by discovering the API itself or the API documentation. If you can find the target's API and documentation as an end-user then mission accomplished, you have successfully discovered an API.APIs meant for consumer use are meant to be easily discovered
- >Another way to find an API provided by a target is to look around the target's landing page. Look through
ora landing page for links to API
. When searching for APIs there are several signs that will indicate that you have discovered the existence of a web API. Be on the lookout for obvious URL naming schemes:development portal
https://target-name.com/api/v1 https://api.target-name.com/v1
- >Another indicator of
. The use ofweb APIs is the HTTP request and response headers
can be a good indicator that you have discovered an API. HTTP Request and Response Headers containingJSON or XML"Content-Type: application/json, application/xml"
##Passive Reconnaissance
is the act of obtainingPassive API Reconnaissance
about ainformation
target
with the target’s systems. When you take this approach, your goal is to find and documentwithout directly interacting
about your target’s attack surface.public information
Typically, passive reconnaissance leverages
, which is data collected from publicly available sources. You will be on the hunt foropen-source intelligence (OSINT)
.API endpoints, exposed credentials, version information, API documentation, and information about the API’s business purpose
###Google Dorking
Even without any
, finding an API as an end-user could be as easy as aDorking techniques
.quick search

However, sometimes you may not get the exact results you were hoping for. If you are getting too many irrelevant results then you could deploy some
to more effectively discover APIs.Google Dorking techniques
| Google Dorking Query | Expected Result |
|---|---|
| inurl:"/wp-json/wp/v2/users" | Finds all publicly available WordPress API user directories. |
| intitle:"index.of" intext:"api.txt" | Finds publicly available API key files. |
| inurl:"/api/v1" intext:"index of /" | Finds potentially interesting API directories. |
| ext:php inurl:"api.php?action=" | Finds all sites with a XenAPI SQL injection vulnerability. (Query from 2016 with currently ~141,000 results.) |
| intitle:"index of" api_key OR "api key" OR apiKey -pool | Lists potentially exposed API keys (favorite query). |
###GitDorking
Regardless of whether your target performs its own development, it’s worth checking
for sensitive information disclosure.GitHub (www.github.com)
. Searching GitHub for OSINT could reveal your target’s API capabilities, documentation, and secrets, such as API keys, passwords, and tokens, which could prove useful during an attack. Similar to Google Dorking, with GitHub, you can specify parameters like:Developers use GitHub to collaborate on software projects
- >filename:swagger.json
- >extension: .json
###TruffleHog
is a great tool forTruffleHog
. You can simply use the following Docker run to initiate a TruffleHog scan of your target's Github.automatically discovering exposed secrets
Example -
sudo docker run -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=target-nameFor additional information check out Trufflehog.
###Shodan
Shodan is the
forgo-to search engine
. Shodan regularly scans thedevices accessible from the internet
for systems withentire IPv4 address space
and makes their collected information public onopen ports
.https://shodan.io
The following table shows some useful Shodan queries.
| Shodan Query | Purpose |
|---|---|
| Performs a basic Shodan search for the target’s domain name. Often used as a foundation for more specific queries. |
| Filters results to those endpoints that respond with JSON, commonly used by APIs. |
| Filters results to endpoints serving XML, useful for discovering XML-based APIs. |
| Refines the search to endpoints that have returned a successful HTTP 200 response. Note: Some APIs may still return 300 or 400 status if the request is not properly formatted. |
| Finds web applications utilizing the WordPress API, indicating a WordPress backend. |
###The Wayback Machine
The Wayback Machine is an
. This is great for passive API reconnaissance because this allows you to check outarchive of various web pages over time
to your target.historical changes
If, for example, the target once advertised a partner API on their landing page, but now hides it behind an authenticated portal, then you might be able to spot that change using the Wayback Machine. Another use case would be to see changes to existing API documentation. If the API has not been managed well over time, then there is a chance that you could find retired endpoints that still exist even though the API provider believes them to be retired. These are known as Zombie APIs. Zombie APIs fall under the Improper Assets Management vulnerability on the OWASP API Security Top 10 list. Finding and comparing historical snapshots of API documentation can simplify testing for Improper Assets Management.
##Active Reconnaissance
Active reconnaissance is the process of interacting directly with the target primarily through the use of scanning. We will use our recon to search for our target's APIs and any useful information.
During this process you will be scanning systems, enumerating open ports, and finding ports that have services using HTTP.
###Nmap
Nmap is a
. For API discovery, you should runpowerful tool for scanning ports, searching for vulnerabilities, enumerating services, and discovering live hosts
in particular:two Nmap scans
. The Nmapgeneral detection and all port
scangeneral detection
anduses default scripts (-sC)
and then saves the output inservice enumeration (-sV) against a target
for later review (-oX for XML, -oN for Nmap, -oG for greppable, or -oA for all three):three formats
$ nmap -sC -sV [target address or network range] -oA nameofoutputThe Nmap all-port scan will quickly check all 65,535 TCP ports for running services, application versions, and host operating system in use:
$ nmap -p- [target address] -oA allportscanAs soon as the general detection scan begins returning results, kick off the all-port scan. Then begin your hands-on analysis of the results. You’ll most likely discover APIs by looking at the results related to HTTP traffic and other indications of web servers. Typically, you’ll find these running on ports 80 and 443, but an API can be hosted on all sorts of different ports. Once you discover a web server, you can perform HTTP enumeration using a Nmap NSE script (use -p to specify which ports you'd like to test).
$ nmap -sV --script=http-enum <target> -p 80,443,8000,8080###OWASP Amass
OWASP Amass is a
that can map acommand-line tool
. You can set it to performtarget’s external network by collecting OSINT from over 55 different sources
. If you choose the active option, Amass will collect information directly from the target by requesting its certificate information. Otherwise, it collects data from search engines (such as Google, Bing, and HackerOne), SSL certificate sources (such as GoogleCT, Censys, and FacebookCT), search APIs (such as Shodan, AlienVault, Cloudflare, and GitHub), and the web archive Wayback.passive or active scans
$ amass enum -active -d target-name.com | grep apiThis scan could reveal many unique API subdomains, including legacy-api.target-name.com. An API endpoint named legacy could be of particular interest because it seems to indicate an improper asset management vulnerability.
Amass has several useful command-line options. Use the intel command to collect SSL certificates, search reverse Whois records, and find ASN IDs associated with your target. Start by providing the command with target IP addresses
$ amass intel -addr [target IP addresses]If this scan is successful, it will provide you with domain names. These domains can then be passed to intel with the whois option to perform a reverse Whois lookup:
$ amass intel -d [target domain] –whoisThis could give you a ton of results. Focus on the interesting results that relate to your target organization. Once you have a list of interesting domains, upgrade to the enum subcommand to begin enumerating subdomains. If you specify the -passive option, Amass will refrain from directly interacting with your target:
$ amass enum -passive -d [target domain]The active enum scan will perform much of the same scan as the passive one, but it will add domain name resolution, attempt DNS zone transfers, and grab SSL certificate information:
$ amass enum -active -d [target domain]To up your game, add the -brute option to brute-force subdomains, -w to specify the API_superlist wordlist, and then the -dir option to send the output to the directory of your choice:
$ amass enum -active -brute -w /usr/share/wordlists/API_superlist -d [target domain] -dir [directory name] ###Gobuster
Gobuster can be used to
. (If you prefer a graphical user interface, check out OWASP’s Dirbuster.) In Gobuster, you can use wordlists for common directories and subdomains to automatically request every item in the wordlist and send them to a web server and filter the interesting server responses. The results generated from Gobuster will provide you with the URL path and the HTTP status response codes. (While you can brute-force URIs with Burp Suite’s Intruder, Burp Community Edition is much slower than Gobuster.)brute-force URIs and DNS subdomains from the command line
Whenever you’re using a brute-force tool, you’ll have to balance the size of the wordlist and the length of time needed to achieve results. Kali has directory wordlists stored under
that are thorough but will take some time to complete./usr/share/wordlists/dirbuster
Example -
$ gobuster dir -u target-name.com:<port> -w /home/kali/api/wordlists/common_apis_160###Kiterunner
is an excellent tool that was developed and released by Assetnote. Kiterunner is currently theKiterunner
. While directory brute force tools like Gobuster/Dirbuster/ work to discover URL paths, it typically relies on standard HTTP GET requests. Kiterunner will not only use all HTTP request methods common with APIs (GET, POST, PUT, and DELETE) but also mimic common API path structures. In other words, instead of requesting GET /api/v1/user/create, Kiterunner will try POST /api/v1/user/create, mimicking a more realistic request.best tool available for discovering API endpoints and resources
Example -
You can perform a quick scan of your target’s URL or IP address like this:
$ kr scan HTTP://127.0.0.1 -w ~/api/wordlists/data/kiterunner/routes-large.kite###DevTools
contains some highly underrated web application hacking tools. The following steps will help you easily and systematically filter through thousands of lines of code in order to find sensitive information in page sources. Begin by opening your target page, and then open DevTools with F12 or ctr-shift-I. Adjust the DevTools window until you have enough space to work with. Select the Network tab and then refresh the page (CTRL+R).DevTools