White Hats - Nepal

Security research, bug bounty writeups, pentest notes

API Pentesting Methodology: A Pro Security Testing Guide

API pentesting methodology is a structured process for identifying security vulnerabilities in application programming interfaces by analyzing documentation, testing authentication, and probing endpoints for logic flaws. It focuses on unique threats like Broken Object Level Authorization (BOLA) and Mass Assignment that traditional web scanners often miss. A successful assessment requires moving beyond automated scans to understand how the API handles state, data ownership, and backend integration.

TL;DR:

Phase 1: Information Gathering and Attack Surface Mapping

The foundation of any API pentesting methodology is a thorough discovery phase. Unlike traditional web applications, APIs do not always have visible links. You are often hunting for hidden endpoints that support mobile apps or internal microservices. Start by looking for documentation. Developers frequently leave Swagger UI, ReDoc, or Postman collections exposed at common paths like /api-docs, /swagger.json, or /v1/swagger.yaml.

If documentation is missing, you must use subdomain enumeration tools to find staging or development environments where security controls might be relaxed. Use tools like subfinder or amass to locate assets like dev-api.target.com or api-staging.target.com. Often, these environments run older versions of the API that contain unpatched vulnerabilities. For a deeper dive into finding these assets, check out our guide on subdomain enumeration tools.

Directory and file brute-forcing is the next step. Use wordlists specifically designed for APIs, such as those found in the SecLists repository. Modern tools like Kiterunner are superior to traditional fuzzers for this task because they understand the structure of API routes (e.g., /api/v1/user/123). While standard tools are great, you should also refer to our directory brute-force tools guide to optimize your scanning speed and accuracy.

Key Takeaway: Never trust the documentation alone. Developers often forget to update Swagger files, leaving "shadow endpoints" active in the production environment that aren't listed in the official docs.

Once you have a list of endpoints, use a tool like Arjun to find hidden parameters. If an endpoint accepts {"username": "test"}, it might also accept {"role": "admin"} or {"is_public": true}. Finding these parameters is the first step toward exploiting Mass Assignment and logic flaws.

Phase 2: Testing Authentication and Session Management

Authentication in APIs usually relies on tokens (JWT, OAuth2) rather than cookies. Your goal is to bypass these mechanisms or assume the identity of another user. Start by testing for JWT (JSON Web Token) misconfigurations. Common flaws include tokens signed with the "none" algorithm, weak secret keys susceptible to brute-forcing, or lack of signature validation. If the API uses JWTs, use the Burp Suite JWT Editor extension to manipulate the payload and see if the server accepts unsigned or modified tokens.

For a complete walkthrough on using proxy tools for this, see our Burp Suite tutorial for pentesters. Beyond JWTs, check for token leakage. Sometimes tokens are passed in URL parameters, which are logged in web server logs or browser history. This is a significant security risk that leads to account takeover.

Another critical check is Token Invalidation. When a user logs out, the token should be blacklisted or deleted from the backend. If you can still use a token after a logout event, the API is vulnerable. Similarly, check for long-lived tokens. An access token that never expires is a goldmine for attackers who manage to steal one through a cross-site scripting (XSS) attack or other means.

Authentication Flaw Impact Testing Method
Weak JWT Secret Full Account Takeover Brute-force secret using Hashcat
None Algorithm Identity Spoofing Modify header to {"alg": "none"}
Improper Invalidation Session Hijacking Reuse token after logout
Lack of MFA Credential Stuffing Check for secondary auth requirements

Phase 3: Deep Dive into Authorization (BOLA and BFLA)

Broken Object Level Authorization (BOLA) is the most prevalent vulnerability in modern APIs. It occurs when a user can access or modify data belonging to another user by changing an ID in the request. For example, if a request to GET /api/v1/messages/1001 returns your message, changing it to GET /api/v1/messages/1002 might return someone else's private message.

To test for BOLA, you need at least two sets of credentials (User A and User B). Capture a request from User A, then replace the session token with User B's token while keeping the Object ID belonging to User A. If the request succeeds, you have found a BOLA vulnerability. This is different from Broken Function Level Authorization (BFLA), where a regular user can access administrative functions, such as POST /api/v1/admin/delete_user.

When testing for BFLA, map out the different roles within the application. Try to access endpoints meant for "Manager" or "Admin" roles using a "Customer" account. Often, developers only protect the UI and forget to implement server-side checks on the API endpoints themselves. This is why a systematic pentest checklist is vital to ensure you don't skip these manual authorization tests.

Key Takeaway: BOLA is not just about GET requests. Test PUT, POST, and DELETE methods. Deleting another user's resources is often more impactful than simply viewing them.

Phase 4: Exploiting Mass Assignment and Data Exposure

Mass Assignment occurs when an API takes user input and blindly applies it to a database model without filtering. This allows an attacker to modify sensitive fields that should be read-only. Imagine a user profile update request:


PATCH /api/v1/users/me
{
  "full_name": "John Doe",
  "email": "[email protected]"
}

An attacker might try to add a field like "is_admin": true or "account_balance": 99999. If the backend uses a framework like Ruby on Rails or Laravel with "fillable" attributes incorrectly configured, the database will update these protected fields. This is a common way to achieve privilege escalation.

Excessive Data Exposure is the sibling of Mass Assignment. It happens when the API returns more data than the client needs, relying on the frontend to filter the information. For example, a GET /api/v1/users/123 might return the user's full profile, including their hashed password, home address, and internal UUIDs, even if the UI only displays their username. Always inspect the raw JSON response in Burp Suite to see if sensitive data is being leaked.

You should also test for Injection Vulnerabilities. While SQL injection is less common in modern ORMs, it still exists. Furthermore, look for Server-Side Request Forgery (SSRF) if the API accepts URLs as input (e.g., for profile pictures or webhooks). An SSRF can allow you to pivot into the internal network or access cloud metadata services. For practical exploitation techniques, refer to our SSRF vulnerability example guide.

Phase 5: Rate Limiting and Business Logic Flaws

APIs are built for automation, which makes them prime targets for resource exhaustion. Without proper rate limiting, an attacker can perform thousands of requests per second, leading to a Denial of Service (DoS) or allowing for large-scale data scraping. Test for rate limiting on sensitive endpoints like login, password reset, and registration. If the API doesn't block you after 100 failed login attempts, it's vulnerable to credential stuffing.

Business logic flaws are unique to each application and require a deep understanding of the business process. For example, if an e-commerce API allows you to add a negative quantity of items to a cart, you might end up with a negative total price. Another common flaw is "Order State Manipulation," where you change the status of an order from "Pending" to "Shipped" via a PATCH request without actually paying.

Check for Race Conditions. If the API handles credits or balances, try sending multiple requests simultaneously to withdraw funds. If the backend doesn't use proper locking mechanisms, you might be able to withdraw more money than you actually have. This requires using Burp Suite's "Turbo Intruder" to send requests with sub-millisecond precision.

Key Takeaway: Rate limiting should be applied based on IP, API key, and User ID. Attackers can use distributed proxy networks to bypass IP-based limits, so user-level throttling is essential.

Essential Tools for API Penetration Testing

While manual testing is irreplaceable, the right tools speed up the process significantly. The following table summarizes the industry-standard tools used by professional security researchers for API assessments.

Tool Category Recommended Tools Primary Use Case
Proxy & Analysis Burp Suite, OWASP ZAP Intercepting and modifying traffic
Discovery Kiterunner, Feroxbuster Finding hidden endpoints and routes
Parameter Brute-force Arjun, Param Miner Finding hidden JSON keys and parameters
Client Simulation Postman, Insomnia Building and organizing API requests
JWT Testing jwt_tool, Joseph Automating JWT vulnerability checks

For those performing more traditional network-level assessments alongside their API testing, our network penetration testing methodology provides a broader context on how these services fit into the overall infrastructure security.

Common Vulnerabilities in Modern API Architectures

Modern APIs often use GraphQL as an alternative to REST. GraphQL introduces new attack vectors, such as Introspection Queries. If introspection is enabled, an attacker can query the __schema system field to get a complete map of all types, queries, and mutations. This is equivalent to finding a perfectly documented Swagger file. You should also check for Circular Queries in GraphQL, which can lead to DoS by forcing the server to process deeply nested objects (e.g., User -> Post -> User -> Post...).

Another rising concern is Insecure Direct Object References (IDOR) in cloud-native environments. When APIs interact with AWS S3 or Azure Blobs, they often generate pre-signed URLs. If these URLs are not properly restricted to the requesting user, anyone who guesses the URL can access private files. This is a variation of BOLA that occurs at the storage layer rather than the database layer.

Finally, don't ignore XML External Entity (XXE) if the API supports XML input. Even if the primary format is JSON, many APIs will still process XML if the Content-Type header is changed to application/xml. This can lead to local file disclosure or SSRF. We have a detailed XXE attack tutorial that explains how to identify and exploit this in legacy or multi-format APIs.

FAQ: People Also Ask

What is the difference between Web Pentesting and API Pentesting?
Web pentesting focuses on the frontend, DOM-based vulnerabilities, and user interface logic. API pentesting focuses on the backend data exchange, focusing on authorization (BOLA), mass assignment, and logic flaws that occur when systems communicate without a visual interface.

How do I start API pentesting if there is no documentation?
Start with "black-box" discovery. Use Kiterunner to scan for common routes and Kube-hunter if you suspect a Kubernetes environment. Monitor mobile app traffic using Burp Suite to see how the app communicates with the backend, which often reveals the API structure.

Is BOLA the same as IDOR?
Yes, Broken Object Level Authorization (BOLA) is the modern term used by the OWASP API Security Top 10 to describe what was traditionally known as Insecure Direct Object Reference (IDOR). The shift in terminology emphasizes that the flaw is fundamentally about a failure in authorization logic.

Which tool is best for finding hidden API parameters?
Arjun is currently the most effective tool for this. It uses a large wordlist and heuristic analysis to identify parameters that don't trigger errors but change the server's response, indicating they are being processed by the backend.

By following this API pentesting methodology, you move from simple automated scanning to a deep, logic-based assessment. The most impactful bugs are rarely found by clicking "scan" in a tool; they are found by understanding how data flows through the application and where the developers made assumptions about user intent. Always document your findings with clear reproduction steps and focus on the business impact to provide the most value during your security assessments.