Risks of using PHP eval [duplicate]

跟風遠走 提交于 2019-12-02 08:00:31
Colin Brock

For the problems, see this link:

http://www.google.com/search?q=php+why+eval+is+bad

But you shouldn't need to use eval. Developers really should act as if eval doesn't exist. Perhaps you could explain your situation more clearly? Questions such as where you are getting the code file, why you can't use include, etc.

As long as you can trust the source of the code you call with eval() you will be safe.

If random users are providing the strings you call eval() on, then you are at risk of someone providing you evil strings like this:

exec("rm -rf /");

Your eval will happily run this string, and depending on permissions it will delete everything on your filesystem.

If you are evaling server-side code that you (or someone you trust) wrote that is not publicly accessible then that is no more dangerous than executing regular PHP code. The problem comes when you depend on user input to do the eval since it can be malicious.

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