언어별 각 함수의 Read/Execute/Remote URL 작동 여부
| lang | Function | Read Content | Execute | Remote URL |
|---|
| PHP | include / include_once | O | O | O |
| require / require_once | O | O | X |
| file_get_contents | O | X | O |
| fopen / file | O | X | X |
| NodeJS | fs.readFile | O | X | X |
| fs.sendFile | O | X | X |
| res.render | O | O | X |
| Java | include | O | X | X |
| import | O | O | O |
| .NET | @Html.Partial | O | X | X |
| @Html.RemotePartial | O | X | O |
| Response.WriteFile | O | X | X |
| include | O | O | O |
LFI 필터링 우회 ....//
PHP 취약 코드 예시
$page = str_replace('../', '', $_GET['page']);
- User Input의
../를 공백으로 치환하는 코드
우회
?page=....//....//....//....//....//etc/passwd
....//가 필터링되어 ../로 처리됨.
- 결과적으로,
../../../../etc/passwd로 처리되어 Path Traversal 취약점이 됨
대응 (PHP)
basename()함수를 사용해 유저 Input의 마지막 경로 파일이름만을 인자로 받아 저장
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";
}