Bypassing GraphQL brute force protections

4 min read Medium Portswigger
GraphQL API vulnerabilities
Contents

On this page

The lab

here is how portswigger describes it

The user login mechanism for this lab is powered by a GraphQL API. The API endpoint has a rate limiter that returns an error if it receives too many requests from the same origin in a short space of time. To solve the lab, brute force the login mechanism to sign in as carlos. Use the list of authentication lab passwords as your password source.

the new pieces in this lab#

the target has a rate limiter, so a normal password spray (one login per request) gets throttled fast. the trick is to collapse a whole wordlist into a single request using GraphQL aliases.

  • aliases: GraphQL lets you call the same field more than once in one operation by giving each call an alias, a label that renames the result so the responses don't collide. normally aliases just let you fetch, say, two users in one query (a: user(id:1) b: user(id:2)). here we abuse them to run the login mutation many times in one request, each with a different password.
  • why this beats the rate limiter: the rate limiter counts HTTP requests from an origin. a batch of 100 aliased logins is still one HTTP request, so it costs us a single tick against the limit while actually trying 100 passwords. the limiter never sees 100 attempts; it sees one. the defense is counting the wrong unit.
  • the success field: each login call returns fields like token and success. by requesting success on every alias, the single response tells us, per alias, whether that password worked, so we scan one response for success: true to find the hit. the method: confirm login is a GraphQL mutation and that a rate limit kicks in, generate 100 aliased login mutations (one per password, all for carlos) with a console script, send them as one request, search the response for true, and read off the winning password.

why the alias batch defeats the rate limit#

the rate limiter's job is to stop brute force by capping how many login attempts an origin can make, but it implements that by counting requests, on the assumption that one request equals one attempt. GraphQL breaks that assumption: a single operation can contain arbitrarily many aliased calls to the same mutation, so one request carries a hundred login attempts. the limiter increments its counter once and lets the request through, while the GraphQL engine dutifully evaluates all hundred logins and returns all hundred results. the mismatch is between the unit the defense measures (HTTP requests) and the unit that matters (authentication attempts), the same "two components disagree about what's being counted/parsed" pattern. because every alias also returns a success flag, the batched response is a complete brute-force result set in one round trip, invisible to the rate limiter.

Step 1 - capture the login mutation#

we access the lab, select My account, and attempt to log in with incorrect credentials. in Proxy > HTTP history we see login requests are sent as a GraphQL mutation. we right-click the login request and Send to Repeater.

1111

Step 2 - confirm the rate limit#

we attempt several more logins with incorrect credentials. after a short period, the API starts returning a rate limit error, so single-request-per-attempt brute force is throttled.

2222

Step 3 - generate the aliased mutations#

we craft a request that uses aliases to send many login mutations in one message. the whole list of aliases goes inside one mutation {}, each aliased login uses username carlos with a different password, and each requests the success field:

graphql
mutation {
    bruteforce0:login(input:{password: "123456", username: "carlos"}) {
        token
        success
    }
    bruteforce1:login(input:{password: "password", username: "carlos"}) {
        token
        success
    }
    ...
    bruteforce99:login(input:{password: "12345678", username: "carlos"}) {
        token
        success
    }
}

to build all 100 aliases quickly, we open the lab in Burp's browser, Inspect > Console, paste the provided generator script, and press Enter. it maps each password in the list to a bruteforceN:login(...) block and copies the full query to the clipboard:

js
copy(`123456,password,12345678,qwerty,...,moscow`.split(',').map((element,index)=>`
bruteforce$index:login(input:{password: "$password", username: "carlos"}) {
        token
        success
    }
`.replaceAll('$index',index).replaceAll('$password',element)).join('\n'));console.log("The query has been copied to your clipboard.");
3333

(when pasting into the Repeater request, we delete the variable dictionary and operationName field first, via the Pretty tab, so the batched query is the sole operation.)

Step 4 - send the batch and find the hit#

we send the single request containing all 100 aliased logins. the response lists each attempt with its success value. using the search bar below the response, we search for true to find which alias logged in successfully, then check that alias's block for the password it used.

4444

Step 5 - log in as carlos#

we log in to the site as carlos with the winning password.

5555

with this, the lab is solved!