CAPIE - Full Study Guide
CAPIE - Full Study Guide
What Is an API?
An API specifies the rules and protocols by which one piece of software can request and
receive services or data from another. In practical terms, you might have an API that allows a
mobile application to pull user profile information from a database, or a web service that
provides stock quotes. APIs come in various flavors—from operating system APIs to
database APIs—but our primary focus is on web APIs. Web APIs handle requests and
responses over the internet (most commonly through HTTP) and include popular styles like
REST and SOAP.
SOAP Basics
SOAP is a protocol that typically relies on XML to format messages. It can operate over several
network protocols (HTTP, SMTP, etc.) and has built-in error handling through its Fault element.
Because SOAP can be stateful, it’s often found in enterprise environments or legacy systems
requiring rigid standards like ACID transactions or WS-* compliance.
Example:
xml
KopiërenBewerken
<soap:Envelope xmlns:soap="[Link]
<soap:Body>
<m:GetStockPrice xmlns:m="[Link]
<m:StockName>GOOG</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
●
● Error Handling: Built-in via <soap:Fault>
● Use Cases: Large enterprise systems, banking transactions, and situations that demand
strict standards.
REST Fundamentals
REST is an architectural style (rather than a protocol) that uses existing HTTP methods (GET,
POST, PUT, DELETE) for communication. RESTful APIs are typically stateless and leverage
standard HTTP status codes to signal success or failure. They often use JSON, but can also
work with XML, HTML, or other formats.
Example:
bash
KopiërenBewerken
POST /stocks
{
"stock": "AAPL",
"price": "145.00"
}
●
● Error Handling: Standard HTTP status codes (e.g., 404 for Not Found, 500 for Server
Error)
● Security Considerations: REST APIs can implement any security mechanism that
rides on HTTP (TLS/SSL, OAuth, etc.).
● Use Cases: Modern web or mobile apps, microservices, public-facing APIs for third-
party integrations.
Key Differences
Aspect SOAP REST
Common Methods
1. Basic Authentication
2. API Keys
○ Useful for identifying the calling application, but doesn’t inherently tie to specific
users.
3. Bearer Tokens
○ Similar to API keys but often represent a user or client session more explicitly.
4. OAuth 2.0
○ Involves access tokens and refresh tokens, with multiple grant types
(Authorization Code, Client Credentials, etc.).
○ Easy to pass around, but must be carefully secured (e.g., use HTTPS, manage
signing secrets).
6. OpenID Connect
Other Considerations
● Rate Limiting: Prevents abusive use of APIs by restricting the number of requests
within a time window.
API Gateway
An API gateway acts as an entry point to route requests to the correct microservice or backend.
It can handle:
● Caching
● Rate limiting
GraphQL
An alternative to REST, GraphQL allows clients to request exactly the data they need via
queries and mutations. While powerful, poorly designed schemas can be vulnerable to
malicious queries (e.g., overfetching, batch attacks).
● Stateless: All necessary information for processing a request is contained within that
request itself. REST typically encourages stateless interactions.
Versioning
APIs evolve over time. Versioning strategies (in the URI, headers, or query parameters) help
ensure backward compatibility. However, maintaining outdated versions can become a security
and maintenance burden.
API Documentation
A well-documented API not only boosts developer productivity but also reduces the risk of
misconfiguration and misuse.
1. Endpoints & Methods: List your URLs (e.g., /users, /orders) and allowed methods
(GET, POST, etc.).
3. Request & Response Examples: Show real examples, including headers, body, and
expected status codes.
5. Authentication & Authorization: Outline how to obtain and use credentials, tokens, or
API keys.
● Swagger UI: Lets developers “try out” endpoints directly from the documentation.
Postman Collections
● Helpful for collaborative API testing.
● Collections can serve as live documentation: each request is stored with descriptions,
parameters, headers, and scripts.
Common Pitfalls
● Outdated or incomplete docs: Leads to confusion and integration errors.
● Security Oversight: Omitting how to properly handle tokens or lacking rate-limit info.
1. Explored what APIs are and why they’re integral to today’s software landscape.
2. Reviewed SOAP vs. REST, two foundational API styles with their own use cases and
security nuances.
In upcoming chapters, we’ll dive deeper into API security testing, examining common
vulnerabilities, pentesting methodologies, and real-world scenarios that show how attackers
target (and defenders secure) these critical interfaces. Stay tuned for more advanced topics on
API pentesting, including threat modeling, secure coding best practices, and penetration
testing tools specifically tailored for APIs.
Chapter 2: Tools to interact with an API
Once you understand the fundamentals of APIs—what they are, why they matter, and how
they’re structured—the next logical step is learning how to effectively communicate with
them. In this chapter, we explore a range of tools (cURL, Postman, SOAP UI, and Python) that
you can use to send requests and examine responses from APIs in different environments.
Whether you’re debugging a REST endpoint, testing a SOAP service, or writing automation
scripts, these tools are invaluable for day-to-day work.
bash
KopiërenBewerken
curl [Link]
bash
KopiërenBewerken
curl -X POST -d "username=john&password=pass123"
[Link]
●
Custom Headers:
bash
KopiërenBewerken
curl -H "Authorization: Bearer <TOKEN>"
[Link]
bash
KopiërenBewerken
curl -u username:password [Link]
Bearer Token:
bash
KopiërenBewerken
curl -H "Authorization: Bearer <TOKEN>" [Link]
endpoint
API Keys:
bash
KopiërenBewerken
curl -H "x-api-key: <API_KEY>" [Link]
bash
KopiërenBewerken
curl -d "param1=value1¶m2=value2" -X POST
[Link]
●
JSON Data:
bash
KopiërenBewerken
curl -X POST \
-H "Content-Type: application/json" \
-d '{"key1":"value1","key2":"value2"}' \
[Link]
● Verbose Output:
curl -v [Link]
● Cookies: Storing cookies with -c [Link] and reading them back with -b
[Link].
File Upload/Download:
bash
KopiërenBewerken
# Upload
curl -F "file=@/path/to/local/[Link]" -X POST
[Link]
# Download
curl -o [Link] [Link]
cURL’s versatility means you can handle everything from simple GET requests to multi-step
authenticated sessions. It’s a must-have tool for quickly testing endpoints in real time.
3. Send the request and view the response status code, headers, and body in the
Postman interface.
● Environments: Store variables for different setups (e.g., dev vs. production).
● Collaboration: Share collections and environments with team members, reducing setup
time and ensuring consistency.
● Pre-request Scripts & Tests: Automate steps before and after requests using
JavaScript.
● Runner & Newman: Execute an entire collection in sequence or integrate with CI/CD
pipelines via Newman (Postman’s command-line runner).
● Mock Servers: Create mock endpoints to simulate server responses for front-end
testing.
With Postman, you can rapidly prototype and document your APIs, while also automating
certain tasks such as integration testing or performance checks.
3.1 Introduction
● History & Role: Initially focused on SOAP-based web services, SOAP UI has grown to
support REST, making it a comprehensive testing tool for many protocols.
● SOAP Envelope Essentials: Understand how the envelope, header, and body structure
your SOAP message.
● Assertions: Validate parts of the XML response (e.g., checking for certain tags or
values).
● Assertions & Test Cases: Similar to SOAP, you can set up REST test steps and
assertions to ensure the response meets expectations.
● Property Transfer: Share data (like tokens or IDs) between test steps.
● Groovy Scripting: Extend functionality with custom scripts for logic or advanced
assertions.
● Security Testing: Basic scans for SQL injection, XSS, and other vulnerabilities.
● Mock Services: Simulate endpoints and responses for local or offline testing.
SOAP UI’s structured approach makes it well-suited for comprehensive regression testing or
continuous integration environments—especially where both SOAP and REST services
coexist.
○ Beginner-friendly syntax
○ Rich ecosystem of libraries for HTTP requests, JSON handling, and more
python
KopiërenBewerken
import requests
response = [Link]('[Link]
print(response.status_code)
print([Link]())
POST Example:
python
KopiërenBewerken
data = {'key': 'value'}
response = [Link]('[Link] data=data)
print([Link])
python
KopiërenBewerken
params = {'search': 'python', 'page': 2}
response = [Link]('[Link] params=params)
Exception Handling:
python
KopiërenBewerken
try:
response = [Link]('[Link] timeout=5)
response.raise_for_status()
except [Link] as e:
print("An error occurred:", e)
File Operations:
python
KopiërenBewerken
# Upload
files = {'file': open('[Link]', 'rb')}
response = [Link]('[Link]
files=files)
# Download
with open('[Link]', 'wb') as f:
[Link]([Link])
●
● Session Management: Persist cookies, headers, and other settings across multiple
requests using [Link]().
● Data Processing: Pull data from an API, transform it, and store it in a database.
● cURL: Powerful command-line utility for quick requests and automation scripts in shell
environments.
● Postman: Intuitive GUI for organizing requests, collaborating with teams, and quickly
testing various endpoints.
● Python: Ideal for scripting and automation, leveraging the popular requests library for
straightforward HTTP interactions.
In practice, teams often use a combination of these tools depending on their workflows. For
example, a developer might prototype a request in Postman, then automate it later with Python.
A QA engineer might set up SOAP UI for structured regression tests and still use cURL to
quickly test server responses.
Going Forward:
● You can now confidently interact with both RESTful and SOAP services.
● Next steps might include exploring best practices for each tool (e.g., advanced scripting
in Postman, groovy scripts in SOAP UI) or delving deeper into performance testing and
security validation with these utilities.
● As you progress, consider how to incorporate these tools into your broader CI/CD
pipelines to ensure ongoing quality and security checks for your APIs.
By mastering these core technologies, you’ll be better positioned to debug, test, and secure
APIs, ensuring seamless integration and robust performance across diverse software
ecosystems.
Chapter 3: The OWASP API Top 10 - 2019
APIs are the connective tissue of modern software, linking mobile clients, web applications, IoT
devices, and backend services. With APIs taking center stage in digital transformation,
vulnerabilities targeting them have also risen sharply. In 2019, the Open Web Application
Security Project (OWASP) released its OWASP API Top 10, outlining the most critical API
weaknesses frequently exploited by attackers. Below is an expanded look at each category,
illustrating how these vulnerabilities manifest, how they can be tested, and which remediation
strategies help mitigate them.
Real-World Example
Pentesting Focus
● Enumerate and test object IDs in URL paths, body parameters, or query strings.
● Attempt horizontal privilege escalation (e.g., normal user accessing another user’s data).
Remediation
● Enforce server-side authorization checks whenever accessing or modifying an object.
Real-World Example
● Unsecured Session IDs: Session tokens remain valid long after a user logs out,
allowing attackers to reuse them for unauthorized access.
Pentesting Focus
● Evaluate login endpoints for potential brute force or credential stuffing attacks (if
permitted).
Remediation
● Implement strong password requirements and lockouts for repeated failures.
● Use JWT or secure session tokens with short lifetimes and robust invalidation.
Real-World Example
● Leaked PII: A mobile banking application’s JSON response contains user addresses,
phone numbers, and account status fields, even though only the user’s first name and
balance are needed by the front-end.
Pentesting Focus
● Intercept and review responses carefully for sensitive fields.
Remediation
● Filter and whitelist the exact fields the client needs.
● Use DTOs (Data Transfer Objects) to explicitly define what data is returned.
Real-World Example
● Bulk Request Spam: Automated scripts send thousands of requests per second to an
e-commerce API, crippling performance.
Pentesting Focus
● Attempt repeated login attempts to see if the service imposes lockouts or rate-limits.
● Send large payloads (e.g., multiple megabytes) to detect any enforced size threshold.
Remediation
● Implement rate-limiting or throttling policies at the application or gateway level.
● Set payload size limits and define graceful failure scenarios for oversized requests.
Real-World Example
Pentesting Focus
● Map the API’s available functions and endpoints, identifying those exclusive to certain
roles.
Remediation
● Use RBAC (Role-Based Access Control) or ABAC (Attribute-Based Access
Control) to restrict sensitive endpoints.
● Ensure consistent role/permission checks in both the application and any microservices
or gateway layers.
6. Mass Assignment
Description
Modern frameworks often provide auto-binding of request data to server-side models. Mass
Assignment exploits this by injecting extra parameters into the request that map to fields a
user shouldn’t control—potentially changing user roles, payment statuses, or other critical fields.
Real-World Example
● Privilege Escalation: A user includes "role": "admin" in the JSON body while
signing up, and the server automatically sets the new user’s role to admin.
Pentesting Focus
● Add extra or guessed parameters to requests to see if they modify restricted fields.
● Look for hints in responses (Excessive Data Exposure) that reveal internal field names.
Remediation
● Use whitelists for allowable fields.
● Adopt DTOs that explicitly define the properties permitted in incoming data.
7. Security Misconfiguration
Description
APIs—and the servers hosting them—rely on numerous components: web servers, databases,
frameworks, or cloud services. Security Misconfiguration arises when default or weak settings
persist, unneeded ports remain open, or verbose error messages give away internal details.
Real-World Example
● Exposed Admin Interfaces: A test environment with default admin credentials or open
debugging endpoints.
Pentesting Focus
● Check for unused features or misconfigured HTTP methods (e.g., PUT, DELETE left
open).
● Scan for open ports, default passwords, or directory listings.
Remediation
● Harden servers: remove defaults, disable unused services, and set least privilege.
● Configure frameworks securely: restrict directories, enforce HTTPS, sanitize error logs.
8. Injection
Description
Injection vulnerabilities occur when untrusted data is fed into an interpreter—like SQL, NoSQL,
OS commands, or LDAP—without proper sanitization or parameterization. This can lead to
unauthorized data access, data manipulation, or even remote code execution.
Real-World Example
Pentesting Focus
● Provide malicious inputs in request parameters and observe if the server returns unusual
errors or behaviors.
● Test for time-based or blind injections by measuring response times or side effects.
Remediation
● Always use parameterized queries or prepared statements.
Real-World Example
● Deprecated API: An outdated version (v1) remains functional, containing unpatched
vulnerabilities from a year ago.
Pentesting Focus
● Attempt connections to these endpoints and see if they are less secure.
Remediation
● Implement an API lifecycle policy: deprecate, retire, or patch old endpoints.
Real-World Example
● Failed Login Flood: Attackers attempt thousands of password guesses, and the system
does not log or alert admins.
Pentesting Focus
● Generate suspicious activity (invalid tokens, repeated login failures, etc.) and see if any
alerts are triggered.
● Check for the presence of logs that detail errors, warnings, and usage patterns.
Remediation
● Log all critical events (auth changes, new user creations, admin actions).
● Integrate logs into monitoring and alerting systems, like SIEM solutions.
Conclusion
From insufficient authorization checks to insecure defaults, each vulnerability in the OWASP
API Top 10 (2019) highlights a distinct weakness that adversaries routinely exploit. By
understanding and mitigating these issues, teams can establish a robust baseline of API
security. While this list isn’t exhaustive, it provides a vital starting point for pentesters,
developers, and security engineers aiming to build, test, or maintain safer APIs. Going
forward, continuous monitoring, testing, and compliance checks are essential in keeping
pace with evolving threats—and ensuring that APIs remain the reliable backbone of modern
applications.
Chapter 4: The OWASP API Top 10 - 2023
As APIs increasingly serve as the backbone of modern applications—from mobile apps to IoT
devices—the attack surface they create continues to expand. The OWASP API Security Top
10 (2023) provides vital insights into the most critical API security risks plaguing organizations
today. Below, you’ll find each category explained, along with common exploit scenarios and
mitigation strategies.
Exploit Example
● A malicious user enumerates possible user or order IDs and accesses sensitive data
belonging to other accounts.
Mitigation
● Enforce server-side authorization checks on every request.
2. Broken Authentication
What It Is
APIs rely on robust authentication systems (passwords, tokens, multi-factor mechanisms) to
validate users or clients. When these fail—through poor password policies, insecure token
management, or missing session timeouts—attackers can log in as other users or hijack active
sessions.
Exploit Example
● Weak password requirements allow brute-forcing, or session tokens stay valid even after
logout, enabling attackers to reuse them.
Mitigation
● Implement strong credentials and enforce secure password reset flows.
Exploit Example
● An API automatically maps any JSON field to the database model. The attacker includes
extra fields ("isAdmin": true) to escalate privileges or modify protected data.
Mitigation
● Whitelist only allowable properties in incoming JSON or form data.
● Use Data Transfer Objects (DTOs) to separate internal models from external inputs.
Exploit Example
● Sending massive JSON payloads repeatedly, consuming excessive memory or CPU on
the server, leading to degraded performance or downtime.
Mitigation
● Implement rate limiting (e.g., request throttling) at the API gateway or server.
Exploit Example
Mitigation
● Enforce role-based or attribute-based checks for sensitive functions.
● Validate user privileges on every endpoint, not just the front-end interface.
● Keep a well-documented list of which roles can call which API methods.
Exploit Example
● A malicious user calls a special endpoint for “bulkDeleteAccounts” or
“bulkExportRecords,” which lacks any additional checks because it’s rarely used in
normal user flows.
Mitigation
● Mark business-critical endpoints and apply stricter authentication/authorization or
additional verification steps (e.g., MFA).
Exploit Example
Mitigation
● Restrict outbound requests to a whitelist of allowed domains or IP ranges.
● Segment network architecture so that API servers have limited internal resource access.
8. Security Misconfiguration
What It Is
APIs run on complex stacks—web servers, frameworks, containers, microservices. Security
Misconfiguration covers default or weak configurations, leaving debug endpoints, open ports,
or verbose error messages accessible to attackers.
Exploit Example
Mitigation
● Regularly audit configurations and remove unnecessary services or endpoints.
Exploit Example
● Attackers discover /api/v1/ or /test/ endpoints that still exist in production and
contain unpatched vulnerabilities.
Mitigation
● Track all public-facing APIs using inventory tools or API gateways.
● Deprecate or patch old versions promptly; retire them fully when no longer needed.
Exploit Example
● An internal microservice calls a partner API for order processing. The partner’s API is
compromised and sends malicious data that triggers a downstream injection in the
consuming service.
Mitigation
● Validate and sanitize all external data—even from trusted vendors.
● Implement version pinning and robust input checks for third-party libraries or services.
● Use zero-trust principles when designing integrations, limiting the blast radius if an
external service is compromised.
Chapter 5: API Pentesting Documentation
\Modern API pentesting goes beyond the technical act of finding vulnerabilities. It also involves
planning the test, documenting results, and coordinating with stakeholders. This chapter
covers three critical aspects of that workflow:
2. Test Report – Detailing the vulnerabilities discovered and how to fix them.
3. Test Debrief Meeting – Reviewing the findings, remediations, and lessons learned with
all relevant parties.
● Objective: Identify and remediate potential security issues across all APIs.
By aligning the team on what will be tested (and how), the Test Plan minimizes confusion and
ensures you can measure success objectively once the engagement is complete.
● Findings:
A strong test report not only exposes vulnerabilities, but also guides the development or
security teams in fixing them.
4. Lessons Learned: Assess the test plan’s coverage; identify missed areas or new
insights.
5. Planning for Next Steps: Set schedules for patching, retesting, and future pentests.
When well-structured, the Test Debrief Meeting encourages clear communication among all
roles, ensuring the discovered issues are understood, prioritized, and resolved.
● Data exposure
● Schema Validation: Apply strict JSON schema or XML schema checks to ensure only
valid request structures are accepted.
● Authentication Checks: Optionally integrate with OAuth, JWT verification, or API key
validation.
1. Send valid requests to confirm the API works as expected behind the firewall.
2. Try malicious payloads (e.g., SQL injection strings, overly large requests) to verify the
firewall blocks them.
3. Review logs to ensure you have clarity around which requests are accepted, rejected,
or flagged for follow-up.
● Bug bounty programs where the business invites ethical hackers to find vulnerabilities.
The goal is always to improve defenses, not to exploit them for harm.
○ Mitigation: Strictly define and allow only necessary HTTP methods. Monitor
unusual method usage.
3. Header Manipulation
○ Request Smuggling: Crafting requests such that the firewall and backend parse
them differently, leading to partial validation or incorrect routing.
● Smuggling Attacks: High-profile breach where request smuggling led to partial checks
from the firewall, ultimately exposing user sessions.
● Security Culture: Share findings across dev, ops, and security teams so everyone can
detect new bypass methods early.