Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //////////////////////////////////////////////
- // PHP Office VBA password remover.
- //
- // Created by /u/AyrA_ch for /r/excel
- // Feel free to do whatever you want.
- //
- // Working copy at https://home.ayra.ch/unlock
- //
- //////////////////////////////////////////////
- error_reporting(E_ALL);
- function getFromZip($fName)
- {
- $temp="";
- $zip=new ZipArchive();
- if($res=$zip->open($fName))
- {
- if(($temp=$zip->getFromName("xl/vbaProject.bin"))==FALSE)
- {
- if(($temp=$zip->getFromName("word/vbaProject.bin"))==FALSE)
- {
- $temp=$zip->getFromName("ppt/vbaProject.bin");
- }
- }
- $zip->close();
- }
- else
- {
- echo "ERR";
- }
- return $temp;
- }
- function addToZip($contents,$fName)
- {
- $temp="";
- $zip=new ZipArchive;
- $res=$zip->open($fName);
- if($res=$zip->open($fName))
- {
- if($zip->getFromName("xl/vbaProject.bin")==FALSE)
- {
- if($temp=$zip->getFromName("word/vbaProject.bin")==FALSE)
- {
- $zip->deleteName("ppt/vbaProject.bin");
- $zip->addFromString("ppt/vbaProject.bin",$contents);
- }
- else
- {
- $zip->deleteName("word/vbaProject.bin");
- $zip->addFromString("word/vbaProject.bin",$contents);
- }
- }
- else
- {
- $zip->deleteName("xl/vbaProject.bin");
- $zip->addFromString("xl/vbaProject.bin",$contents);
- }
- $zip->close();
- }
- else
- {
- echo $res;
- }
- }
- if($_FILES && $_FILES['excel'])
- {
- if($fp=fopen($_FILES['excel']['tmp_name'],"rb"))
- {
- $contents=fread($fp,filesize($_FILES['excel']['tmp_name']));
- fclose($fp);
- if(substr($contents,0,2)=="PK")
- {
- //assume ZIP file (O 2007 and newer)
- $z=tempnam(dirname(__FILE__)."/TMP/","zip");
- move_uploaded_file($_FILES['excel']['tmp_name'], $z);
- $contents=getFromZip($z);
- if($contents!="")
- {
- header("Content-Type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"" . $_FILES['excel']['name'] . "\"");
- $contents=str_replace("DPB=","DPx=",$contents);
- addToZip($contents,$z);
- if($fp=fopen($z,"rb"))
- {
- echo fread($fp,filesize($z));
- fclose($fp);
- unlink($z);
- exit();
- }
- }
- }
- else
- {
- //assume classic file (O 2003 and older)
- header("Content-Type: application/octet-stream");
- header("Content-Disposition: attachment; filename=\"" . $_FILES['excel']['name'] . "\"");
- $contents=str_replace("DPB=","DPx=",$contents);
- echo $contents;
- $unlink($_FILES['excel']['tmp_name']);
- exit();
- }
- }
- }
- ?>
- <html>
- <head>
- <title>Office VBA Password remover</title>
- </head>
- <body>
- <h1>Office VBA Password remover</h1>
- <form method="post" action="index.php" enctype="multipart/form-data">
- Office File (doc,docm,xls,xlsm,ppt,pptm): <input type="file" name="excel" /><br />
- <input type="submit" value="Decrypt VBA" />
- </form>
- <h2>How it works</h2>
- <ol>
- <li>Upload your Office document. You get a document back</li>
- <li>Open the downloaded document and press [ALT]+[F11]. Confirm error message about invalid entry "BPx"</li>
- <li>In the Macro window, do not expand the project, go to Tools > VBA Project Properties</li>
- <li>On the "Protection" Tab, set a password of your choice and leave the checkbox selected.</li>
- <li>Save and close the Editor</li>
- <li>Repeat Step 3</li>
- <li>On the "Protection" Tab, clear the checkbox and password fields</li>
- <li>Save</li>
- <li>...</li>
- <li>Profit</li>
- </ol>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement