disable_functions
禁止掉eval函数的方法是错误的,并不能真正禁止!
php5版本安装Suhosin防护PHP一句话木马eval!下载扩展源码:https://www.suhosin.org/stories/download.html
wget http://download.suhosin.org/suhosin-0.9.38.tar.gz #获取扩展包
tar -zxvf suhosin-0.9.38.tar.gz#解压
/www/server/php/56/bin/phpize #当前php的phpize的路径
./configure --with-php-config=/www/server/php/56/bin/php-config
make && make install
make test
cd /www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/ #查看
cd /www/server/php/56/etc/
echo "extension = oauth.so" >> /www/server/php/56/etc/php.ini #写配置
/www/server/php/56/bin/php -m #查看安装扩展列表
(重载php后phpinfo()查看扩展是否安装成功)
在extension=suhosin.so
后面加一行代码 suhosin.executor.disable_eval = on
来禁止eval
函数。
php7.4版本:
git clone https://github.com/sektioneins/suhosin7.git
,发现suhosin7不支持。
make && make install
时候报错,Suhosin7 works with PHP 7.0 and 7.1 only!
[root@xxx suhosin7]# make && make install
/bin/sh /root/suhosin7/libtool --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/root/suhosin7 -DPHP_ATOM_INC -I/root/suhosin7/include -I/root/suhosin7/main -I/root/suhosin7 -I/www/server/php/74/include/php -I/www/server/php/74/include/php/main -I/www/server/php/74/include/php/TSRM -I/www/server/php/74/include/php/Zend -I/www/server/php/74/include/php/ext -I/www/server/php/74/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -std=c11 -c /root/suhosin7/suhosin7.c -o suhosin7.lo
mkdir .libs
cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/root/suhosin7 -DPHP_ATOM_INC -I/root/suhosin7/include -I/root/suhosin7/main -I/root/suhosin7 -I/www/server/php/74/include/php -I/www/server/php/74/include/php/main -I/www/server/php/74/include/php/TSRM -I/www/server/php/74/include/php/Zend -I/www/server/php/74/include/php/ext -I/www/server/php/74/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -std=c11 -c /root/suhosin7/suhosin7.c -fPIC -DPIC -o .libs/suhosin7.o
In file included from /root/suhosin7/suhosin7.c:31:0:
/root/suhosin7/php_suhosin7.h:27:2: error: #error Suhosin7 works with PHP 7.0 and 7.1 only! Looking for Suhosin for PHP 5.x? Take a look at https:
#error Suhosin7 works with PHP 7.0 and 7.1 only! Looking for Suhosin for PHP 5.x? Take a look at https://www.suhosin.org/
^
make: *** [suhosin7.lo] Error 1
[root@xxx suhosin7]#
diseval方式:
https://github.com/mk-j/PHP_diseval_extension
;
extension=/www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/diseval.so
添加到php.ini
重载php配置之后,刷新eval已经获取不到服务器打印的信息了。访问php方法中的eval("phpinfo();");
已经提示:DISEVAL - Use of eval is forbidden
,如果eval是由变量替换而成,形如:$bb="eval"; $aa="bb"; $$aa($_POST['a']);
则页面显示空白。
cd source/ #切换到解压的source目录
1103 /www/server/php/74/bin/phpize #注意自己php版本和路径
1104 ./configure --with-php-config=/www/server/php/74/bin/php-config
1105 make && make install
1106 make test
1108 cd modules/ #diseval.so
1114 ls /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/ #diseval.so
如果未禁用eval则可以打印服务器信息,禁用无法打印
https://m.xxx.com/test.php?s=phpinfo();
https://m.xxx.com/test.php?s=print_R($_SERVER);
test.php
内容
#代表允许任意域的跨站资源共享请求
header("Access-Control-Allow-Origin:*");
@eval($_GET['s']);
//一句话木马变形
//https://blog.csdn.net/bylfsj/article/details/101227210?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
/*
$bb="eval";
$aa="bb";
$$aa($_POST['a']);
#base64_decode函数
$a=base64_decode("ZXZhbA==")
$a($_POST['a']);
*/
网友评论