Detect if Mod_Security Is Installed With PHP?

Deadly 提交于 2019-12-06 03:34:33

问题


Is there any simple way to detect if mod_security is installed & enabled using just PHP? Ideally without any exec() terminal type commands to be executed.

Some people have recommended using apache_get_modules() but this specific web-host does not allow it to show. This is also mentioned by other users here: http://www.devcomments.com/apache_get_modules-solution-to130703.htm


回答1:


Try the apache_get_modulesfunction to get an array of the loaded modules. If that module is loaded but not listed there, you might want to try phpinfo with phpinfo(INFO_MODULES) instead:

ob_start();
phpinfo(INFO_MODULES);
$contents = ob_get_clean();
$moduleAvailable = strpos($contents, 'mod_security') !== false;



回答2:


You can do just create a test.php file and use..

<?php phpinfo(); ?>

And look at the apache2handler, and look at: Loaded modules.. something like this...

http://gyazo.com/bcba303469f23671f7213e1478788cbd.png

-Mike




回答3:


Grasping at straws here.

Try having your script make a request to itself (via file_get_contents or maybe the cURL extension) that would trip mod_security. If it returns a 403 (or whatever mod_security's default response is), that should be enough information for you to go on...




回答4:


You can search the get_loaded_extensions() function and use array_intersect() which will return matching values in an array else an empty array if it does not find anything matching.

$modSecurity = !empty(array_intersect(array_map('strtolower', get_loaded_extensions()), array('mod_security', 'mod security'))) ? true : false;


来源:https://stackoverflow.com/questions/3182500/detect-if-mod-security-is-installed-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!