API Penetration Testing PlayBook
API Penetration Testing PlayBook
Passive Reconnaissance :
-Google Hacking:
You can use google to find information about your target ,for
Example:
Google Query Parameters:
Query Purpose
operator
Intitle Searches page titles
Inurl Searches for words in the URL
Filetype Searches for desired file types
Site Limits a search to specific sites
-OWASP Amass:
Amass is a command line tool that can map a target’s external network by
collecting OSINT from over 55 different sources. You can set it to perform passive
or active scans.
The following is a passive scan of twitter.com, with grep used to show only API-
related results:
legacy-api.twitter.com
api1-backup.twitter.com
api3-backup.twitter.com
tdapi.twitter.com
failover-urls.api.twitter.com
cdn.api.twitter.com
pulseone-api.smfc.twitter.com
urls.api.twitter.com
api2.twitter.com
apistatus.twitter.com
apiwiki.twtter.com
Active Recon:
One shortcoming of performing passive reconnaissance is that you’re collecting information
from secondhand sources. As an API hacker, the best way to validate this information is to
obtain information directly from a target by port or vulnerability scanning, pinging, sending
HTTP requests, making API calls, and other forms of interaction with a target’s environment.
This section will focus on discovering an organization’s APIs using detection scanning, hands-on
analysis, and targeted scanning. The lab at the end of the chapter will show these techniques in
action.
The Active Recon Process:
The active recon process should lead to an efficient yet thorough investigation of the target
and reveal any weaknesses you can use to access the system.
Guest:
How would a new user use this site? Can new users interact with the API? Is API
documentation public? What actions can this group perform?
Authenticated User:
What can you do when authenticated that you couldn’t do as a guest? Can you upload files?
Can you explore new sectons of the web application? Can you use the API? How does the web
application recognize that a user is authenticated?
Administrator:
Where would site administrators log in to manage the web app? What is in the page source?
What comments have been left around various pages? What programming languages are in
use? What sections of the website are under development or experimental?
Next, analyze the app as a hacker by intercepting the HTTP traffic with Burp
Suite. When you use the web app’s search bar or attempt to authenticate, the
app might be using API requests to perform the requested action, and you’ll see
those requests in Burp Suite.
Once you find API directories like the /api directory shown in this output, either by crawling or
brute force, you can use Burp to investigate them further. Gobuster has additional options, and
you can list them using the -h option:
$ gobuster dir -h
If you would like to ignore certain response status codes, use the option -b. If you would like to
see additional status codes, use -x. You could enhance a Gobuster search with the following:
$ gobuster dir -u http://targetaddress/ -w /usr/share/wordlists/api_list/common_apis_160 -x
200,202,301 -b 302
As you can see, Kiterunner will provide you with a list of interesting paths. The fact that the
server is responding uniquely to requests to certain /api/ paths indicates that the API exists.
Note that we conducted this scan without any authorization headers, which the target API likely
requires. I will demonstrate how to use Kiterunner with authorization headers in Chapter 7. If
you want to use a text wordlist rather than a .kite file, use the brute option with the text file of
your choice:
$ kr brute -w ~/api/wordlists/data/automated/nameofwordlist.txt
If you have many targets, you can save a list of line-separated targets as a text file and use that
file as the target. You can use any of the following line-separated URI formats as input:
Test.com
Test2.com:443
http://test3.com
http://test4.com
http://test5.com:8888/api
One of the coolest Kiterunner features is the ability to replay requests. Thus, not only will you
have an interesting result to investigate, you will also be able to dissect exactly why that
request is interesting. In order to replay a request, copy the entire line of content into
Kiterunner, paste it using the kb replay option, and include the wordlist you used:
ATTACKING AUTHENTICATION:
Classic Authentication Attacks:
Password Brute-Force Attacks
Password Reset and Multifactor Authentication Brute-Force Attacks
Password Spraying
including Base64 Authentication in Brute-Force Attacks
Forging Tokens
Manual Load Analysis
Brute-Forcing Predictable Tokens
Fuzzing:
Choosing Fuzzing Payloads
Detecting Anomalies
Fuzzing Wide and Deep
Fuzzing Wide for Improper Assets Management
Testing Request Methods
Fuzzing “Deeper” to Bypass Input Sanitization
Fuzzing for Directory Traversal
EXPLOITING AUTHORIZATION:
-Testing for BOLA(Broken object Level Authorization)
• Swap out your UserA token for another user’s token
• Using UserB’s token, make the request for UserA’s resources
• Create multiple accounts at each privilege level to which you have access
• Using your accounts, create a resource with UserA’s account and attempt to interact
with it using UserB’s
Request Response
GET /api/user/test987123 404 Not Found HTTP/1.1
GET /api/user/hapihacker 405 Unauthorized HTTP/1.1 { }
GET /api/user/1337 405 Unauthorized HTTP/1.1 { }
GET /api/user/phone/2018675309 405 Unauthorized HTTP/1.1 { }
Injection:
Discovering Injection Vulnerabilities:
You should attempt injection attacks against all potential inputs and especially within the
following:
• API keys
• Tokens
• Headers
• Query strings in the URL
• Parameters in POST/PUT requests
Evasive Techniques:
• String Terminators
• Case Switching
• Encoding Payloads
Path Bypass