我多年來一直在使用 REST API(作為消費者和開發人員),并且我才剛剛開始第一次使用 GraphQL API,特別是BurpSuite 的 Enterprise GraphQL API。我喜歡它,但我肯定缺少一些關鍵概念。
我試圖達到他們的GetScan終點:
curl -k -i -H "Content-Type: application/json" -H "Authorization: <MY_API_KEY>" -X GET -d '{ "query": "query GetScan ($id: ID!) { scan(id: $id) { id status agent { id name } site_application_logins { login_credentials { label username } recorded_logins { label } } audit_items { id issue_counts { total } number_of_requests } scan_configurations { id name } } }"}' 'https://mybsee.example.com/graphql/v1'
為了更容易閱讀,graphql 查詢也是:
query GetScan ($id: ID!) {
scan(id: $id) {
id status
agent { id name }
site_application_logins {
login_credentials { label username }
recorded_logins { label }
}
audit_items {
id
issue_counts { total }
number_of_requests
}
scan_configurations { id name }
}
},
variables {
$agent: "Firefox"
}
<MY_API_KEY>當我運行它時,上面有一個真正的價值(顯然,我不能在這里發布它)。與 URL 相同(例如,我有一個本地版本的 BurpSuite 正在運行mybsee.example.com)。
當我運行那個 curl 時,我得到以下輸出:
About to execute: query GetScan ($id: ID!) { scan(id: $id) { id status agent { id name } site_application_logins { login_credentials { label username } recorded_logins { label } } audit_items { id issue_counts { total } number_of_requests } scan_configurations { id name } } }
HTTP/2 200
date: Wed, 20 Oct 2021 23:33:50 GMT
x-frame-options: DENY
<lots of response headers omitted>
{"errors":[{"message":"Unexpected exception occurred. Check logs for more details.","extensions":{"code":77}}]}
我無權訪問服務器日志,所以我試圖排除客戶端的問題(GetScan對我來說是錯誤的呼叫)。有什么不對的人嗎?我是否應該向查詢中的任何欄位注入值,例如idorstatus等?如果是這樣,我如何(特別是)將查詢更改為有效?我也不確定是否需要將"query"JSON 欄位名稱附加到實際查詢中。
感謝您在這里提供的任何幫助。
更新
我確實意識到這不是一個完全可以回答的問題,因為不幸的是 BurpSuite API 是專有的,除非您購買產品或通過大量繁瑣的操作以獲得免費試用許可證,否則您無法從他們那里獲得 API 密鑰。
But more importantly, I'm not looking for anyone to fish for me here, I'm hoping someone can teach me how to fish. In reality I need to integrate with a lot more GraphQL endpoints besides this one, but if someone can show me the proper way to construct one query, I can take it from there.
uj5u.com熱心網友回復:
curl -k -i -H "Content-Type: application/json" -H "Authorization: Bearer <API_TOKEN>" -X POST -d "{ \"query\": \"$string\"}" '<API_URL>'
你幾乎所有的事情都做對了。只需將 HTTP 方法更改為 POST 而不是 GET。GET 將嘗試獲取整個頁面,另一方面 POST 將與 GraphQL API 互動。
盡管如此,在通過 HTTP 提供服務的GraphQL 頁面中指出,GET 方法也應該在某些限制下處理查詢。有關更多資訊,請參閱鏈接。
還可以考慮訪問其他網頁,這些網頁引導我解決這個問題;
GitHub 上的
GraphQL簡介使用 HTTP 方法發出 GraphQL 請求
Burp Suite Enterprise GraphQL 論壇討論與您的錯誤代碼相同
uj5u.com熱心網友回復:
最安全的方法是使用jq您的查詢及其引數生成正確轉義的 JSON。
構建一個函式來自動化:
# usage: gqlQuery http://ENDPOINT/graphql "$query" arg1=val1 arg2=val2 ...
gqlQuery() {
local endpoint query postBody
local -a jqArgs=( )
endpoint=$1; shift || return
query=$1; shift || return
while (( $# )); do
case $1 in
# the variable name "query" is used for passing in, well, the query
query=*) echo "ERROR: variable name query is reserved" >&2; return 1;;
# 'foo=JSON:["bar", "baz"]' passes ["bar", "baz"] as a list, not a string
*=JSON:*) jqArgs =( --argjson "${1%%=*}" "${1#*=}" ) ;;
# without JSON:, everything gets passed as a string to the child
*=*) jqArgs =( --arg "${1%%=*}" "${1#*=}" ) ;;
# arguments without a = are not recognized
*) echo "ERROR: Argument $1 not well-formed" >&2; return 1;;
esac
shift
done
postBody=$(jq -nc \
--arg query "$query" \
"${jqArgs[@]}" \
'{ "query": $query, "variables": ($ARGS.named | del(.query)) }'
) || return
curl --fail -XPOST \
-H 'Content-Type: application/json' \
-d "$postBody" "$endpoint"
}
...你可能會使用這樣的函式:
getScanQuery='query GetScan ($id: ID!) { scan(id: $id) { id status agent { id name } site_application_logins { login_credentials { label username } recorded_logins { label } } audit_items { id issue_counts { total } number_of_requests } scan_configurations { id name } } }'
myUrl=https://mybsee.example.com/graphql/v1
scanIdToRetrieve=1000 # replace with whatever is appropriate
result=$(golQuery "$myUrl" "$getScanQuery" id="$scanIdToRetrieve")
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/330819.html
