#!/usr/bin/env bash # php2shell-check.sh — READ-ONLY triage for PHP2Shell (CVE-2026-109618 / CVE-2026-109619) # and the related CVE-2026-115560 (version check only). # # Looks for the behavioural signs of exploitation: PHP worker crashes and OOMs, # odd POSTs and 5xx in access logs, shells/downloaders spawned by PHP, outbound # connections from web users, new PHP files and webshell patterns, persistence # (cron, keys, uid 0, systemd), and the same inside running Docker containers. # # It never writes, deletes, restarts or installs anything. It only reads files, # /proc, logs, `ps`/`ss`, and runs read-only `docker ps/top/diff/logs/exec cat|php -v`. # There are no published IOCs yet, so a WARN means "look closer", not "breached". # # Usage: sudo bash php2shell-check.sh [--since YYYY-MM-DD] [--no-docker] | tee ~/php2shell-report.txt # (run as root to see every process, log and container; tee is yours, not the script's) set -u export LC_ALL=C SINCE="2026-08-01" # Sophos: review from Aug 1 2026, the flaws may have been known pre-disclosure DOCKER=1 while [ $# -gt 0 ]; do case "$1" in --since) SINCE="${2:?--since needs a date}"; shift 2 ;; --no-docker) DOCKER=0; shift ;; -h|--help) sed -n '2,15p' "$0"; exit 0 ;; *) echo "unknown argument: $1" >&2; exit 2 ;; esac done WARNS=0 hdr() { printf '\n==== %s ====\n' "$*"; } info() { printf ' %s\n' "$*"; } warn() { WARNS=$((WARNS + 1)); printf ' [WARN] %s\n' "$*"; } ok() { printf ' [ok] %s\n' "$*"; } have() { command -v "$1" >/dev/null 2>&1; } WEB_USERS='www-data|apache|nginx|http|nobody|lsadm|wwwrun|_www' WEB_PROCS='php|php-fpm|php-cgi|lsphp|frankenphp|apache2|httpd|nginx|litespeed|lshttpd' SUSPECT_CHILD='^(sh|bash|dash|zsh|ash|busybox|curl|wget|nc|ncat|netcat|socat|python[0-9.]*|perl|ruby|base64|telnet|openssl|xmrig|kinsing)$' WEBSHELL_RE='eval[[:space:]]*\([[:space:]]*(base64_decode|gzinflate|gzuncompress|str_rot13|\$_(POST|GET|REQUEST|COOKIE))|assert[[:space:]]*\([[:space:]]*\$_(POST|GET|REQUEST)|(system|passthru|shell_exec|exec|popen|proc_open)[[:space:]]*\([[:space:]]*\$_(POST|GET|REQUEST|COOKIE)|preg_replace[[:space:]]*\(.*/e["'"'"']|\$_(POST|GET|REQUEST)\[[^]]+\][[:space:]]*\(' # Fixed upstream releases. Distros backport without bumping the upstream version, # so "below fixed" on a distro package means "check its advisory". # PHP2Shell (CVE-2026-109618 / CVE-2026-109619): 8.5.12 / 8.4.27 / 8.3.36 / 8.2.35 (2026-10-21) # CVE-2026-115560 (related): 8.5.13 / 8.4.28 / 8.3.37 / 8.2.36 (2026-11-19) php_fixed_in() { # $1 = version, $2 = label, $3..$6 = fixed patch level for 8.5 8.4 8.3 8.2 local v="$1" label="$2" maj min pat fixed IFS=. read -r maj min pat <<<"${v%%[-+~]*}" pat="${pat%%[!0-9]*}"; pat="${pat:-0}" case "$maj.$min" in 8.5) fixed=$3 ;; 8.4) fixed=$4 ;; 8.3) fixed=$5 ;; 8.2) fixed=$6 ;; *) echo "VULN $label: EOL branch $maj.$min, no upstream fix (use a vendor/LTS backport or upgrade)"; return 1 ;; esac if [ "$pat" -ge "$fixed" ]; then echo "OK $label: patched (>= $maj.$min.$fixed)"; return 0; fi echo "VULN $label: below $maj.$min.$fixed, vulnerable unless your distro backported the fix (check its advisory)"; return 1 } php_verdict() { # $1 = version string like 8.3.30; one "OK ..."/"VULN ..." line per fix php_fixed_in "$1" "PHP2Shell (CVE-2026-109618/109619)" 12 27 36 35 php_fixed_in "$1" "CVE-2026-115560" 13 28 37 36 return 0 } report_php() { # $1 = what was found (binary, package, ...), $2 = version local line while IFS= read -r line; do case "$line" in OK\ *) ok "$1 — ${line#OK }" ;; *) warn "$1 — ${line#VULN }" ;; esac done < <(php_verdict "$2") } echo "PHP2Shell read-only check — host $(hostname) — $(date -u +%FT%TZ) — since $SINCE" [ "$(id -u)" -eq 0 ] || echo "NOTE: not running as root; some logs, processes and containers will be invisible." # --------------------------------------------------------------------------- hdr "1. PHP runtimes on the host" found=0 for bin in $(ls /usr/bin/php* /usr/sbin/php-fpm* /usr/local/bin/php* /usr/local/sbin/php-fpm* /usr/local/lsws/lsphp*/bin/php 2>/dev/null | sort -u); do [ -x "$bin" ] || continue ver=$("$bin" -v 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+[^ ]*' | head -1) [ -n "$ver" ] || continue found=1 report_php "$bin $ver" "$ver" done [ "$found" -eq 1 ] || info "no PHP binary on the host itself (containers checked in section 7)" if have dpkg-query; then # Only installed ("ii") packages; removed ones linger in dpkg with status "rc". dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version}\n' 'php*-fpm' 'php*-cli' 'php*-cgi' 'libapache2-mod-php*' 2>/dev/null | awk '$1 == "ii" {print $2, $3}' | while read -r pkg pver; do up=$(echo "$pver" | grep -oE '^([0-9]+:)?[0-9]+\.[0-9]+\.[0-9]+' | sed 's/^[0-9]*://') [ -n "$up" ] || { info "pkg: $pkg $pver"; continue; } report_php "pkg: $pkg $pver" "$up" done elif have rpm; then rpm -qa 'php*' 2>/dev/null | grep -E 'php(-fpm|-cli|-common)?-[0-9]' | sed 's/^/ pkg: /' fi ps -eo comm= 2>/dev/null | grep -E "^($WEB_PROCS)" | sort | uniq -c | sed 's/^/ running: /' modphp=$(ls /etc/apache2/mods-enabled/php*.load /etc/httpd/conf.modules.d/*php* 2>/dev/null) [ -n "$modphp" ] && info "Apache mod_php enabled (highest-risk setup): $modphp" fpmsock=$(grep -rlsE 'proxy:(unix|fcgi).*php|SetHandler.*php|fastcgi_pass' /etc/apache2/sites-enabled /etc/apache2/conf-enabled /etc/httpd/conf.d /etc/nginx/sites-enabled /etc/nginx/conf.d 2>/dev/null) [ -n "$fpmsock" ] && info "web server hands requests to PHP via: $fpmsock" [ -z "$modphp$fpmsock" ] && pgrep -x apache2 >/dev/null 2>&1 && info "apache2 runs but no mod_php or PHP handler found: it may only proxy to a non-PHP backend (then PHP2Shell doesn't reach this host)" # --------------------------------------------------------------------------- hdr "2. PHP worker crashes and out-of-memory (logs + journal + kernel)" LOGS=$(ls /var/log/php*fpm*.log* /var/log/php-fpm/*.log* /var/log/php*/*.log* \ /var/log/apache2/*error*.log* /var/log/httpd/*error* /var/log/nginx/*error*.log* \ /usr/local/lsws/logs/error.log* /var/log/syslog* /var/log/messages* 2>/dev/null | sort -u) CRASH_RE='exited on signal (11|6|7)|SIGSEGV|SIGBUS|core dumped|segfault at|Allowed memory size of [0-9]+ bytes exhausted|Out of memory \(allocated' if [ -n "$LOGS" ]; then n=$(zgrep -hcE "$CRASH_RE" $LOGS 2>/dev/null | awk '{s+=$1} END {print s+0}') if [ "$n" -gt 0 ]; then warn "$n crash/OOM lines in web/PHP logs — check whether they cluster around odd requests:" zgrep -hE "$CRASH_RE" $LOGS 2>/dev/null | tail -25 | sed 's/^/ /' else ok "no worker crashes or OOMs in: $(echo $LOGS | wc -w) log files"; fi else info "no PHP/web error logs found in the usual places"; fi if have journalctl; then j=$(journalctl --since "$SINCE" --no-pager -q 2>/dev/null | grep -iE "(php|lsphp|frankenphp|apache2|httpd).*(segfault|signal 11|SIGSEGV|core dump)|traps: (php|lsphp|frankenphp)" | tail -25) [ -n "$j" ] && { warn "journal shows PHP crashes since $SINCE:"; echo "$j" | sed 's/^/ /'; } || ok "journal: no PHP segfaults since $SINCE" fi if have dmesg; then d=$(dmesg 2>/dev/null | grep -iE "(php|lsphp|frankenphp).*segfault" | tail -10) [ -n "$d" ] && { warn "kernel ring buffer has PHP segfaults:"; echo "$d" | sed 's/^/ /'; } fi # --------------------------------------------------------------------------- hdr "3. Access logs: POSTs, 5xx and upload-progress probes" ACC=$(ls /var/log/nginx/*access*.log* /var/log/apache2/*access*.log* /var/log/apache2/other_vhosts_access.log* \ /var/log/httpd/*access* /usr/local/lsws/logs/access.log* 2>/dev/null | sort -u) if [ -n "$ACC" ]; then up=$(zgrep -hc 'PHP_SESSION_UPLOAD_PROGRESS' $ACC $LOGS 2>/dev/null | awk '{s+=$1} END {print s+0}') [ "$up" -gt 0 ] && { warn "$up log lines mention PHP_SESSION_UPLOAD_PROGRESS (the field exploit chains abuse):"; zgrep -h 'PHP_SESSION_UPLOAD_PROGRESS' $ACC $LOGS 2>/dev/null | tail -10 | sed 's/^/ /'; } # Prints "ip path status"; copes with combined and vhost_combined ("host:port ip - - ...") formats. PARSE='{ ip = ($1 ~ /:[0-9]+$/ && $2 ~ /^[0-9a-fA-F.:]+$/) ? $2 : $1 for (i = 1; i < NF; i++) if ($i ~ /^"[A-Z]+$/) { path = $(i+1); st = $(i+3); break } sub(/\?.*/, "?…", path); print ip, path, st }' info "POSTs that ended in 500/502/503/504 (worker died or errored), top 20 IP + path:" zgrep -hE '"POST [^"]*" (500|502|503|504) ' $ACC 2>/dev/null | awk "$PARSE" | sort | uniq -c | sort -rn | head -20 | sed 's/^/ /' info "502s per day (a spike on/after disclosure is worth a look):" zgrep -hE '" 502 ' $ACC 2>/dev/null | grep -oE '\[[0-9]{2}/[A-Za-z]{3}/[0-9]{4}' | sort | uniq -c | tail -20 | sed 's/^/ /' info "top 15 POST targets (anything that never takes uploads is suspicious):" zgrep -hE '"POST ' $ACC 2>/dev/null | awk "$PARSE" | awk '{print $2}' | sort | uniq -c | sort -rn | head -15 | sed 's/^/ /' info "client IPs above in 10.x/172.16-31.x/192.168.x are usually your load balancer/WAF — real attacker IPs are in its logs or X-Forwarded-For" info "access logs rarely record request bodies — check WAF/CDN events (e.g. Cloudflare Security → Events) too" else info "no access logs found (behind a CDN? check its logs/WAF events)"; fi # --------------------------------------------------------------------------- hdr "4. Processes: shells/downloaders spawned by PHP or the web server" hits=0 for p in /proc/[0-9]*; do pid=${p#/proc/} comm=$(cat "$p/comm" 2>/dev/null) || continue echo "$comm" | grep -qE "$SUSPECT_CHILD" || continue ppid=$pid; chain="" for _ in 1 2 3 4 5 6; do ppid=$(awk '/^PPid:/ {print $2}' "/proc/$ppid/status" 2>/dev/null); [ -n "$ppid" ] && [ "$ppid" -gt 1 ] || break pc=$(cat "/proc/$ppid/comm" 2>/dev/null); chain="$chain<$pc" if echo "$pc" | grep -qE "^($WEB_PROCS)"; then hits=$((hits + 1)) warn "pid $pid '$comm' runs under web process ($comm$chain): $(tr '\0' ' ' < "$p/cmdline" 2>/dev/null | cut -c1-200)" break fi done done [ "$hits" -eq 0 ] && ok "no shell/downloader process under a PHP or web-server parent" info "everything currently running as a web user:" ps -eo user:12,pid,ppid,etime,cmd --sort=user 2>/dev/null | grep -E "^($WEB_USERS) " | grep -vE " ($WEB_PROCS)[: ]|php-fpm: (pool|master)|nginx: worker|/usr/sbin/(apache2|httpd)" | cut -c1-200 | sed 's/^/ /' # --------------------------------------------------------------------------- hdr "5. Network: connections and listeners owned by web users / PHP" if have ss; then out=$(ss -tnpH state established 2>/dev/null | grep -E "\"($WEB_PROCS|$SUSPECT_CHILD)" | grep -vE ':(80|443|8080|8443|9000) ' | head -20) [ -n "$out" ] && { warn "established connections from PHP/web processes to non-web ports (outbound C2/miner?):"; echo "$out" | sed 's/^/ /'; } || ok "no unusual established connections from PHP/web processes" lis=$(ss -tlnpH 2>/dev/null | grep -E "\"($SUSPECT_CHILD|php)" | head -10) [ -n "$lis" ] && { warn "listening sockets owned by PHP/shell processes (bind shell?):"; echo "$lis" | sed 's/^/ /'; } else info "ss not available"; fi # --------------------------------------------------------------------------- hdr "6. Files and persistence since $SINCE" ROOTS=$(ls -d /var/www /srv /usr/share/nginx /home/*/public_html /home/*/www /opt/*/www /var/lib/docker/volumes 2>/dev/null) TMPS="/tmp /var/tmp /dev/shm" if [ -n "$ROOTS" ]; then new=$(find $ROOTS -xdev \( -name node_modules -o -name .git \) -prune -o \ -type f \( -name '*.php' -o -name '*.phtml' -o -name '*.php[0-9]' -o -name '*.phar' -o -name '.user.ini' -o -name '.htaccess' \) \ -newermt "$SINCE" -print 2>/dev/null | head -40) [ -n "$new" ] && { warn "PHP/.htaccess/.user.ini files created or changed since $SINCE (expected after deploys; check unknown ones):"; echo "$new" | while read -r f; do ls -l "$f" 2>/dev/null; done | sed 's/^/ /'; } || ok "no new/changed PHP files in web roots since $SINCE" info "scanning web roots for webshell patterns ($(echo $ROOTS); skips vendor/node_modules/.git/cache; big trees take a few minutes)..." shells=$(nice -n 19 grep -rlIE "$WEBSHELL_RE" --include='*.php' --include='*.phtml' --include='*.inc' \ --exclude-dir=vendor --exclude-dir=node_modules --exclude-dir=.git --exclude-dir=cache \ --exclude-dir=storage --exclude-dir=uploads-cache $ROOTS 2>/dev/null | head -25) [ -n "$shells" ] && { warn "files matching webshell patterns (eval of request data, base64+eval, exec of \$_POST…):"; echo "$shells" | sed 's/^/ /'; } || ok "no webshell patterns in web roots" fi tmpphp=$(find $TMPS -xdev -type f \( -name '*.php*' -o -name '*.phar' -o -perm -u+x \) -newermt "$SINCE" 2>/dev/null | head -20) [ -n "$tmpphp" ] && { warn "PHP or executable files in temp dirs since $SINCE:"; echo "$tmpphp" | while read -r f; do ls -l "$f" 2>/dev/null; done | sed 's/^/ /'; } || ok "no PHP/executables dropped in /tmp, /var/tmp, /dev/shm" cr=$(find /etc/cron* /var/spool/cron /etc/anacrontab -type f -newermt "$SINCE" 2>/dev/null) [ -n "$cr" ] && { warn "cron files changed since $SINCE:"; echo "$cr" | sed 's/^/ /'; } || ok "no cron changes since $SINCE" for u in www-data apache nginx http; do for f in /var/spool/cron/crontabs/$u /var/spool/cron/$u; do [ -s "$f" ] && { warn "web user $u has a crontab ($f):"; sed 's/^/ /' "$f"; }; done done keys=$(find /root/.ssh /home/*/.ssh /var/www/.ssh -name 'authorized_keys*' -newermt "$SINCE" 2>/dev/null) [ -n "$keys" ] && { warn "authorized_keys changed since $SINCE:"; echo "$keys" | sed 's/^/ /'; } || ok "no authorized_keys changes since $SINCE" uid0=$(awk -F: '$3==0 && $1!="root" {print $1}' /etc/passwd) [ -n "$uid0" ] && warn "extra uid-0 accounts: $uid0" websh=$(awk -F: -v re="^($WEB_USERS)$" '$1 ~ re && $7 ~ /(ba|z|da)?sh$/ {print $1":"$7}' /etc/passwd) [ -n "$websh" ] && warn "web user with a login shell: $websh" units=$(find /etc/systemd/system /lib/systemd/system /etc/init.d /etc/rc.local -maxdepth 2 -type f -newermt "$SINCE" 2>/dev/null | head -20) [ -n "$units" ] && info "systemd/init files changed since $SINCE (package upgrades also do this):" && echo "$units" | sed 's/^/ /' pre=$(cat /etc/ld.so.preload 2>/dev/null) [ -n "$pre" ] && warn "/etc/ld.so.preload is set (rootkit trick): $pre" # --------------------------------------------------------------------------- hdr "7. Docker containers running PHP" if [ "$DOCKER" -eq 1 ] && have docker && docker info >/dev/null 2>&1; then for c in $(docker ps --format '{{.Names}}' 2>/dev/null); do ver=$(docker exec "$c" sh -c 'php -v 2>/dev/null | head -1' 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) procs=$(docker top "$c" -eo pid,ppid,user,comm,args 2>/dev/null) echo "$procs" | grep -qE " ($WEB_PROCS)" || [ -n "$ver" ] || continue printf '\n -- %s (%s)\n' "$c" "$(docker inspect -f '{{.Config.Image}}' "$c" 2>/dev/null)" if [ -n "$ver" ]; then report_php "PHP $ver" "$ver" fi sus=$(echo "$procs" | awk -v re="$SUSPECT_CHILD" 'NR>1 && $4 ~ re' | grep -vE 'entrypoint|supervisord|docker-php-entrypoint|wait-for' ) [ -n "$sus" ] && { warn "shell/downloader processes inside $c (check their parents):"; echo "$sus" | cut -c1-200 | sed 's/^/ /'; } diff=$(docker diff "$c" 2>/dev/null | grep -E '^[AC] .*(\.php[0-9]?|\.phtml|\.phar|\.htaccess|\.user\.ini)$|^A /(tmp|var/tmp|dev/shm)/' | grep -vE '/(vendor|cache|sessions?)/' | head -25) [ -n "$diff" ] && { warn "files added/changed in $c since its image (A=added C=changed):"; echo "$diff" | sed 's/^/ /'; } || ok "no PHP files added/changed since the image was built" dl=$(docker logs --since "$SINCE" "$c" 2>&1 | grep -E "$CRASH_RE|PHP_SESSION_UPLOAD_PROGRESS" | tail -15) [ -n "$dl" ] && { warn "crash/OOM/upload-progress lines in $c logs:"; echo "$dl" | sed 's/^/ /'; } || ok "container logs since $SINCE: no crashes, OOMs or upload-progress probes" done else info "docker not present, not reachable, or skipped (--no-docker)"; fi # --------------------------------------------------------------------------- hdr "Summary" if [ "$WARNS" -eq 0 ]; then echo " No warnings. Keep PHP at 8.5.13 / 8.4.28 / 8.3.37 / 8.2.36 or later (or your distro backport):" echo " those cover PHP2Shell and CVE-2026-115560." else echo " $WARNS warning(s). Review each one above. If you see PHP spawning shells, outbound connections" echo " from web users, or unknown PHP files: isolate the host, keep the logs, rebuild from a clean," echo " patched image rather than cleaning in place." fi