PHP ‘_gd2GetHeader()’函数整数溢出漏洞

大嘎好,半吊子运维又出现了。

登录阿里云发现一个新的安全警告。

中危 PHP ‘_gd2GetHeader()’函数整数溢出漏洞 存在EXP 拒绝服务

漏洞描述

PHP(PHP:Hypertext Preprocessor,PHP:超文本预处理器)是PHP Group和开放源代码社区共同维护的一种开源的通用计算机脚本语言。 PHP的‘_gd2GetHeader()’函数中存在整数溢出漏洞,攻击者可利用该漏洞造成堆缓冲区溢出。

基本信息

  • CVE编号: CVE-2016-5766
  • 漏洞类型: 拒绝服务,缓冲区溢出
  • 危险等级: 中危
  • 披露时间: 未知

修复建议

目前厂商已经发布了升级补丁以修复此安全问题,补丁获取链接:
https://bugs.php.net/bug.php?id=72339

参考链接

稍微看了一下,登录到服务器,进行更新

#yum update gd
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile

  • base: mirrors.163.com
  • epel: mirror.sjtu.edu.cn
  • extras: mirrors.163.com
  • remi-safe: mirrors.tuna.tsinghua.edu.cn
  • updates: mirrors.aliyun.com
    Resolving Dependencies
    –> Running transaction check
    —> Package gd.x86_64 0:2.0.35-26.el7 will be updated
    —> Package gd.x86_64 0:2.0.35-27.el7_9 will be an update
    –> Finished Dependency Resolution

Dependencies Resolved

================================================================================

Package Arch Version Repository Size

Updating:
gd x86_64 2.0.35-27.el7_9 updates 146 k

Transaction Summary

Upgrade 1 Package

Total download size: 146 k

Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
gd-2.0.35-27.el7_9.x86_64.rpm | 146 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : gd-2.0.35-27.el7_9.x86_64 1/2
Cleanup : gd-2.0.35-26.el7.x86_64 2/2
Verifying : gd-2.0.35-27.el7_9.x86_64 1/2
Verifying : gd-2.0.35-26.el7.x86_64 2/2

Updated:
gd.x86_64 0:2.0.35-27.el7_9

Complete!

保险起见,重启一下,正好现在没有人用

#reboot

然后登录应用系统,貌似一切正常哦。

打完,收工。

升级centos后php中imagick模块错误解决

阿里云上一台跑php应用的服务器,centos 7

收到一个信息说云服务器上说有什么什么漏洞,需要进行升级

当时也没有想太多,老规矩,先做个系统快照。

然后登录系统,把软件和内核一起升级一下

#yum update

一切看起来非常的顺利,搞完之后重启一下。

虽然有点夜深,但是还是要测试一下应用是否正常。

做为一个半吊子运维的基本素养还是要有的

好了,一访问冒出一串问题

A PHP Error was encountered

Severity: Core Warning

Message: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/imagick.so’ – libMagickWand.so.5: cannot open shared object file: No such file or directory

Filename: Unknown

Line Number: 0

Backtrace:

感觉身上有点热,这么冷的天,我仿佛出汗了。

需要回滚快照?

幸好是深夜,白天交代过晚上会更新系统,应该不会有人使用。

那就先看一看有没有办法解决吧

# php –version 同样提示 imagick.so 无法 load

#vi /etc/php.ini

extension=imagick.so 先把这一行给注释了。

发现 imagick.so在 /usr/lib64/php/modules/ imagick.so 目录下,文件明明在的,为什么load不上呢?

那就删了重新装一下,试试。

# pecl uninstall imagick

#pecl install imagick

#vi /etc/php.ini 把 extension=imagick.so 打开

#php –version 正常

再启动一下nginx ,发现一切正常

世界又恢复了美好。

洗洗睡。

继续假装是个运维小哥。

phpstudy中使用composer

Composer是 PHP 世界里用于管理项目依赖的工具。

phpstudy 自带了composer,只需要在环境中点击安装一下就可以。

使用时,将 composer.bat,composer.phar 二个文件从,[phpstudy]/extensions/[composer1.8.5]/ 目录复制到 [phpstudy]/extensions/php/[php目录]/ 即可

设置使用国内镜像,命令行进入到 [phpstudy]/extensions/php/[php目录]/ 输入 composer config -g repo.packagist composer https://packagist.phpcomposer.com

解除镜像 composer config -g --unset repos.packagist

下载文件时safari上中文文件名乱码的处理办法(php代码实现)

php一段代码,处理文件下载时的文件名,后来客户反馈说firefox,safari下的中文文件名不能正常显示。

        $file_info['title'] = rawurlencode($file_info['title']);
        $filename=iconv('utf-8', 'gbk', $file_info['title']);
        header("Content-Disposition:attachment;filename = " . $filename);

修正为以下内容后firefox,safari下正常显示

如果没有兴趣请看简版,一句话解决
if (preg_match("/Safari/", $ua)) { 
header( 'Content-Disposition: attachment; filename*="UTF-8\'\'' .  rawurlencode($file_info['title']) );
}

之前试过和firefox一样处理方法,结果下载的文件名连扩展名都没有了
 header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' .  rawurlencode($file_info['title'])  . '"' ); 

兜兜转转后发现去掉一对双引号就可以,

求此时此刻内心的阴影面积

一堆代码参考一下。


        $file_info['title'] = rawurlencode($file_info['title']);
        $filename=iconv('utf-8', 'gbk', $file_info['title']);
//        header("Content-Disposition:attachment;filename = " . $filename);


        $encoded_filename =  $file_info['title'] 
        $ua = $_SERVER["HTTP_USER_AGENT"];
        //IE
        if(preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)){
            header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
        } else if (preg_match("/Firefox/", $ua)) {
            header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"');
        } else if (preg_match("/Safari/", $ua)) {
            header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . $encoded_filename );
        } else {
            header('Content-Disposition: attachment; filename="' . $filename . '"');
        }

相关原理有请度娘上场

浏览器能正确识别的编码格式,只要按照这样的编码来设置对应的Content-Disposition,那么应该就不会出现中文文件名的乱码问题了。 
首先,Content-Disposition值可以有以下几种编码格式 
1. 直接urlencode: 

    Content-Disposition: attachment; filename=”struts2.0%E4%B8%AD%E6%96%87%E6%95%99%E7%A8%8B.chm” 

2. Base64编码: 

    Content-Disposition: attachment; filename=”=?UTF8?B?c3RydXRzMi4w5Lit5paH5pWZ56iLLmNobQ==?=” 

3. RFC2231规定的标准: 

    Content-Disposition: attachment; filename*=UTF-8”%E5%9B%9E%E6%89%A7.msg 

4. 直接ISO编码的文件名: 

    Content-Disposition: attachment;filename=”测试.txt” 

然后,各浏览器支持的对应编码格式为: 

1.  IE浏览器,采用URLEncoder编码 
2.  Opera浏览器,采用filename*方式 
3.  Safari浏览器,采用ISO编码的中文输出 
4.  Chrome浏览器,采用Base64编码或ISO编码的中文输出 
5.  FireFox浏览器,采用Base64或filename*或ISO编码的中文输出 

new_filename = URLEncoder.encode(filename, “UTF8”);  
// 如果没有UA,则默认使用IE的方式进行编码,因为毕竟IE还是占多数的  
rtn = “filename=\”” + new_filename + “\””;  
if (userAgent != null)  
{  
     userAgent = userAgent.toLowerCase();  
      // IE浏览器,只能采用URLEncoder编码  
     if (userAgent.indexOf(“msie”) != -1)  
    {  
        rtn = “filename=\”” + new_filename + “\””;  
    }  
     // Opera浏览器只能采用filename*  
     else if (userAgent.indexOf(“opera”) != -1)  
     {  
        rtn = “filename*=UTF-8”” + new_filename;  
    }  
    // Safari浏览器,只能采用ISO编码的中文输出  
      else if (userAgent.indexOf(“safari”) != -1 )  
      {  
          rtn = “filename=\”” + new String(filename.getBytes(“UTF-8″),”ISO8859-1”) + “\””;  
      }  
      // Chrome浏览器,只能采用MimeUtility编码或ISO编码的中文输出  
      else if (userAgent.indexOf(“applewebkit”) != -1 )  
       {  
         new_filename = MimeUtility.encodeText(filename, “UTF8”, “B”);  
          rtn = “filename=\”” + new_filename + “\””;  
       }  
      // FireFox浏览器,可以使用MimeUtility或filename*或ISO编码的中文输出  
       else if (userAgent.indexOf(“mozilla”) != -1)  
       {  
          rtn = “filename*=UTF-8”” + new_filename;  
      }  
   }  

ref:

https://my.oschina.net/u/1391970/blog/215361

https://blog.csdn.net/weixin_30701575/article/details/97463481

https://my.oschina.net/junn/blog/97699

https://bbs.csdn.net/topics/390424956 最后解决的来源

header( ‘Content-Disposition: attachment; filename*=UTF-8\’\” . rawurlencode ( $originfile ) );