assert()不自动评估代码

问题描述 投票:0回答:1

我的PHP版本是7.2.9-1。在以下练习中,assert上有代码注入:

extract($_POST);
function goAway() {
    error_log("Hacking attempt.");
    header('Location: /error/');
}

if (!isset($pi) || !is_numeric($pi)) {
    goAway();
}

if (!assert("(int)$pi == 3")) {
    echo "This is not pi.";
} else {
    echo "This might be pi.";
}

操作assert()评估PHP代码,它包含用户输入。但是,我使用pi=phpinfo(),服务器不是phpinfo()但只输出This might be pi.。有人可以解释一下吗?

php code-injection assert
1个回答
0
投票

从PHP手册:

断言不应用于输入参数检查等常规运行时操作。根据经验,如果未激活断言检查,则代码应始终能够正常工作。

在PHP配置中可能只是禁用断言。检查你的php.ini文件或assert_options()

此外,根据您提供的代码示例,这不是assert的用途。

© www.soinside.com 2019 - 2024. All rights reserved.