GraphQL injection

GraphQL is a query language for APIs and a runtime for fulfilling those queries with existing data. A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type

Summary

  • Tools

  • Exploit

    • Identify an injection point

    • Enumerate Database Schema via Instropection

    • Extract data

    • Extract data using edges/nodes

    • Extract data using projections

    • Enumerate the types' definition

    • Use mutations

    • NOSQL injection

    • SQL injection

    • GraphQL Batching Attacks

  • References

Tools

Exploit

Identify an injection point

Most of the time the graphql is located on the /graphql or /graphiql endpoint.

Check if errors are visible.

Enumerate Database Schema via Introspection

URL encoded query to dump the database schema.

URL decoded query to dump the database schema.

Single line query to dump the database schema without fragments.

List path

Extract data

HTB Help - GraphQL injection

Extract data using edges/nodes

Extract data using projections

⚠️ Don’t forget to escape the " inside the options.

Enumerate the types' definition

Enumerate the definition of interesting types using the following GraphQL query, replacing "User" with the chosen type

Use mutations

Mutations work like function, you can use them to interact with the GraphQL.

NOSQL injection

Use $regex, $ne frominside a search parameter.

SQL injection

Send a single quote ' inside a graphql parameter to trigger the SQL injection

Simple SQL injection inside a graphql field.

GraphQL Batching Attacks

Common scenario:

  • Password Brute-force Amplification Scenario

  • 2FA bypassing

References

Last updated