githubEdit

LFI

Local File Inclusions (LFI)

chevron-rightWhat is LFI ?hashtag

An attacker can use Local File Inclusion (LFI) to trick the web application into exposing or running files on the web server. An LFI attack may lead to information disclosure, remote code execution, or even XSS.

Typically, LFI occurs when an application uses the path to a file as input. If the application treats this input as trusted, a local file may be used in the include statement.

Check for LFI

The following is an example of PHP code that is vulnerable to LFI.

/**
* Get the filename from a GET input
* Example - http://example.com/?file=filename.php
*/
$file = $_GET['file'];

/**
* Unsafely include the file
* Example - filename.php
*/
include('directory/' . $file);
  • GET parameter in url

Tool to check LFI

Payloads

FUZZ LFI ENDPOINTS

PHP Wrapper

  • Used to read .PHP files. It is not possible to read a PHP file's content via LFI because PHP files get executed and never show the existing code. We can use the PHP filter to display the content of PHP files in other encoding formats such as base64 or ROT13.

Commands

LFI 2 RCE

/proc/self/environ

Like a log file :

Via Apache Log Files

via SSH

via MAIL

First send an email using the open SMTP then include the log file located at http://example.com/index.php?page=/var/log/mail.

In some cases you can also send the email with the mail command line.

Via DNS

Check for :

Change the DNS record via nsupdate

Last updated