언어별 각 함수의 Read/Execute/Remote URL 작동 여부

langFunctionRead ContentExecuteRemote URL
PHPinclude / include_onceOOO
require / require_onceOOX
file_get_contentsOXO
fopen / fileOXX
NodeJSfs.readFileOXX
fs.sendFileOXX
res.renderOOX
JavaincludeOXX
importOOO
.NET@Html.PartialOXX
@Html.RemotePartialOXO
Response.WriteFileOXX
includeOOO

LFI 필터링 우회 ....//

PHP 취약 코드 예시

$page = str_replace('../', '', $_GET['page']);
  • User Input의 ../를 공백으로 치환하는 코드

우회

?page=....//....//....//....//....//etc/passwd
  • ....//가 필터링되어 ../로 처리됨.
  • 결과적으로, ../../../../etc/passwd로 처리되어 Path Traversal 취약점이 됨

대응 (PHP)

  1. basename()함수를 사용해 유저 Input의 마지막 경로 파일이름만을 인자로 받아 저장
  2. allowlist방식으로 코드 작성
<?php
$allowed_files = ['home.php', 'about.php', 'contact.php'];
$file = basename($_GET['file'] ?? 'home.php');
 
if (in_array($file, $allowed_files, true)) {
    $filepath = '/var/www/html/pages/' . $file;
    if (file_exists($filepath)) {
        include $filepath;
    } else {
        echo "File Not Found";
    }
} else {
    echo "Error";
}