arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

NodeJS - GraphQL Mutations

hashtag
Running the app on Docker

circle-check

Now that the app is running let's go hacking!

hashtag
Reconnaissance

The application implements a very basic mutation to create a new post on the blog. The mutation used is the following

If we look at the code we have a class CreatePost that will implement our logic to create a post.

The method mutate will just get the new Post object and insert an instance in the database.

hashtag
Exploit

There are many ways we could exploit this, one would be to create posts as another user:

Bingo! We have create a new post as another user. Let's refresh the page:

You could, of course, achieve the same goal with burp. What else can you exploit using this vulnerability?

hashtag
Additional resources

$ sudo docker pull blabla1337/owasp-skf-lab:js-graphql-mutations
$ sudo docker run -ti -p 127.0.0.1:5000:5000 blabla1337/owasp-skf-lab:js-graphql-mutations
mutation{
  createPost(title: "This is a new title", body: "This is a new post", author_id: 2 ){
    id
    title
    body
    author_id
  }
}
const mutationType = new graphql.GraphQLObjectType({
  name: "Mutation",
  fields: {
    createPost: {
      type: PostType,
      args: {
        title: {
          type: new graphql.GraphQLNonNull(graphql.GraphQLString),
        },
        body: {
          type: new graphql.GraphQLNonNull(graphql.GraphQLString),
        },
        author_id: { type: new graphql.GraphQLNonNull(graphql.GraphQLID) },
      },
      resolve: (root, { title, body, author_id }) => {
        return new Promise((resolve, reject) => {
          database.run(
            "INSERT INTO Posts (title, body, author_id) VALUES (?,?,?);",
            [title, body, author_id],
            (err) => {
              if (err) {
                reject(null);
              }
              database.get("SELECT last_insert_rowid() as id", (err, row) => {
                resolve({
                  id: row["id"],
                  title: title,
                  body: body,
                  author_id: author_id,
                });
              });
            }
          );
        });
      },
    },
  },
});
GraphQL - OWASP Cheat Sheet Seriescheatsheetseries.owasp.orgchevron-right
Logo

Python - GraphQL Mutations

hashtag
Running the app on Docker

circle-check

Now that the app is running let's go hacking!

hashtag
Reconnaissance

The application implements a very basic mutation to create a new post on the blog. The mutation used is the following

If we look at the code we have a class CreatePost that will implement our logic to create a post.

The method mutate will just get the new Post object and insert an instance in the database.

hashtag
Exploit

There are many ways we could exploit this, one would be to create posts as another user:

Bingo! We have create a new post as another user. Let's refresh the page:

You could, of course, achieve the same goal with burp. What else can you exploit using this vulnerability?

hashtag
Additional resources

$ sudo docker pull blabla1337/owasp-skf-lab:graphql-mutation
$ sudo docker run -ti -p 127.0.0.1:5000:5000 blabla1337/owasp-skf-lab:graphql-mutation
GraphQL - OWASP Cheat Sheet Seriescheatsheetseries.owasp.orgchevron-right
mutation {
  createPost(input: {body: "' -- ", title: "test_title", authorId: 2}) {
    post {
      body
      authorId
      title
    }
  }
}
class CreatePost(graphene.Mutation):
    """Mutation to create a post."""
    post = graphene.Field(lambda: PostObject, description="Post created by this mutation.")

    class Arguments:

        input = CreatePostInput(required=True)

    def mutate(self, info, input):

        post = Post(**input)
        db.session.add(post)
        db.session.commit()

        return CreatePost(post=post)
Logo

Java - GraphQL Mutations

hashtag
Running the app on Docker

circle-check

Now that the app is running let's go hacking!

hashtag
Reconnaissance

The application implements a very basic mutation to create a new post on the blog. The mutation used is the following

If we look at the code we have a class CreatePost that will implement our logic to create a post.

The method mutate will just get the new Post object and insert an instance in the database.

hashtag
Exploit

There are many ways we could exploit this, one would be to delete any post we want. If there is a createPost class there might be another class called deletePost, let's try:

Bingo! Post with id:4 was deleted. If we go back and refresh the application:

You could, of course, achieve the same goal with burp. What else can you exploit using this vulnerability?

hashtag
Additional resources

$ sudo docker pull blabla1337/owasp-skf-lab:java-graphql-mutation
$ sudo docker run -ti -p 127.0.0.1:5000:5000 blabla1337/owasp-skf-lab:java-graphql-mutation
GraphQL - OWASP Cheat Sheet Seriescheatsheetseries.owasp.orgchevron-right
mutation {
  createPost(title: "This is a new title", body: "This is a new post", author_id: 2) {
    id
    title
    body
  }
}
public Post createPost(String title, String body, int user_id) throws org.hibernate.exception.GenericJDBCException{
    Post post = new Post();
    post.setTitle(title);
    post.setBody(body);
    post.setUser(new User(user_id));
    postRepository.save(post);
    return post;
}
Logo

GraphQL Mutations