加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – move_uploaded_file – 为什么重要?

发布时间:2020-12-13 22:48:26 所属栏目:PHP教程 来源:网络整理
导读:我无法想象为什么我应该使用这个函数而不是简单的重命名. 手册写道: move_uploaded_file This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP‘s HTTP POST upload mechan
我无法想象为什么我应该使用这个函数而不是简单的重命名.

手册写道:

move_uploaded_file

This function checks to ensure that the file designated by filename
is a valid upload file (meaning that it was uploaded via PHP‘s HTTP
POST upload mechanism). If the file is valid,it will be moved to the
filename given by destination.

This sort of check is especially important if there is any chance that
anything done with uploaded files could reveal their contents to the
user,or even to other users on the same system.

你能写一个例子,为什么这么重要?

解决方法

因为为此目的使用常规文件系统功能可能会产生安全漏洞.如果你在你的程序中这样做:

rename($source,$destination);

并且攻击者能够控制$source的值,他们已经获得了重命名(或移动! – 重命名也可以跨文件移动文件)PHP进程可以访问的任何文件的功能.

如果它们也可以影响$destination,或者如果有一些方法可以在文件移动后获得对文件内容的访问权限,则可以使用此漏洞至少获得对源代码的访问权限,这通常会显示身份验证凭据.并且不难想象会发生这种情况:如果您接受用户上传并通过URL访问它们,则此功能已经内置到您的应用程序中.

一般来说,这是一个你必须考虑的安全问题; _uploaded_file函数可以帮助你登陆pit of success.

更新(从评论中提取材料):

文件上传的现代处理(通过$_FILES)在很大程度上使得move_uploaded_file在技术上不必要.但不要忘记:

>技术上不必要可能仍然是一个好主意:我们正在谈论安全性,为什么不安全?> move_uploaded_files是在$_FILES甚至不存在的时候引入的,register_globals的广泛使用是现实而不是儿童恐怖故事.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读