douyanyan1123 2011-05-23 19:10
浏览 119

PHP图片上传。 如何保护包含代码的图像?

From what I understand, - images (jpeg, gif etc.) might contain valid php/python/perl etc. code. So - anyone can create file that will be valid jpeg at the same time can be executed by PHP interpreter. (here is description: link)

So - I was wondering - is there a way to strip malicious code from images? would recoding images with GD or imagemagic work?

Thanks!

  • 写回答

2条回答 默认 最新

  • du16178 2011-05-23 19:14
    关注

    Actual images will not contain code. But there's nothing stopping someone from trying to get an "image" file uploaded, and then try and get it to execute.

    Your interpreters (Perl, PHP, whatever) should be set up so that they only execute certain file types (i.e. .php or .php5). There's no reason Perl or PHP should be parsing image files.

    Just use the following common sense to protect yourself:

    1) Verify the mime type of the document
    2) Enforce policies that only allow uploading files of a certain extension
    3) Don't accept filenames at face value. Generate your own internal file name and use a database table to keep the mapping.
    4) If you're truly paranoid, find some code to check that the byte signatures are valid for the given file type upload.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法