Remote File Inclusion is a technique to include remote files and into a vulnerable application. Like Local File Inclusion, the RFI occurs when improperly sanitizing user input, allowing an attacker to inject an external URL into include function.
One requirement for RFI is that the allow_url_fopen option needs to be on.
The risk of RFI is higher than LFI since RFI vulnerabilities allow an attacker to gain Remote Command Execution (RCE) on the server. Other consequences of a successful RFI attack include:
An external server hosting malicious files must communicate with the application server for a successful RFI attack. The malicious file is injected into the include fn via HTTP requests, and the content of the malicious file executes on the vulnerable application server.
If there is no input validation, then the malicious URL passes into include. Next, the web app server will send a GET request to the malicious server to fetch the file. As a result, the web app includes the remote file into include function to execute the PHP file within the page and send the execution content to the attacker.