Advertisement
AyrA

VBA Password remover

Sep 25th, 2014
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.50 KB | None | 0 0
  1. <?php
  2.     //////////////////////////////////////////////
  3.     // PHP Office VBA password remover.
  4.     //
  5.     // Created by /u/AyrA_ch for /r/excel
  6.     // Feel free to do whatever you want.
  7.     //
  8.     // Working copy at https://home.ayra.ch/unlock
  9.     //
  10.     //////////////////////////////////////////////
  11.    
  12.     error_reporting(E_ALL);
  13.    
  14.     function getFromZip($fName)
  15.     {
  16.         $temp="";
  17.         $zip=new ZipArchive();
  18.         if($res=$zip->open($fName))
  19.         {
  20.             if(($temp=$zip->getFromName("xl/vbaProject.bin"))==FALSE)
  21.             {
  22.                 if(($temp=$zip->getFromName("word/vbaProject.bin"))==FALSE)
  23.                 {
  24.                     $temp=$zip->getFromName("ppt/vbaProject.bin");
  25.                 }
  26.             }
  27.             $zip->close();
  28.         }
  29.         else
  30.         {
  31.             echo "ERR";
  32.         }
  33.         return $temp;
  34.     }
  35.  
  36.     function addToZip($contents,$fName)
  37.     {
  38.         $temp="";
  39.         $zip=new ZipArchive;
  40.         $res=$zip->open($fName);
  41.         if($res=$zip->open($fName))
  42.         {
  43.             if($zip->getFromName("xl/vbaProject.bin")==FALSE)
  44.             {
  45.                 if($temp=$zip->getFromName("word/vbaProject.bin")==FALSE)
  46.                 {
  47.                     $zip->deleteName("ppt/vbaProject.bin");
  48.                     $zip->addFromString("ppt/vbaProject.bin",$contents);
  49.                 }
  50.                 else
  51.                 {
  52.                     $zip->deleteName("word/vbaProject.bin");
  53.                     $zip->addFromString("word/vbaProject.bin",$contents);
  54.                 }
  55.             }
  56.             else
  57.             {
  58.                 $zip->deleteName("xl/vbaProject.bin");
  59.                 $zip->addFromString("xl/vbaProject.bin",$contents);
  60.             }
  61.             $zip->close();
  62.         }
  63.         else
  64.         {
  65.             echo $res;
  66.         }
  67.     }
  68.    
  69.     if($_FILES && $_FILES['excel'])
  70.     {
  71.    
  72.         if($fp=fopen($_FILES['excel']['tmp_name'],"rb"))
  73.         {
  74.             $contents=fread($fp,filesize($_FILES['excel']['tmp_name']));
  75.             fclose($fp);
  76.  
  77.             if(substr($contents,0,2)=="PK")
  78.             {
  79.                 //assume ZIP file (O 2007 and newer)
  80.                 $z=tempnam(dirname(__FILE__)."/TMP/","zip");
  81.                 move_uploaded_file($_FILES['excel']['tmp_name'], $z);
  82.                 $contents=getFromZip($z);
  83.                 if($contents!="")
  84.                 {
  85.                     header("Content-Type: application/octet-stream");
  86.                     header("Content-Disposition: attachment; filename=\"" . $_FILES['excel']['name'] . "\"");
  87.                     $contents=str_replace("DPB=","DPx=",$contents);
  88.                     addToZip($contents,$z);
  89.                     if($fp=fopen($z,"rb"))
  90.                     {
  91.                         echo fread($fp,filesize($z));
  92.                         fclose($fp);
  93.                         unlink($z);
  94.                         exit();
  95.                     }
  96.                 }
  97.             }
  98.             else
  99.             {
  100.                 //assume classic file (O 2003 and older)
  101.                 header("Content-Type: application/octet-stream");
  102.                 header("Content-Disposition: attachment; filename=\"" . $_FILES['excel']['name'] . "\"");
  103.                 $contents=str_replace("DPB=","DPx=",$contents);
  104.                 echo $contents;
  105.                 $unlink($_FILES['excel']['tmp_name']);
  106.                 exit();
  107.             }
  108.         }
  109.     }
  110.  
  111. ?>
  112. <html>
  113.     <head>
  114.         <title>Office VBA Password remover</title>
  115.     </head>
  116.     <body>
  117.         <h1>Office VBA Password remover</h1>
  118.         <form method="post" action="index.php" enctype="multipart/form-data">
  119.             Office File (doc,docm,xls,xlsm,ppt,pptm): <input type="file" name="excel" /><br />
  120.             <input type="submit" value="Decrypt VBA" />
  121.         </form>
  122.         <h2>How it works</h2>
  123.         <ol>
  124.             <li>Upload your Office document. You get a document back</li>
  125.             <li>Open the downloaded document and press [ALT]+[F11]. Confirm error message about invalid entry "BPx"</li>
  126.             <li>In the Macro window, do not expand the project, go to Tools > VBA Project Properties</li>
  127.             <li>On the "Protection" Tab, set a password of your choice and leave the checkbox selected.</li>
  128.             <li>Save and close the Editor</li>
  129.             <li>Repeat Step 3</li>
  130.             <li>On the "Protection" Tab, clear the checkbox and password fields</li>
  131.             <li>Save</li>
  132.             <li>...</li>
  133.             <li>Profit</li>
  134.         </ol>
  135.     </body>
  136. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement