Giter Site home page Giter Site logo

lfi-and-typical-causes's Introduction

LFI-And-Typical-Causes

Lỗi Local File Inclusion (LFI) xảy ra khi một ứng dụng web cho phép người dùng truy nhập các file hệ thống hoặc tệp tin nhạy cảm khác trên server, thông qua việc không chặn đúng cách nhập liệu từ người dùng. Đây là một số ví dụ dạng dòng code hoặc mô hình phát triển có thể gây ra lỗi LFI:

  1. Dùng luôn input đầu vào và không kiểm soát để đọc file
<?php 
  $file =  $_GET['file];
  include($file)
?>

Trong đoạn PHP trên , biến $_GET['file];lấy giá trị từ tham số file trong URL và trực tiếp dùng luôn cho include() mà không filter hay kiểm duyệt gì cả

Khi URL http://example/com/script.php?file=content.php thì $_GET['file]; sẽ nhận giá trị là content.php -> sau đó biến $file được gán giá trị là content.php lệnh include($file) sẽ tìm file có tên content.php và output ra nội dung file đó -> rủi ro về việc user có thể trỏ đến bất kì file nào mà họ muốn

  1. Linked File Path
<?php
  $filepath = 'includes/' . $_GET['page'];  
  include($filepath);
?>

này là tượng đài của url lfi với các ví dụ

http://example/com/script.php?file=content.php

Nối chuỗi input của người dùng vào chạy luôn

  1. Ghi đè biến
<?php
  $template = 'default.php';
  if(isset($_GET['template'])){
    $template = $_GET['template'];
  }
  include('/templates/' . $template);
?>

Có nỗ lực đặt file mặc định nhưng không đáng kể :)) . Biến $template sẽ bị ghi đè bởi tham số template từ URL 4. Không sử dụng Whitelisting với các file có thể include()

<?php
  if(file_exist('includes/' . ``` $_GET['file]; ``` . '.php')){
    include('includes/' . ``` $_GET['file]; ``` . '.php');
  }
?>

Trường hợp này là có check nhưng không đáng kể. Có biết check xem file có tồn tại trước khi include thay vì cứ đẩy input vô tùm lum . Nhưng mà không có whitelist về các file có thể truy cập tùy theo ủy quyền .

  1. Sử dụng đầu vào người dùng trong các hàm đọc file
<?php
  $content = file_get_contents('content/' . $_GET['filename']);
  echo $content;
?>

Hàm file_get_contents sẽ bị khai thác nếu như không filter đúng cách

lfi-and-typical-causes's People

Contributors

lilly-dox avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.