Activity 2.2 - File Inclusion Vulnerabilities

circle-exclamation

Local File Inclusion (LFI) Setup

Make a directory called file-inclusion

Paste the following into a index.php file

Make three files that each include a simple html page. Below you will see page1.html,page2.html,page3.html

Start a php server in your terminal using php -S 127.0.0.7:9000

The go to a web browser and type http://127.0.0.1:9000 and you will see the php and html pages that you made! Your php server will also display messages saying that you successfully executed a GET http request.

Interact with the buttons on the page

Deliverable 1: See if you can display kali's etc/passwd.

If we look at our URL after we click on the button we can see the format of the request that is being submitted to the web server for a page.

We have to tell the web server in the same format that we want to change the page. so instead of looking for page2.html we can tell the server we want the /etc/passwd page instead/

Deliverable 2: Figure out how to display the file that shows the current version of Linux

Challenge: dispaly my partners /etc/passwd file using their IP address

Deliverable 3: include the rfi.html file using 2 web servers.

RFI

circle-info

Helpful hint! If you want to easily go back to a directory instead of having to remember the path you can use pushd and popd. Say you are in the directory ~/sec480/week2/file-inclusion and you need to go to another directory but will be coming back to the orginal one. Within your directory you can do pushd . to define to the system that that is the directory you want to go back to. For an example I decide to go to the /etc/php directory. From that directory I can then type popd and it will take me back to my original directory!

  • Create a file called rfi.html in your file-inclusion directory

  • Make a copy of php.ini and put it in your file-inclusion directory

    • cp etc/php/8.4/cli/php.ini

    • You should check your php version within etc/php when running this command (it may not be 8.4 anymore).

  • Modify the new php.ini file so that allow_url_include is turned on

In a new tab run the following python command:

In your original tab restart the local php server with:

In the following screenshot we are using one web server to get content from another web server. The second web server that we ran with the python command could have malware or a malicious file that we wanted to inject in the first server (but right now the files are not harmful).

Deliverable 4: Figure out how to include a rfi.php that executes a single command of your choice.

circle-exclamation

make a file in your file-inclusion directory rfi.php

Put your rfi.php file in your url and you should see the output of your command!

Last updated