36
RT in peace. Exploiting GraphQL SAULO HACHEM

Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

REST in peace. Exploiting GraphQLSAULO HACHEM

Page 2: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Who are you anyway?● Saulo Hachem● Security Analyst● CTF-Player● Shellter Labs Co-Founder

Page 3: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Disclaimer

Opinions are my own and not the views of my employer

Page 4: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Agenda- A quick look at REST APIs- What is GraphQL- Exploiting GraphQL- Security Recommendations

Page 5: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

REST

Page 6: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Regular ScenarioIn a “ToDo List” web application dashboard needs to:

- Display the username of that user- Display the titles of the buckets of a specific user.- Display the ‘todos’ of that bucket

Page 7: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

How does REST works?

Page 8: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

How does REST works?

Page 9: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

How does REST works?

Page 10: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

It’s not only one dashboard

Page 11: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Imagine Multiple Apps

Page 12: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

What if?

Page 13: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application
Page 14: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Little bit of History- Developed by Facebook- Source Released in 2015

Page 15: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Solving Problems- Exposes 1 endpoint- Minimize amount of data transferred (No more Over- and Underfetching)

- Fast development (Rapid Product Iterations on the Frontend)

- Works with any platform (React, Python, Angular, etc)- Database Agnostic- Query Language for APIs

Page 16: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

A few Concepts- Types- Queries- Mutations- Schemas- Resolvers

Page 17: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Type

Page 18: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Query Type

Page 19: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Query Type

Page 20: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Mutation Type

Page 21: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Schema- Defines the server API- Schema is simply a collection of GraphQL types- Root Types:

type Query { ... }type Mutation { ... }type Subscription { ... }

Page 22: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Schema

https://www.howtographql.com/basics/2-core-concepts/

Page 23: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Resolver- In its most basic form, a GraphQL server will have one resolver function

per field in its schema.

Page 24: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Exploiting

Page 25: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

ToolsGraphQL Payloads https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/GraphQL%20Injection

Insomnia https://insomnia.rest/graphql/

GraphQL Playground https://electronjs.org/apps/graphql-playground

GraphQL-Voyager https://apis.guru/graphql-voyager/

Page 26: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Exploiting GraphQL- Find the endpoint- Translate the query- Present GraphQL Playground- Show Insonia- Present documentation- Explains where it comes from (_schemas)- Test the query we captured- Add new values to the query- Error Messages- DoS Application- List all the items- Escalate to users data- SQL Injection

Page 27: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

ReconFinding the endpoint

GraphQL Playground (maybe?)

Read the Schema (Introspection System)

Documentation for free

Page 28: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Recon - Finding the endpoints/graphql

/graphiql

/graphql.php

/graphql/console

Page 29: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Recon - GraphQL Playground

Page 30: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Recon - Read Schema

Page 31: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Information Leakage

Page 32: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

SQL InjectionSQL Injection like everywhere else

query{ buckets(search: "home' UNION ALL SELECT 1,@@,3,4,5,6--"){ name }}

query{ buckets(search: "home' UNION ALL SELECT 1,name,3,4,5,6 FROM bucket_bucket--"){ name }}

Page 33: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

DoS - Depth Limit

Page 34: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Recommendations

Page 35: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Recommendations- Query Whitelisting- Depth Limiting- Write your resolvers correctly- Server-Side Validation Checks (as usual)- Careful with verbose messages- Have proper Access Control

Page 36: Exploiting GraphQL REST in peace. - The Long Con · - What is GraphQL - Exploiting GraphQL - Security Recommendations. REST. Regular Scenario In a “ToDo List” web application

Thanks!