1.Local-file-inclusion-lfi
Key Takeaways: Local File Inclusion (LFI) Attacks
Basic LFI
Exploits a parameter that directly includes a file.
Example:
Allows reading local files by manipulating the parameter.
Path Traversal
Bypasses directory restrictions using relative paths (
../
).Example:
Enables escaping the intended directory to access other files.
Filename Prefix Handling
Some applications prepend a prefix to included filenames.
Example:
Can be bypassed by using
/
to treat the prefix as a directory.
Appended Extensions Bypass
Some implementations append extensions like
.php
.Example:
Common bypasses include null byte injections and PHP wrappers (discussed below).
Second-Order LFI
Occurs when LFI is exploited through indirect user input (e.g., database entries).
Example:
Highlights the importance of sanitizing all user-controlled data.
Platform Agnostic Nature
LFI techniques apply across various backend languages and frameworks.
Additional Considerations
Null Byte Injection (Older PHP)
In older PHP versions, appending a null byte (
%00
) could truncate the filename and bypass appended extensions.Example:
This is less effective in modern PHP versions.
PHP Wrappers and Filters
PHP wrappers like
php://filter
allow encoding/decoding files, enabling attackers to read source code even if it’s executed.Example:
Log File Poisoning
Attackers can inject data into log files and later include those logs using LFI to execute arbitrary code.
Often used for achieving Remote Code Execution (RCE).
Error Handling
Detailed error messages should be disabled in production environments.
Attackers can leverage errors to map the server's file structure.
Input Sanitization
Proper validation and sanitization of user input prevent LFI vulnerabilities.
Whitelisting allowed characters and file paths is a best practice.
Security Headers
While not a direct mitigation, security headers add an additional layer of defense against exploitation.
Last updated