EVAl函数是一个非常强大的可以直接执行用户提交的php代码了,同时此函数也给黑客常利用到了,所以很多站长都想去禁止此函数,但小编搜索后发现很多朋友对于PHP禁用EVAL函数有错误的理解了,下面小编为各位纠证一下.
val()针对php安全来说具有很大的杀伤力 一般不用的情况下 为了防止<?php eval($_POST[cmd]);?> 这样的小马砸门 需要禁止掉的
网上好多说使用disable_functions禁止掉eval 是错误的,其实eval() 是无法用php.ini中的disable_functions禁止掉的 because eval() is a language construct and not a function
eval是zend的 不是PHP_FUNCTION 函数,php怎么禁止eval,如果想禁掉eval 可以用 php的扩展 Suhosin,安装Suhosin后在php.ini 中load进来Suhosin.so 加上suhosin.executor.disable_eval = on即可
linux中suhosin安装方法:
-
# cd /usr/local/src
-
# wget http:
-
wget http:
-
# tar zxvf php-5.2.5.tar.gz
-
# gunzip suhosin-patch-5.2.5-0.9.6.2.patch.gz
-
# cd php-5.2.5
-
# patch -p 1 -i ../suhosin-patch-5.2.5-0.9.6.2.patch
-
# ./buildconf --force
-
# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib-dir --with-bz2 --with-tiff-dir --with-libxml-dir=/usr/local/libxml2 --with-gd=/usr/local/gd2 --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-maintainer-zts --enable-memory-limit --enable-zend-multibyte --enable-sockets --enable-soap --enable-suhosin
-
# make
-
# make install
-
重启apachectl,查看phpinfo信息,会出现
-
This server is protected with the Suhosin Patch 0.9.6.2
-
Copyright (c) 2006 Hardened-PHP Project
-
等许多Suhosin信息那么你就成功了。呵呵。
-
在这里也顺便说一下将suhosin安装成为php的动态扩展的方法。
-
wget http:
-
tar zxvfsuhosin-0.9.23.tgz
-
cd suhosin-0.9.23
-
/usr/local/php/bin/phpize
-
./configure --with-php-config=/usr/local/php/bin/php-config
-
make
-
make install
-
会提示编译的模块存在的目录,记住它。
-
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
-
然后在php.ini中增加一行下列语句。
-
extension=suhosin.so
-
suhosin.executor.disable_eval = on
如果对于部分业务需要运行eval咋办?如果是 PHP 5.3+ 且 CGI/FastCGI 方式运行,可以这么改 php.ini,则可以破例使用 eval.
操作方法如下:
-
suhosin.executor.disable_eval = on
-
[PATH=/htdocs/www/ex1/]
-
suhosin.executor.disable_eval = off
最后重启php-fpm 即可.