top of page

What is File Inclusion vulnerability and its types?

File inclusion is a type of vulnerability that can exist in web applications. It occurs when a web application allows a user to include a file, typically using a parameter or variable, without properly validating or sanitizing the user input. This can allow an attacker to include a file from a remote server or from the local file system of the server hosting the application, which can lead to various security issues.


For example, imagine a web application that allows users to view their profile information by visiting a URL like example.com/profile.php?username=john. The username parameter is used by the application to include the profile information for the user specified in the parameter. However, if the application doesn't properly validate the input for the username parameter, an attacker could manipulate the parameter value to include a malicious file instead of a legitimate user profile. This could allow the attacker to execute arbitrary code, steal sensitive data, or perform other malicious actions on the server.


Types of File Inclusion -

  1. Local File Inclusion - 

This type of vulnerability occurs when a web application allows a user to include a local file, typically using a parameter or variable. The attacker can manipulate the parameter value to include a file from the local file system of the server hosting the application. This can allow the attacker to access sensitive files, such as configuration files or log files, and execute arbitrary code on the server.


Let's say there is a web application with a page that allows users to view their profile information by entering their username in a search box. The application fetches the user's profile data from a local file using a URL like this: http://example.com/profile.php?username=<username>. The <username> parameter is replaced with the user's input from the search box.


Now, let's say an attacker notices that the <username> parameter is not properly validated and can be manipulated by the user. The attacker could enter a malicious URL like this: http://example.com/profile.php?username=../../../../etc/passwd. If the web application includes the user's profile data using the user-controlled parameter without proper validation, the attacker's code would be executed on the server and could potentially read sensitive files or compromise the entire system.


  1. Remote File Inclusion - 

This type of vulnerability occurs when a web application allows a user to include a file from a remote server, typically using a parameter or variable. The attacker can manipulate the parameter value to include a malicious file hosted on a remote server controlled by the attacker. This can allow the attacker to execute arbitrary code on the server or steal sensitive data from the server or its users.


Let's say there is a web application with a page that displays the weather forecast for a specified location. The application allows users to select the location by entering a city name in a search box. The application fetches the weather data from a third-party API and displays it on the page.


The web application includes the weather data by making a request to the API using a URL like this: http://api.example.com/weather.php?location=<city>. The <city> parameter is replaced with the user's input from the search box.


Now, let's say an attacker notices that the <city> parameter is not properly validated and can be manipulated by the user. The attacker could enter a malicious URL like this: http://attacker.com/malicious.php. If the web application includes the weather data using the user-controlled parameter without proper validation, the attacker's code would be executed on the server and could potentially steal sensitive data or compromise the entire system.


Helpful Resources:

6 views

Recent Posts

See All
bottom of page