# Copyright 2026 Tailwind Resource Group # SPDX-License-Identifier: Apache-2.0 # Provided as is, with no warranty. License: https://everythingsfine.io/license/ # # php2shell_upload_guard # # Tested on BIG-IP 17.5.1.x. Start in log-only mode. # # Purpose: temporary filter for multipart requests to PHP applications, # until the PHP servers run 8.2.35, 8.3.36, 8.4.27, 8.5.12 or later # (CVE-2026-109618 and CVE-2026-109619, "php2shell"). # This iRule does not replace the PHP update. # # It finds: # - user agents of public php2shell scanners # - multipart POST requests that are chunked or have no Content-Length # - multipart POST requests larger than static::p2s_max_body # - the session upload progress field name in the first # static::p2s_scan_bytes of a multipart body # # Attach to: HTTP virtual servers whose pool members run PHP. # It does not protect BIG-IP itself. See the runbook for BIG-IP. # Log: /var/log/ltm, prefix "php2shell:". The iRule does not log body content. when RULE_INIT { # 1 = log only. 0 = log and reject with HTTP 403. set static::p2s_log_only 1 # 1 = reject every multipart POST. Use only if no application on the # virtual server accepts file uploads or multipart forms. set static::p2s_block_multipart 0 # The PHP default for session.upload_progress.name. If your servers # use a different name, put it here in lower case. set static::p2s_field "php_session_upload_progress" # Bytes of each multipart body to examine. set static::p2s_scan_bytes 131072 # Largest multipart body to permit. Make it equal to post_max_size. set static::p2s_max_body 8388608 } when HTTP_REQUEST priority 40 { set p2s_collect 0 set p2s_reason "" set p2s_ua [string tolower [HTTP::header value "User-Agent"]] if { [string first "php2shell" $p2s_ua] >= 0 || [string first "php-upload-progress-scan" $p2s_ua] >= 0 } { set p2s_reason "scanner_user_agent" } elseif { [HTTP::method] eq "POST" } { set p2s_ctype [string tolower [string trimleft [HTTP::header value "Content-Type"]]] if { [string first "multipart/" $p2s_ctype] == 0 } { set p2s_len [HTTP::header value "Content-Length"] if { $static::p2s_block_multipart } { set p2s_reason "multipart_not_permitted" } elseif { [HTTP::header exists "Transfer-Encoding"] || $p2s_len eq "" } { set p2s_reason "multipart_no_content_length" } elseif { ![string is digit -strict $p2s_len] || [string length $p2s_len] > 12 } { set p2s_reason "bad_content_length" } else { # Remove leading zeros, so that Tcl does not read the value as octal. set p2s_len [string trimleft $p2s_len "0"] if { $p2s_len eq "" } { set p2s_len 0 } if { $p2s_len > $static::p2s_max_body } { set p2s_reason "multipart_too_large len=$p2s_len" } elseif { $p2s_len > 0 } { set p2s_collect 1 if { $p2s_len > $static::p2s_scan_bytes } { HTTP::collect $static::p2s_scan_bytes } else { HTTP::collect $p2s_len } } } } } if { $p2s_reason ne "" } { log local0.warning "php2shell: reason=$p2s_reason client=[IP::client_addr] vs=[virtual name] path=[HTTP::path] enforce=[expr {!$static::p2s_log_only}]" if { !$static::p2s_log_only } { set p2s_collect 0 HTTP::respond 403 content "Forbidden" "Content-Type" "text/plain" "Connection" "close" } } } when HTTP_REQUEST_DATA priority 40 { if { !$p2s_collect } { return } set p2s_collect 0 set p2s_body [string tolower [HTTP::payload $static::p2s_scan_bytes]] set p2s_found [string first $static::p2s_field $p2s_body] unset p2s_body if { $p2s_found >= 0 } { log local0.warning "php2shell: reason=upload_progress_field client=[IP::client_addr] vs=[virtual name] path=[HTTP::path] enforce=[expr {!$static::p2s_log_only}]" if { !$static::p2s_log_only } { HTTP::respond 403 content "Forbidden" "Content-Type" "text/plain" "Connection" "close" } } }