Resource Ebook API
Resource Ebook API
Publication Information
Summary This white paper is sponsored
This white paper demystifies API Author Information by Detectify.
fuzzing, why it should be incorporated Alissa Valentina Knight
into every API penetration test, and Partner Initial Date of Publication:
what free, open source fuzzers are Knight Ink August 2021
available and how to use them. 1980 Festival Plaza Drive Revision: 1.0
Suite 300
Las Vegas, NV 89135
ak@[Link]
2 GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
TABLE OF CONTENTS
06 07 08
§ Key Takeaways § Introduction § Problem Statement
§ Audience § When penetration testing
doesn’t include fuzzing
HOW TO FIND MORE VULNERABILITIES IN APIS THROUGH FUZZING 3
TABLE OF CONTENTS
09 11 14
§ API Fuzzers § The OpenAPI Specification § Fuzzing with Kiterunner
§ Methods of Generating Input § HTTP Methods, Headers, and Values § Overview
§ Content Discovery § Replaying Requests
§ Send to Burp Suite
4 GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
TABLE OF CONTENTS
23 26 28
§ Wrestling with RESTler § Conclusion § Sources
§ About The Author
§ About Knight Ink
§ About Detectify
HOW TO FIND MORE VULNERABILITIES IN APIS THROUGH FUZZING 5
KEY TAKEAWAYS
• Omitting fuzzing from your penetration testing other than a HTTP 403 or 404 error code
of APIs leaves vulnerabilities undetected that response from the EHR systems I was targeting
other tactics and techniques won’t find. in my vulnerability research campaign. When I
• Fuzz testing of APIs is setting the value of API finally did, it was a HTTP 200 and HTTP 415
operation parameters to a value that the response to a POST to an endpoint that I sent
developer didn’t expect to receive. to Burp and continued to manipulate within
• Because APIs process untrusted inputs, fuzzing Burp Repeater.
is fundamental to the penetration testing
process, often finding vulnerabilities missed by
static program analysis and manual code
inspection.
• Content discovery is the identification of
unlinked files and folders in a web application.
Specifically, when targeting APIs, it is an
effective tool when attempting to discover
undocumented API endpoints.
• API documentation is different from API
specifications, such as OpenAPI (formerly
Swagger). API documentation provides a
reference manual for both developers and non-
developers in how the API behaves and what
the expected inputs and responses are in plain
English.
• API specification files such as OpenAPI is a
format for describing an API, defining all its
available endpoints (such as /R4/patients) and
operations (such as PUT), supported
authentication methods, contact information,
and more. Currently at version 3, OpenAPI files
are clear text and written in specific languages,
such as YAML or JSON.
• HTTP verbs (methods) specifies a specific action
for the API endpoint to perform, such as GET,
POST (the most commonly used verbs), and for
REST APIs, PUT, PATCH, and DELETE. Each verb
corresponds to a particular action and expected
response code, such as 200 (OK). Meaning, the
action was performed successfully. 401
(Unauthorized) or 404 (Not Found), means the
file or resource doesn’t exist. Other response
codes exist, but these are the most common.
• Content discovery in APIs, specifically to the
end of discovering API endpoints requires
patience. It wasn’t until about two hours into
the scanning effort and attempting different
base URLs before I was able to get something
HOW TO FIND MORE VULNERABILITIES IN APIS THROUGH FUZZING 7
INTRODUCTION
Application programming interfaces (APIs) is Additionally, CISOs and other cybersecurity leaders
essentially a way to describe the protocols and can use this white paper to be better informed on
tools used for two systems to talk to each other — what their expectations should be of those
akin to a Rosetta Stone between applications that performing penetration tests of the APIs they are
allows them to talk that couldn’t previously responsible for securing and that the results of
understand each other without APIs. fuzzing are a fundamental part of the final report
delivered to them from the penetration tester(s)
A false sense of security is created when a Chief performing the work.
Information Security Officer (CISO) thinks her APIs
are secure simply because regular penetration
testing is performed. This false sense of security
can lead to an expensive data breach and loss to
customer and shareholder confidence.
Audience
This paper was written for red team members who
want to learn how to properly perform
comprehensive penetration testing of their APIs by
incorporating fuzzing into their tactics and
techniques used in testing.
8 GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
PROBLEM STATEMENT
Penetration testing of APIs performed today is SAST lacks context in security, meaning it doesn’t
profoundly inadequate if fuzzing isn’t performed understand how an API fulfills its contract or uses
as one of the tactics employed against the the data coming into it and is blind to third-party
endpoint. Many penetration testers don’t include libraries and frameworks where source code is
fuzzing in their repertoire of tactics and techniques typically not available. DAST was designed to send
either because: Web 1.0 style page parameter requests during the
running state of an application. DAST can not
1. They haven’t been exposed to fuzzing; invoke the API as it’s unaware of how to form the
2. Don’t know how to use fuzzing tools; or requests expected by the API endpoints. (Williams,
3. Don’t know how to properly interpret the J., 2015)
results.
API Fuzzers
This creates a false sense of security with the There are different taxonomies of fuzzers that
organization thinking all possible vulnerabilities leverage different techniques towards the same
were found for remediation, leaving potentially goal. While different people opine on what these
vulnerable APIs exposed to the internet. categories of fuzzers are, it’s generally accepted
that Microsoft’s taxonomy makes the most sense.
These include:
• Knowledge of Input;
• Knowledge of target application structure; and
• Method of generating new input.
Knowledge of Input
When Penetration Testing This category of fuzzers are also referred to as
Doesn’t Include Fuzzing “smart fuzzers” as they have a knowledge of the
application’s expected input and format. For
example, the encoding expected such as Base64 or
Vulnerability Scanners
Approaching penetration testing of web file-type, such as PE headers.
applications can be done using manual testing of
vulnerabilities in the OWASP Security Top 10, such Knowledge of Target Application Structure
Before I decompose the different taxonomies of
as SQL injection, cross-site scripting (XSS), and
fuzzers, it’s important to note that in the broader
more; and automated scanning using tools, but
these same scanners can’t be used to find hemisphere of testing is black box and white box
testing. In lay terms, white box testing is simply
vulnerabilities in APIs due to the nature of how
different APIs work from traditional web apps. where the tester or the tool has the requisite
information needed of the target that obviates the
need to figure it out (a la guessing) while black box
There are two types of approaches to identifying
vulnerabilities in applications, static application testing is the antithesis of that, ultimately
requiring the tester or the tool to figure it out on
security tools (SAST) and dynamic application
security tools (DAST). These scanners approach their own by hunting for the answers to those
questions.
vulnerability identification differently.
SAST performs what’s also referred to as “static In the application of fuzzers, the smartest fuzzers
will have full (white box) or partial (gray box)
code analysis” where the source code is checked
line-by-line for vulnerabilities, often responsible information on the target API.
for a lot of false positives.
HACKING APIS THROUGH FUZZING AND CONTENT DISCOVERY 9
API
FUZZERS
GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
10 GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
API FUZZERS
Method of Generating New Input search for files and folders of interest typically
Fuzzers are capable of generating the test input placed there with the different API frameworks.
data from scratch randomly or semi-randomly or
by taking pre-existing properly structured stimulus Routes and Endpoints
by mutating it to generate different permutations In traditional web applications, filenames and
for stimulus to evaluate how the target application folders are mapped to actual files and folders that
responds. exist on the web server, e.g.
[Link] which actually
This paper demonstrates the efficacy of two maps to a file on the web server called [Link].
different types of fuzzers, Kiterunner and RESTler However, in modern web applications, such as
and decomposes the idiosyncratic distinctions APIs, you’ll have a server
between them through the presentation of their [Link] which specifies a
empirical output run against public APIs. route. On the server is a routes file that points to a
snippit of code instead of an actual file. In the
Fuzzing should be used because it’s an effective latter example URI, /r4 is the API endpoint.
way to find security vulnerabilities in applications.
Content Discovery
Content discovery is the automated identification
of hidden/unlinked resources that aren’t visible or
able to be spidered in a target web application.
While content discovery tools date back several
decades, this class of tools have continued to
evolve from Web 1.0 to modern applications, such
as APIs to become more context-aware.
THE OPENAPI
SPECIFICATION
Fuzzing
WITH KITERUNNER
HOW TO FIND MORE VULNERABILITIES IN APIS THROUGH FUZZING 15
Linux
# scan away
kr scan [Link] -w [Link] -x 20 -j 100 --ignore-length=1053
Running with Kites access token and ships in the form of a JSON
1. Download large and small wordlists (.kite files) object.
from the Kiterunner Github page
The JSON datasets can be found below: If the API has implemented tokens, you’ll need to
• [Link] (118MB compressed, authenticate with the API using the Chromium
2.6GB decompressed) browser within Burp Suite for example, then copy
• [Link] (14MB compressed, and paste the token you receive into your
228MB decompressed) command line for Kiterunner in order to send
authenticated requests to the API. Otherwise, not
Alternatively, it is possible to download the doing so will result in a bunch of HTTP 403
compile .kite files from the links below: (FORBIDDEN) error messages rendering your
• [Link] (40MB compressed, 183M Kiterunner scan useless.
decompressed)
• [Link] (2MB compressed, 35MB In order to pass fields to the header of your
decompressed) requests within Kiterunner, pass the -H flag to
Kiterunner and specify your header fields, in our
2. kr scan [Link] -w [Link] case, the Bearer token between quotes. (Figure 3).
When wordlists are compiled from .txt files into # this will use the first 20000 lines in the api routes
.kite files, they are cached in wordlist
~/.cache/kiterunner/wordlists. An example of one
of the wordlists from the most recent list of $ kr scan <target> -A=apiroutes-
generated wordlists on [Link] can be found 210228:20000 -x 10 --ignore-length=34
in Figure 5 below.
Figure 6: Using Kiterunner replay to dig further into an HTTP response from the FHIR API server
Figure 8. Sending a HTTP 415 response code to Repeater in Burp for further tampering
WRESTLING
WITH RESTler
GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
24 GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
WRESTLING WITH
RESTler
RESTler, developed at Microsoft, is the world’s first 2. First, create the directory where you’ll be
stateful API fuzzer that automatically generates building RESTler
tests and automatic execution by first reading the 3. Switch to the repo root directory and run the
OpenAPI specification in order to automatically following Python script:
find vulnerabilities in the API.
$ python ./[Link] --dest_dir
A high-level picture for the first-time usage of <full_path_to_directory_you_created_in_st
RESTler can be found in Figure 9 below. ep_2>
Building RESTler
The following section is adapted from the build NOTE: If you receive a nuget error NU1403 when
instructions available on the Github repository for building, a quick workaround is to clear your cache
RESTler. with this command: $ dotnet nuget locals all--clear
Source: Microsoft
HOW TO FIND MORE VULNERABILITIES IN APIS THROUGH FUZZING 25
The below results are typical for an API that does An optional settings file can also be passed to
not require authentication and has a few GET RESTler by adding the command-line option --
endpoints without any input parameters. settings <path_to_settings_file.json>. For a list of
available settings, see SettingsFile.
• 29 requests (endpoint + method) were found in
the Swagger spec. Outputs: see the sub-directory FuzzLean or Fuzz
• 3 requests were attempted by RESTler. The (similar to Test)
other 26 were not attempted because RESTler
determined that they depend on outputs of RESTLer will generate a sub-directory
one of the requests that were executed, and a Fuzz[Lean]\RestlerResults\experiment<GUID>\logs
failure prevented that output resource from including the following files:
being available to the other requests.
• 2 requests were successful. • bug_buckets.txt reports bugs found by RESTler.
• The coverage is 7% (2/29) Those bugs are either "500 Internal Server
• There were no bugs found. Sometimes, bugs Errors" found by the RESTler "main_driver" or
are found in the quick start phase. property checker violations
CONCLUSION
HOW TO FIND MORE VULNERABILITIES IN APIS THROUGH FUZZING 27
Conclusion
I have performed dozens of penetration tests of
APIs in my career, from hacking healthcare APIs to
hacking federal and state law enforcement
vehicles through the manufacturer’s APIs giving
me remote control of the vehicles.
SOURCES
Assetnote. (n.d.). assetnote/kiterunner. GitHub. Retrieved June 22, 2021, from
[Link]
OWASP. (n.d.). Forced Browsing Software Attack | OWASP Foundation. Retrieved June
22, 2021, from [Link]
Li, V. (2020, January 26). Fuzzing Web Applications - The Startup. Medium.
[Link]
14a8b702dc61-1624248014&_branch_match_id=link-935370843063544148
RapidAPI. (2021, April 20). What is an API Endpoint? | API Endpoint Definition |
RapidAPI. The Last Call - RapidAPI Blog. [Link]
glossary/endpoint/
Todd Fredrich, Pearson eCollege. (n.d.). HTTP Methods for RESTful Services. Pearson
ECollege. Retrieved June 22, 2021, from
[Link]
RapidAPI. (2021b, April 23). What are API Parameters? | Parameters Definition | API
Glossary. The Last Call - RapidAPI Blog. [Link]
glossary/parameters/
Paxton-Fear, D. K. P.-F. (2021, April 14). API Recon with Kiterunner - Hacker Toolbox.
YouTube. [Link]
Our guide to fuzzing | F-Secure. (n.d.). F-Secure. Retrieved August 12, 2021, from
[Link]
Godefroid, P. (2020, March 4). A brief introduction to fuzzing and why it’s an important
tool for developers. Microsoft Research. [Link]
us/research/blog/a-brief-introduction-to-fuzzing-and-why-its-an-important-tool-for-
developers/
HOW TO FIND MORE VULNERABILITIES IN APIS THROUGH FUZZING 29
Williams, J. (2015, June 25). What Do You Mean My Security Tools Don’t Work on
APIs?!! Dark Reading. [Link]
you-mean-my-security-tools-don-t-work-on-apis-
Web API Fuzz Testing | GitLab. (n.d.). Gitlab. Retrieved August 12, 2021, from
[Link]
GitHub - microsoft/restler-fuzzer: RESTler is the first stateful REST API fuzzing tool for
automatically testing cloud services through their REST APIs and finding security and
reliability bugs in these services. (n.d.). GitHub. Retrieved August 13, 2021, from
[Link]
[Link]
30 GO FUZZ YOURSELF | BROUGHT TO YOU IN PARTNERSHIP WITH
ABOUT DETECTIFY
Firm Overview
Detectify offers cloud-based web
application security solutions that
streamline vulnerability findings in
production to security defenders and
application owners. Detectify
collaborates with ethical hackers to
source the latest security research from
hacker-into-scanner in as fast as 15
minutes. It leverages fuzzing and crawling
techniques and delivers reliable payload-
based testing to customers. This means
verified results and clearer visibility with
less noise. With Detectify you will bring
security up to speed and scale with
development, and go to market safer.