search
Homephp教程php手册php正确禁用eval函数与误区介绍

php正确禁用eval函数与误区介绍

Jun 13, 2016 am 09:50 AM
evalphpandintroducefunctionexistusyescorrectDisablesystemcomponentsMisunderstanding

eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。

eval()针对php安全来说具有很大的杀伤力 一般不用的情况下 为了防止

 代码如下 复制代码

使用范例

 代码如下 复制代码


$string = '杯子';
$name = '咖啡';
$str = '这个 $string 中装有 $name.
';
echo $str;
eval( "$str = "$str";" );
echo $str;
?>


本例的传回值为
这个 $string 中装有 $name.
这个 杯子 中装有 咖啡.


或更高级点的是

 代码如下 复制代码
$str="hello world"; //比如这个是元算结果
$code= "print('n$strn');";//这个是保存在数据库内的php代码
echo($code);//打印组合后的命令,str字符串被替代了,形成一个完整的php命令,但并是不会执行
eval($code);//执行了这条命令
?>;

 你上面的咖啡的例子了,在eval里面,首先字符串被替换了,其次替换完后形成一个完整的赋值命令被执行了.

 

这样的小马砸门 需要禁止掉的

网上好多说使用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即可

总结,php eval函数在php中是无法禁用的我们也只有使用插件了

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.