[英]How to detect GraphQL endpoint using Python
I am trying to detect a graphql endpoint using Python language.我正在尝试使用 Python 语言检测 graphql 端点。 I am an absolute beginner, but i have tried to make a code.我是一个绝对的初学者,但我试图编写代码。 Can you please suggest changes and better ways to do it?你能建议改变和更好的方法吗? CODE:代码:
import requests,urllib,urllib.request
import string
consoleDict = [
"",
"/graphql",
"/graphql/console",
"graphql.php",
"graphiql",
"explorer",
"altair",
"/playground"
]
for endpoint in consoleDict:
ep = ' http://159.100.248.211 '
response = requests.get(ep)
if response.status_code in [200,403]:
print("It is a GraphQL endpoint",endpoint)
Thank you:)谢谢:)
Even with gql
, you need the schema to ask for anything.即使使用gql
,您也需要架构来请求任何内容。 If you don't know it, you could use introspection query:如果您不知道,可以使用自省查询:
{
__schema {
types {
name
}
}
}
Some endpoints might have this disabled, but if you don't know the schema it is a good starting point.某些端点可能已禁用此功能,但如果您不知道架构,这是一个很好的起点。 Try with something like this:尝试这样的事情:
import json
import requests
from urllib import parse
paths = [
"",
"/graphql",
"/graphql/console",
"graphql.php",
"graphiql",
"explorer",
"altair",
"/playground"
]
query = """{
__schema {
types {
name
}
}
}
"""
for path in paths:
hostname = 'http://159.100.248.211'
endpoint = parse.urljoin(hostname, path)
try:
print(f"Attempt: {endpoint}")
response = requests.post(endpoint, json={'query': query}, timeout=0.1)
except Exception:
print("No GraphQL endpoint found")
else:
if response.status_code == 200:
json_data = json.loads(response.text)
if json_data.get('data'):
print("It is a GraphQL endpoint",endpoint)
Let mw know if this works让 mw 知道这是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.