Hello dear TurkHackTeam members, in this post I will talk about the Local File Inclusion vulnerability and try to explain what kind of data you can access by using this vulnerability.
LFI, or Local File Inclusion , is a web security vulnerability . Thanks to this vulnerability , we can read, change or run any file on the server. The main reason for this vulnerability is that the data is not properly filtered and verified by the site administration or administrator and any file is directly imported ( with functions such as include, require
). We can explain an example LFI situation as follows;
PHP:
<?php$page=$_GET['page'];include($page.'.php');?>
If the page structure is like this, it can access the page it wants by manipulating the URL structure. When we want to go to the contact page, the URL will be like this;
Code:
http://denemesite.com/index.php?page=iletisim
How to Prevent LFI Vulnerability? 1. Validation of User Input File names entered by the user must be filtered. Only allowed file names should be accessible. To achieve this, a code like this can be written;
PHP:
$allowed_pages=['anasayfa','hakkimizda','iletisim'];if(in_array($_GET['page'],$allowed_pages)){include($_GET['page'].'.php');}else{echo"Bu sayfayı görmek için yetkiniz yok!";}
2. URL Sanitization We can prevent characters like../or.. in the entered file names . 3. Real File Paths Instead of dynamically adding files, we can fix the file paths and ensure that only certain files are used. 4. Server Configuration We can control the access permissions to important files by limiting the access to the local file system on our server.We can limit the file inclusion functionsinPHPopen_basediranddisable_functions
So let's get to the main topic, how can we evaluate the LFI vulnerability? First of all, we do a small dork search on Google , I searched for index.php?page= to make it very simple . I went to the first page that came up and started trying them in order. 1. /etc/passwd With this directory, I can see the user information and perform a Bruteforce attack with this information. URL: Output :
2. /etc/shadow With this directory, I can see the hash of users' passwords and enter the system after cracking them with the help of password crackers. URL: Output :https://www.ravagedband.com/index.php?page=/etc/shadow
3. /etc/hosts DNS through this directory, whichIPwhichDNSa DNS Poisoningattackby manipulating this file . URL: Output : https://www.ravagedband.com/index.php?page=/etc/hosts
We can only access this data on the site we tried.
Apart from these, you can see network configuration settings with /etc/network/interfaces , SSH configuration with /etc/ssh/sshd_config, disk structure in the system with / etc/fstab, scheduled tasks with /etc/crontab, which software the package manager uses with /etc/apt/sources.list, and which users can use the sudo command with /etc/sudoers .