EasySwoole

CVE-2026-109618

此次漏洞非常严重,废话不多说。本文章目的主要在告知如何解决问题,特别是为无法打上补丁的老版本提供决绝方案

攻击原理

制造悬空的 PS(id)

大概构造如下:

POST /index.php HTTP/1.1
Content-Type: multipart/form-data; boundary=SSSSSSSSSSSSSSSSS
Content-Length: ...

--SSSSSSSSSSSSSSSSS
Content-Disposition: form-data; name="f0000"

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
# 合计约 1001 个普通字段,使 PHP 触发 max_input_vars
...
--SSSSSSSSSSSSSSSSS
Content-Disposition: form-data; name="PHPSESSID"

<NUL 字节>
--SSSSSSSSSSSSSSSSS
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"

ppp
--SSSSSSSSSSSSSSSSS
Content-Disposition: form-data; name="f"; filename="a.txt"
Content-Type: application/octet-stream

AAAAAAAA...
--SSSSSSSSSSSSSSSSS
Content-Disposition: form-data; name="big"

<约 24 MiB 数据>
--SSSSSSSSSSSSSSSSS--

作用如下:

  • 约 1001 个表单变量触发 max_input_vars 警告。
  • 表单里的 PHPSESSID 是单个 NUL 字节。
  • PHP_SESSION_UPLOAD_PROGRESS 加文件字段,触发 PHP 在 RINIT 之前初始化上传进度 Session。
  • 最后的超大字段触发 memory_limit OOM。
  • 请求异常中止后,PS(id) 指向的 request heap 已被释放,但指针仍保留

从 Set-Cookie 泄露地址

构建请求大概如下:

Content-Type: multipart/form-data; boundary=BBBBBBBBBB

--BBBBBBBBBB
Content-Disposition: form-data; name="PHPSESSID"

leaksessionid01
--BBBBBBBBBB
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"

pwn
--BBBBBBBBBB
Content-Disposition: form-data; name="a0000[0]"

x
--BBBBBBBBBB
Content-Disposition: form-data; name="a0001[0]"

x

大量 aNNNN[index] 字段促使 PHP 分配 zend_array,其中一个数组覆盖之前释放的 PS(id) 附近内存。随后 PHP 把这片内存误认为字符串,并 URL 编码进响应:

Set-Cookie: PHPSESSID=<约 512 字节 URL 编码的内存>

泄露内容包含 libphp 函数指针和 Zend heap 指针

制造悬空引用

PHPSESSID
PHP_SESSION_UPLOAD_PROGRESS
约 107 个用于堆布局的短字段
一个文件 part
约 24 MiB 的普通字段

OOM 发生在 rfc1867_post_handler 中,使 PS(http_session_vars) 留下一个跨请求的悬空 zend_reference

伪造 PHP 内部对象

最后一个请求包含:

  • PHPSESSID
  • PHP_SESSION_UPLOAD_PROGRESS
  • 大量 31 字节字段,用于占用释放后的 zend_reference
  • 一个约 167 字节字段,内容被构造成伪造 HashTable
  • 泄露阶段计算出的地址
  • 伪造的 pDestructor 指向 zif_system

清理session的时候就变为:

zend_reference_destroy
  → zend_array_destroy
    → zend_hash_destroy
      → attacker-controlled pDestructor
        → zif_system

解决策略

不依赖session的应用

session.upload_progress.enabled = 0

禁用session,注意重启服务

OpenResty 代理阻断

Openresty可以用lua脚本对请求头做提前过滤,大致脚本如下:

location ~ \.php$ {
    # 根据业务实际需要设置;越小越安全。
    client_max_body_size 8m;
    client_body_buffer_size 128k;

    access_by_lua_block {
        local ct = ngx.var.http_content_type or ""
        local ctl = string.lower(ct)

        -- PHP 接受分号、逗号和空白作为 multipart 参数分隔符。
        local multipart =
            ngx.re.find(
                ctl,
                [[^\s*multipart/form-data(?:[;,\s]|$)]],
                "jo"
            )

        if not multipart then
            return
        end

        -- 非标准但会被 PHP 接受的 Content-Type。
        -- 可直接阻止绕过只匹配 "; boundary=" 的规则。
        if ngx.re.find(
            ctl,
            [[^\s*multipart/form-data(?:,|\s+boundary\s*=)]],
            "jo"
        ) then
            ngx.log(ngx.WARN,
                "blocked abnormal multipart content-type: ", ct)
            return ngx.exit(ngx.HTTP_FORBIDDEN)
        end

        -- 如果业务不需要 chunked multipart,建议直接拒绝。
        -- 可阻止利用 chunked 绕过 Content-Length 预检查。
        local te = string.lower(ngx.var.http_transfer_encoding or "")
        if te:find("chunked", 1, true) then
            ngx.log(ngx.WARN, "blocked chunked multipart request")
            return ngx.exit(ngx.HTTP_REQUEST_ENTITY_TOO_LARGE)
        end

        ngx.req.read_body()

        local blocked = false
        local reason
        local part_count = 0
        local nested_count = 0

        local function inspect(buf)
            local lower = string.lower(buf)

            if lower:find('name="php_session_upload_progress"', 1, true)
               or lower:find("name=php_session_upload_progress", 1, true)
            then
                blocked = true
                reason = "PHP_SESSION_UPLOAD_PROGRESS"
                return
            end

            -- PHPSESSID 正常应位于 Cookie,而不是 multipart 字段中。
            if lower:find('name="phpsessid"', 1, true)
               or lower:find("name=phpsessid", 1, true)
            then
                blocked = true
                reason = "PHPSESSID multipart field"
                return
            end

            local _, n = lower:gsub(
                "content%-disposition%s*:%s*form%-data", ""
            )
            part_count = part_count + n

            local _, nested = lower:gsub(
                'name%s*=%s*"[^"\r\n]-%[[^%]]-%]"', ""
            )
            nested_count = nested_count + nested
        end

        local body = ngx.req.get_body_data()

        if body then
            inspect(body)
        else
            local path = ngx.req.get_body_file()
            if path then
                local f = io.open(path, "rb")
                if not f then
                    ngx.log(ngx.ERR, "cannot inspect request body file")
                    return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
                end

                -- 保留重叠区,避免关键字符串跨 64 KiB 边界。
                local carry = ""
                while true do
                    local chunk = f:read(65536)
                    if not chunk then
                        break
                    end

                    local buf = carry .. chunk
                    inspect(buf)

                    if blocked then
                        break
                    end

                    carry = buf:sub(-512)
                end
                f:close()
            end
        end

        -- 即使上传进度字段被改名,异常 part 数量也能拦住本 PoC。
        if not blocked and part_count > 500 then
            blocked = true
            reason = "excessive multipart part count: " .. part_count
        end

        -- Leak-B 使用大量 aNNNN[index] 数组字段。
        if not blocked and nested_count > 128 then
            blocked = true
            reason = "excessive nested multipart fields: " .. nested_count
        end

        if blocked then
            ngx.log(
                ngx.WARN,
                "blocked suspected PHP2Shell request; reason=",
                reason,
                " uri=", ngx.var.request_uri,
                " ip=", ngx.var.remote_addr
            )
            return ngx.exit(ngx.HTTP_FORBIDDEN)
        end
    }

    fastcgi_pass php_backend;
    include fastcgi_params;
}

如果没有大文件上传业务

Nginx,直接限制请求大小

client_max_body_size 2m;

说明

以上POC分析仅为帮助建立快速响应,并无传播意图。受损企业可以根据此方式进行修复。具体实施和效用评估,请团队自行考量,本说明不做任何担保。 需要支援的可以在项目介绍章节联系上EasySwoole团队