dtny30176 2016-10-17 04:36
浏览 44

使用php [duplicate]阻止将.sh文件上传到服务器

This question already has an answer here:

Currently in my code the extension of the files is checked before it is uploaded to the server. I need to check the content of the files too before uploading it to server. I have used the following code


    $FileName = $_FILES[$imageInput]['name'];
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mtype = finfo_file($finfo, $FileName);

$mtype is correctly identified for all image type like .png , .jpg but it doesn't recognised .sh files. How can I check this using php? Some one please help.

</div>
  • 写回答

2条回答 默认 最新

  • dqwh2717 2016-10-17 04:47
    关注

    You can block various files to be executed via .htaccess. For example you can place this

    <FilesMatch "\.(sh|cgi.+)$">
        ForceType text/plain
    </FilesMatch>
    

    This will ensure files in the folder will return as text/plain

    If you want you can detect mime type as you detect for images. Mime type for .sh is

    application/x-sh
    application/x-csh
    text/x-shellscript
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题