Local File Inclusion
How common?
Description:
Local File Inclusion (also known as LFI) is the process of including files, that are already locally present on the server, through the exploiting of vulnerable inclusion procedures implemented in the application. This vulnerability occurs, for example, when a page receives, as input, the path to the file that has to be included and this input is not properly sanitized, allowing directory traversal characters (such as dot-dot-slash) to be injected. Although most examples point to vulnerable PHP scripts, we should keep in mind that it is also common in other technologies such as JSP, ASP and others.
Implication:
  • Code execution on the web server
  • Code execution on the client-side such as JavaScript which can lead to other attacks such as cross site scripting (XSS)
  • Denial of Service (DoS)
  • Sensitive Information Disclosure
OWASP
Vulnerable Objects:
  • URL forms
  • FTP cli interface
How to find:
Locate phpinfo page?
/script.php?page=index.html
/foo.php?file=image.jpg
/layout.php?addr=
Google dork example:
inurl:index.php?page=
Interesting files to include:
Linux
Windows
/etc/passwd /etc/shadow /etc/issue /etc/group /etc/hostname /etc/ssh/ssh_config /etc/ssh/sshd_config /root/.ssh/id_rsa /root/.ssh/authorized_keys /home/user/.ssh/authorized_keys /home/user/.ssh/id_rsa
– %SYSTEMROOT%\repair\system – %SYSTEMROOT%\repair\SAM – %WINDIR%\win.ini – %SYSTEMDRIVE%\boot.ini – %WINDIR%\Panther\sysprep.inf – %WINDIR%\system32\config\AppEvent.Evt
More LFI paths to test:
GitHub - cyberheartmi9/PayloadsAllTheThings
GitHub
Automating the audit:
GitHub - crunchsec/fimap: LFI/RFI scanner by Iman Karim ([email protected])
GitHub
Filtering bypass:
  • Try / and \ at the start of the folder name to try and reach the root directory.
  • Try %2f and %5c (percent encoded versions of the above).
  • Try using 16-bit Unicode encoding (. = %u002e, / = %u2215, \ = %u2216).
  • Try double URL encoding (. = %252e, / = %252f, \ = %255c).
  • Try overlong UTF-8 Unicode encoding (. can be %c0%2e, %e0%40%ae, %c0ae, / can be %c0%af, %e0%80%af, %c0%2f, etc, \ can be %c0%5c, %c0%80%5c).
An URL-encoded nullbyte %00 can be used on PHP ≤ v.5.3. to cut off a hard-coded file-extension
Practice Labs:
Copy link