是否有任何简单的方法来检测是否仅使用 PHP 安装和启用了 mod_security?理想情况下,无需执行任何 exec() 终端类型命令。
有些人建议使用 apache_get_modules() 但这个特定的网络主机不允许它显示。其他用户在这里也提到了这一点:http: //www.devcomments.com/apache_get_modules-solution-to130703.htm
是否有任何简单的方法来检测是否仅使用 PHP 安装和启用了 mod_security?理想情况下,无需执行任何 exec() 终端类型命令。
有些人建议使用 apache_get_modules() 但这个特定的网络主机不允许它显示。其他用户在这里也提到了这一点:http: //www.devcomments.com/apache_get_modules-solution-to130703.htm
尝试该apache_get_modules
函数以获取已加载模块的数组。如果该模块已加载但未在此处列出,您可能想尝试phpinfo
使用phpinfo(INFO_MODULES)
:
ob_start();
phpinfo(INFO_MODULES);
$contents = ob_get_clean();
$moduleAvailable = strpos($contents, 'mod_security') !== false;
您可以只创建一个 test.php 文件并使用..
<?php phpinfo(); ?>
看看apache2handler,看看:加载的模块..像这样的东西......
http://gyazo.com/bcba303469f23671f7213e1478788cbd.png
-麦克风
在这里抓住稻草。
尝试让您的脚本向自身发出请求(通过file_get_contents
或者可能是 cURL 扩展),这会触发 mod_security。如果它返回 403(或任何 mod_security 的默认响应),那应该是足够的信息让您继续...
您可以搜索 get_loaded_extensions() 函数并使用 array_intersect() 如果找不到任何匹配项,它将返回数组中的匹配值,否则返回一个空数组。
$modSecurity = !empty(array_intersect(array_map('strtolower', get_loaded_extensions()), array('mod_security', 'mod security'))) ? true : false;