test: 增加 PHP2Shell(CVE-2026-109618/109619) 安全基线与 php.ini 防护测试用例
这个提交包含在:
67
tests/SecurityPhpIniTest.php
普通文件
67
tests/SecurityPhpIniTest.php
普通文件
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* FastAdmin / PHP2Shell 安全配置验证测试 (严格遵循 TDD 模式)
|
||||
* 对应社区安全提醒:https://ask.fastadmin.net/question/51687.html
|
||||
* 漏洞防护目标:CVE-2026-109618 / CVE-2026-109619
|
||||
*/
|
||||
|
||||
define('ROOT_PATH', __DIR__ . '/../');
|
||||
define('APP_PATH', ROOT_PATH . 'application/');
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
|
||||
echo "====================================================\n";
|
||||
echo "【安全配置测试】PHP2Shell 安全基线验证 (TDD 模式)\n";
|
||||
echo "====================================================\n";
|
||||
|
||||
$failedCount = 0;
|
||||
|
||||
// 测试 1:session.upload_progress.enabled 必须被完全禁用 (Off / 0)
|
||||
$uploadProgress = ini_get('session.upload_progress.enabled');
|
||||
if ($uploadProgress === '1' || $uploadProgress === 1 || strtolower($uploadProgress) === 'on') {
|
||||
echo "[FAIL] 测试 1 未通过: session.upload_progress.enabled 当前为 1 (On),存在 PHP2Shell 远程代码执行风险,必须设置为 Off!\n";
|
||||
$failedCount++;
|
||||
} else {
|
||||
echo "[PASS] 测试 1 通过: session.upload_progress.enabled 已正确关闭 (Off / 0)\n";
|
||||
}
|
||||
|
||||
// 测试 2:session.use_strict_mode 必须被启用 (1 / On)
|
||||
$strictMode = ini_get('session.use_strict_mode');
|
||||
if ($strictMode !== '1' && $strictMode !== 1 && strtolower($strictMode) !== 'on') {
|
||||
echo "[FAIL] 测试 2 未通过: session.use_strict_mode 当前为 0 (Off),未开启严格模式,必须设置为 1!\n";
|
||||
$failedCount++;
|
||||
} else {
|
||||
echo "[PASS] 测试 2 通过: session.use_strict_mode 已正确开启严格模式 (1)\n";
|
||||
}
|
||||
|
||||
// 测试 3:检查 php.ini 配置文件内容中的明确配置声明
|
||||
$iniPath = php_ini_loaded_file();
|
||||
echo "当前加载的 php.ini 路径: " . ($iniPath ?: "未检测到 loaded php.ini") . "\n";
|
||||
|
||||
if ($iniPath && file_exists($iniPath)) {
|
||||
$iniContent = file_get_contents($iniPath);
|
||||
|
||||
// 匹配有效(非注释)的 session.upload_progress.enabled = Off 或 0
|
||||
if (!preg_match('/^\s*session\.upload_progress\.enabled\s*=\s*(Off|0)\s*(;.*)?$/mi', $iniContent)) {
|
||||
echo "[FAIL] 测试 3.1 未通过: {$iniPath} 中未显式配置有效未注释的 `session.upload_progress.enabled = Off`\n";
|
||||
$failedCount++;
|
||||
} else {
|
||||
echo "[PASS] 测试 3.1 通过: {$iniPath} 显式配置了 `session.upload_progress.enabled = Off`\n";
|
||||
}
|
||||
|
||||
// 匹配有效(非注释)的 session.use_strict_mode = 1 或 On
|
||||
if (!preg_match('/^\s*session\.use_strict_mode\s*=\s*(1|On)\s*(;.*)?$/mi', $iniContent)) {
|
||||
echo "[FAIL] 测试 3.2 未通过: {$iniPath} 中未显式配置有效未注释的 `session.use_strict_mode = 1`\n";
|
||||
$failedCount++;
|
||||
} else {
|
||||
echo "[PASS] 测试 3.2 通过: {$iniPath} 显式配置了 `session.use_strict_mode = 1`\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "====================================================\n";
|
||||
if ($failedCount > 0) {
|
||||
echo "【测试结论】共 {$failedCount} 项安全指标不符合要求,存在安全隐患!\n";
|
||||
exit(1);
|
||||
} else {
|
||||
echo "【测试结论】所有安全防护指标均已满足,安全基线通过!\n";
|
||||
exit(0);
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户