HTB Attacking GraphQL

📅 2026/7/6 1:38:10
HTB Attacking GraphQL
GraphQL是一种查询语言通常被 Web API 用作 REST 的替代方案。它允许客户端通过简单的语法获取所需数据同时提供 SQL 等查询语言通常具备的各种功能。与 REST API 类似GraphQL API 可以读取、更新、创建或删除数据。然而GraphQL API 通常实现在一个处理所有查询的单一端点上。因此与传统的 REST API 相比使用 GraphQL 的主要优势之一是资源利用率和请求处理效率更高。Question1.After executing an introspection query, what is the flag you can exfiltrate?git clone https://github.com/dolevf/graphw00fpython3 main.py -d -f -t http://154.57.164.67:31484识别出GraphQL接口并访问执行通用自省查询并使用https://apis.guru/graphql-voyager/将其可视化query IntrospectionQuery{__schema{queryType{name}mutationType{name}subscriptionType{name}types{...FullType}directives{name description locations args{...InputValue}}}}fragment FullType on __Type{kind name descriptionfields(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}}}}}}}}查询secrets得到flagQuestion2.After following the steps in the section, what is the flag you can find in the admins password?Question3.Exploit the SQL injection vulnerability to exfiltrate data from the database. What is the flag you find?查表查列flagQuestion4.What is the flag you find in the admin dashboard?Mutation 是 GraphQL 查询用于修改服务器数据。它们可用于创建新对象、更新现有对象或删除现有对象。执行自省查询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}}}}}}}}注册admin用户登录admin后台GraphQL漏洞预防漏洞预防信息披露为防止信息泄露漏洞应遵循通用的安全最佳实践。这些实践包括避免显示冗长的错误信息而应显示通用的错误信息。此外内省查询是获取信息的强大工具因此应尽可能禁用。至少应检查内省查询中是否泄露了任何敏感信息。如果发现泄露则必须删除所有敏感信息。注入攻击必须实施适当的输入验证检查以防止任何注入型攻击例如 SQL 注入、命令注入或 XSS 攻击。用户提供的任何数据在经过适当的清理之前都应视为不可信数据。应优先使用允许列表而非拒绝列表。拒绝服务攻击DoS如前所述拒绝服务攻击 (DoS) 和通过批处理放大暴力破解攻击是常见的 GraphQL 攻击途径。需要实施适当的限制来缓解此类攻击。这包括限制 GraphQL 查询深度或最大查询长度以及限制 GraphQL 端点的速率以防止快速连续执行多个查询。此外应尽可能禁用 GraphQL 查询中的批处理功能。如果必须使用批处理则需要限制查询深度。API设计为防止进一步的攻击例如针对不当访问控制例如 IDOR的攻击或因变更操作授权检查不当而导致的攻击应遵循通用的 API 安全最佳实践。这些最佳实践包括基于最小权限原则的严格访问控制措施。特别是GraphQL 端点应尽可能仅在成功身份验证后才能访问并应符合 API 的使用场景。此外必须实施授权检查以防止参与者执行未经授权的查询或变更操作。附https://github.com/dolevf/graphql-cop用于 GraphQL API 的安全审计工具python3 graphql-cop/graphql-cop.py -t http://172.17.0.2/graphqlSkills Assessment.Exploit the vulnerable GraphQL API to obtain the flag.执行通用自省查询并可视化查询activeApikeys查询allCustomerssql注入查到flag