<?php
//rgod_ctvx_fuzz.php
ini_set("memory_limit","512M");//some problem with memory exhaustion
error_reporting(E_ALL);        //show all php errors
$suntzu="OVCtl.OVCtl";       //progID, change this

system("php object.php $suntzu > typelib");//extract typelip

$my_typelib=file('typelib');

$metodi=array();
$prop=array();

//parse com_print_typeinfo output
for ($i=0; $i<count($my_typelib); $i++) {
   if (eregi("function",$my_typelib[$i])){
       $my_typelib[$i]=str_replace("function","",$my_typelib[$i]);
       $my_typelib[$i]=trim(str_replace("(","",$my_typelib[$i]));
       if (!in_array($my_typelib[$i],$metodi)){
           $temp=Array($my_typelib[$i]);
           $metodi=array_merge($temp,$metodi);
       }
   }
   if ((eregi("var",$my_typelib[$i])) and (!eregi("variant",$my_typelib[$i]))){
       $my_typelib[$i]=str_replace("var","",$my_typelib[$i]);
       $my_typelib[$i]=str_replace("$","",$my_typelib[$i]);
       $my_typelib[$i]=trim(str_replace(";","",$my_typelib[$i]));
       if (!in_array($my_typelib[$i],$prop)){
           $temp=Array($my_typelib[$i]);
           $prop=array_merge($temp,$prop);
       }
   }
}
//show methods and properties, hidden also
for ($i=0; $i<count($prop); $i++){
    echo "property' -> ".$prop[$i]."\n";
}
for ($i=0; $i<count($metodi); $i++){
    echo "metodo -> ".$metodi[$i]."\n";
}
$pattern=array( '$bof','$bof,$I','$I,$bof','$bof,$I,$I',
                '$I,$bof,$I','$I,$I,$bof','$bof,$I,$I,$I',
                '$I,$bof,$I,$I','$I,$I,$bof,$I','$I,$I,$I,$bof',
                '$bof,$I,$I,$I,$I','$I,$bof,$I,$I,$I','$I,$I,$bof,$I,$I',
                '$I,$I,$I,$bof,$I','$I,$I,$I,$I,$bof','$bof,$I,$I,$I,$I,$I',
                '$I,$bof,$I,$I,$I,$I','$I,$I,$bof,$I,$I,$I','$I,$I,$I,$bof,$I,$I',
                '$I,$I,$I,$I,$bof,$I','$I,$I,$I,$I,$I,$bof'
               );
$objIndexServer = new COM($suntzu);
for ($u=9999; $u<=10000;$u++){
for ($k=1; $k<=255; $k++){ 
//sleep(1);
$bof="a".str_repeat(chr($k),$u);

for ($i=0; $i<count($prop); $i++)
{  try { 
    echo "proprieta' -> ".$prop[$i].":".$k.":".$u."\n";
    $objIndexServer->$prop[$i] = $bof;
    //$objIndexServer->$prop[$i] = 1; //free memory
  } catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
}
for ($o=0;$o<count($pattern);$o++) {    

echo 'pattern: '.$o.":".$u."\n";  
if  (strtolower($metodi[$i]) <> "saveas"){ 
    
eval('
for ($i=0; $i<count($metodi); $i++)
if ($metodi[$i] <> "GetTypeInfoCount"){ 
{  try { 
    echo "metodo -> ".$metodi[$i].":".$k."\n";
    $I=1;
    $objIndexServer->$metodi[$i]('.$pattern[$o].');
  } catch (Exception $e) {
    echo "Caught exception: ",  $e->getMessage(), "\n";
}
}}
}' 
);
}
}
}
$objIndexServer = null; 
?>