i Local File Inclusion Attack – All things in moderation

Local File Inclusion Attack


Local File Inclusion (LFI) is the process of including files, that are already locally present on the server. This vulnerability occurs when a user input contains the path to the file that has to be included. When such an input is not properly sanitized, the attacker may give some default file names and access unauthorized files, or an attacker may also make use of directory traversal characters (such as dot-dot-slash) and retrieve sensitive files available in other directories.

Example Local file inclusion in PHP

  • Consider following url:

  • The value of “page” parameter is taken into the following PHP code, and the file is included:
    $file = $_GET['page'];
  • To successfully test for this flaw, the tester needs to have knowledge of the system being tested and the location of the files being requested. Because There is no point requesting /etc/passwd from an IIS web server, each operating system uses different characters as path separator:

linux :

root directory: “/”

directory separator: “/”

Windows :

root directory: “:\”

directory separator: “\” or “/”

  • Now, an attacker can give malicious input in the “page” parameter which might retrieve unauthorized files present in the same directory, or he may use directory traversal characters like “../” to move to other directories. For example read user credentials in linux system by input “../../../../../../../../../etc/passwd”

  • In some cases, a file extension is a default type added to the user input during file inclusion, the best way to avoid the default extension to be added is by using null byte terminator “%00”.

  • If server enable php://filter wrapper this can help you read php file content.

I have write about php://filter in fllowing article: http://hydrasky.com/2016/10/18/php-local-file-inclusion-using-wrapper-phpfilter/

Example using php://filter for read php file content:

Then I receive content of the file index.php in base64-endcode.


Decode below string i have content of the file index.php

Once you’ve got the source code, you can inspect it for further vulnerabilities!




Leave a Reply