gpt4 book ai didi

php - 这个脚本容易受到 LFI(本地文件注入(inject))的攻击吗?

转载 作者:可可西里 更新时间:2023-11-01 00:36:39 25 4
gpt4 key购买 nike

我想知道这个小片段是否受到本地文件注入(inject)漏洞的影响。

<?php
$lang = $_GET['lang'];
include '/some/dir/prefix_'.$lang.'whatever';

我知道可以通过在请求中放入“%00”(空字节)来忽略任何内容。但是如果/some/dir/目录下没有以'prefix_'开头的子目录,是否可以利用呢?怎么办?

在此先感谢您的回答。

最佳答案

你的意思是这样的吗?

$lang .= 'en/../../../../../etc/passwd' . 0x00;

你可以通过以下方式避免这种情况

$path = '/some/dir/prefix_'.$_GET['path'].'whatever';
$path = realpath($path);
if (($path !== false) && (strncmp('/dir/some/prefix_', $path, 17) === 0)) {
// $path is fine
}

这个测试,如果路径存在,如果它真的在目录树下,你允许它存在。应该足够了。

关于php - 这个脚本容易受到 LFI(本地文件注入(inject))的攻击吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6042108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com