#!/usr/bin/env bash # Copyright 2026 Tailwind Resource Group # SPDX-License-Identifier: Apache-2.0 # Provided as is, with no warranty. License: https://everythingsfine.io/license/ # # php2shell-check.sh # # Read-only. Reports the PHP versions, the Apache PHP module, vendor # backports and the interim settings on this host for CVE-2026-109618 # and CVE-2026-109619 ("php2shell"). It changes nothing. # # Run as root, so that apachectl and php-fpm can read their configuration. # Exit status: 0 = every PHP binary found is a fixed release, # 1 = one or more is not, or is not known, 2 = no PHP binary found. set -u # Fixed release for each supported branch. fixed_patch() { case "$1" in 8.2) echo 35 ;; 8.3) echo 36 ;; 8.4) echo 27 ;; 8.5) echo 12 ;; *) echo "" ;; esac } status=0 found=0 seen="" for bin in php php-fpm php-cgi \ /usr/bin/php[0-9]* /usr/sbin/php-fpm* /usr/local/bin/php /usr/local/sbin/php-fpm \ /opt/remi/php*/root/usr/bin/php /opt/remi/php*/root/usr/sbin/php-fpm; do path=$(command -v "$bin" 2>/dev/null) || continue real=$(readlink -f "$path" 2>/dev/null || echo "$path") case " $seen " in *" $real "*) continue ;; esac seen="$seen $real" found=1 ver=$("$real" -v 2>/dev/null | sed -n '1s/^PHP \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p') if [ -z "$ver" ]; then echo "UNKNOWN $real: cannot read the version" status=1 continue fi branch=${ver%.*} patch=${ver##*.} want=$(fixed_patch "$branch") if [ -z "$want" ]; then echo "CHECK $real: PHP $ver. The PHP project does not fix this branch. Ask your vendor for a backport, or upgrade." status=1 elif [ "$patch" -ge "$want" ]; then echo "FIXED $real: PHP $ver (fixed in $branch.$want)" else echo "UPDATE $real: PHP $ver (fixed in $branch.$want). A vendor backport can keep the old number: see below." status=1 fi case "$real" in *php-cgi*) ;; *) "$real" -i 2>/dev/null | grep -E '^(Server API|Loaded Configuration File|Scan this dir|session\.upload_progress\.enabled|fatal_error_backtraces|memory_limit|post_max_size|max_input_nesting_level) ' | sed 's/^/ /' ;; esac done echo echo "Apache PHP module (mod_php has the highest risk):" apache_found=0 for ctl in apachectl apache2ctl httpd; do if command -v "$ctl" >/dev/null 2>&1; then apache_found=1 "$ctl" -M 2>/dev/null | grep -Ei 'php[0-9_]*_module' | sed "s/^/ $ctl: /" fi done [ "$apache_found" -eq 1 ] || echo " no apachectl, apache2ctl or httpd found" echo echo "Vendor package changelogs that name the CVEs (backports):" if command -v rpm >/dev/null 2>&1; then for pkg in $(rpm -qa 2>/dev/null | grep -E '^php[0-9.]*-(common|cli|fpm)-' ); do rpm -q --changelog "$pkg" 2>/dev/null | grep -m 1 -E 'CVE-2026-10961[89]' | sed "s/^/ $pkg: /" done fi for log in /usr/share/doc/php*/changelog.Debian.gz; do [ -r "$log" ] || continue gzip -dc -- "$log" | grep -m 1 -E 'CVE-2026-10961[89]' | sed "s|^| $log: |" done if [ "$found" -eq 0 ]; then echo "No PHP binary found on this host." exit 2 fi exit "$status"