Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
Local File Inclusion (LFI)
Next article icon

Local File Inclusion (LFI)

Last Updated : 30 Sep, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report
A File Inclusion Vulnerability is a type of Vulnerability commonly found in PHP based websites and it is used to affect the web applications. This issue generally occurs when an application is trying to get some information from a particular server where the inputs for getting a particular file location are not treated as a trusted source. It generally refers to an inclusion attack where an attacker can supply a valid input to get a response from a web server. In response, an attacker will be able to judge whether the input which he supplied is valid or not. If it is valid, then whatever/whichever file an attacker wants to see they can easily access it. Below example illustrates the working procedure of an LFI vulnerability: php
<?php  // The Page we wish to display $file = $_GET['page'];  ?> 
Local File Inclusion Work: Let us understand the working of Local File Inclusion via the following example: In the above example "$file = $_GET['page'];" $file is just a file/code for indicating that the PHP code is going to return a 'file' in response. The $_GET is one of the sets of instruction which will get a particular file or webpage from a web server i.e. it will request for a file. The ['page'] is an argument that will define what type of pages will be displayed in response. Where Local LFI found ? Basically this the location
http://vulnerable_host/preview.php?file=abc.html
This is the place where an attacker can perform the LFI attack on web applications. The script can be included here in the URL that is containing various parameters upon which the attack will be performed. It is possible to include arbitrary files on the server. The affected URL by the attacker would be something like this:
http://vulnerable_host/preview.php?document=../../../../etc/passwd
Identifying Vulnerabilities within Web Application: Identifying LFI Vulnerability within the web application is easy as it is going to include a file from a web server and return it to the attacker. For example "/fi/?page=include.php" LFI would be possible in such an application if the above example or something related to such example is existing in the web application. A Pentester would attempt to get benefit from this sort of misconfiguration i.e. he can exploit this vulnerability by manipulating the parameters. For Example "/fi/?page=include.php" this will execute successfully only if the index.php" file exists in the same directory. If not, we have to add "../" ahead of "index.php" . Imagine this "index.php" is located in the "/var/www/html" folder and "include.php" is located in "/var/www/dvwa/vulnerabilities/lfi/" folder and you can see the responses of files from this folder location only. Now to execute a file located in another directory, we have to change our directory in URL. For example "/fi/?page=../../../index.php". There are three kinds of scenarios possible in LFI attack:
  • Including Files to be Parsed by the Language's Interpreter
  • Including Files that are Printed to a Page
  • Including Files that are Served as Downloads
Impacts of an Local File Inclusion Vulnerability: An attacker would be able to get access to the following by exploiting LFI Vulnerability:
  • Information Disclosure of files stored in Web Server
  • Passwords/Database Access
  • Log Files
  • Complete System Compromise
Remediation File Inclusion(LFI) Vulnerability:
  • One should not allow the file path that could be modified directly either it should be hardcoded or to be selected via hardcoded path list.
  • One must make sure that the required should have dynamic path concatenation i.e must contain (a-z) (0-9) instead of (/, /% etc)
  • There should be specific limit the API so that only inclusion from directories under it work so that Directory Traversal attack could not take place in this situation

Next Article
Local File Inclusion (LFI)

D

deepamanknp
Improve
Article Tags :
  • PHP

Similar Reads

    PHP | SplDoublyLinkedList valid() Function
    The SplDoublyLinkedList::valid() function is an inbuilt function in PHP which is used to check whether the doubly linked list contains more nodes or not. Syntax: bool SplDoublyLinkedList::valid( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRUE
    1 min read
    PHP | include_once() and require_once()
    We already have learnt about file inclusion in PHP in the article PHP | (Include and Require). We have discussed about include() and require() functions for file inclusion in our previous article. In this article we will discuss about two more yet useful functions in PHP for file inclusion: include_
    3 min read
    Difference between RFI and LFI
    Remote File Inclusion (RFI) is a type of vulnerability most often found on the suited PHP running web portals be on the web and the Local File Inclusion (LFI) is similar to RFI, the only difference is that in LFI, the attacker has been uploading the malicious scripts types. Remote File Inclusion (RF
    6 min read
    LOB Locator and LOB Value
    There are two methods that could be used to access and modify LOB values: Using the Data Interface for LOBs Using the LOB Locator to Access/Modify LOB Values Using the Data Interface for LOBs You can perform bind and define operations on BLOB and CLOB columns in C applications using the data interfa
    3 min read
    COBOL - Include Statement
    The INCLUDE statement refers to the file or the directory mentioned after it and inserts the command present inside that member in the pre-compilation state. Basically, it is used to insert a code block onto a source program. Syntax: INCLUDE member-name Where, The member-name refers to the name of t
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences