Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

Phpbuka Vba

This PHP script removes passwords from VBA project code in Office files like Word, Excel and PowerPoint from 2007 onwards. It extracts the vbaProject.bin file from the ZIP archive, removes the password, and adds it back to return a file without VBA protection. The document provides instructions for users to fully remove the password after running the script.

Uploaded by

Joe Habybie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Phpbuka Vba

This PHP script removes passwords from VBA project code in Office files like Word, Excel and PowerPoint from 2007 onwards. It extracts the vbaProject.bin file from the ZIP archive, removes the password, and adds it back to return a file without VBA protection. The document provides instructions for users to fully remove the password after running the script.

Uploaded by

Joe Habybie
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

<?

php
////////////////////////////////////////////////
// PHP Office VBA password remover.
//
// Created by /u/AyrA_ch for /r/excel
// Feel free to do whatever you want
// as long as access to this stays free of
// any charges and/or subscriptions.
//
// Working copy at https://home.ayra.ch/unlock/
//
// You need the bootstrap framework for this to look
nicely.
// It's optional and not required for the site to wor
k properly.
//
///////////////////////////////////////////////

//Be extra pedantic


error_reporting(E_ALL);

$err="";

//Extract vbaProject.bin from a modern office file.


function getFromZip($fName)
{
global $err;
$temp="";
$zip=new ZipArchive();

//Try to open the file as zip archive


if($res=$zip->open($fName) && $zip->numFiles>0)
{
//try to figure out, where to extract vbaProj
ect.bin from
if(($temp=$zip-
>getFromName("xl/vbaProject.bin"))==FALSE)
{
if(($temp=$zip-
>getFromName("word/vbaProject.bin"))==FALSE)
{
if(($temp=$zip-
>getFromName("ppt/vbaProject.bin"))==FALSE)
{
$err="No VBA Code in the specifie
d file. This script only removes VBA protection and not d
ocument protection (password to open or change content)";

}
}
}
$zip->close();
}
else
{
$err="Can't open your file. It seems to be fr
om Office 2007 or newer but is corrupt.";
}
//return the vbaProject.bin content if it has bee
n extracted.
return $temp===FALSE?"":$temp;
}

//Add vbaProject.bin back to a modern Office file


function addToZip($contents,$fName)
{
global $err;
$temp="";
$zip=new ZipArchive;
//Open file as zip archive
if($res=$zip->open($fName))
{
//Try to find where the original vbaProject.b
in was located and overwrite it.
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
{
$err="Can't open file to change VBA settings.
Inform the administrator.";
}
}
//provides file source code upon request
if(isset($_GET["source"]))
{
highlight_file(__FILE__);
exit(0);
}

//Check if file uploaded


if(isset($_FILES['excel']))
{
//Try to read it
if($fp=fopen($_FILES['excel']['tmp_name'],"rb"))
{
$contents=fread($fp,filesize($_FILES['excel']
['tmp_name']));
fclose($fp);

//If it starts with "PK" it is a modern file


if(substr($contents,0,2)=="PK")
{
//assume ZIP file (O2007 and newer)
$z=tempnam(dirname(__FILE__)."/TMP/","zip
");
move_uploaded_file($_FILES['excel']['tmp_
name'], $z);
$contents=getFromZip($z);
if($contents!="" && $err=="")
{
if(strpos($contents,"DPB=")===FALSE)
{
$err="We found VBA Code but it is
not protected.";
}
else
{
header("Content-
Type: application/octet-stream");
header("Content-
Disposition: attachment; filename=\"" . $_FILES['excel'][
'name'] . "\"");
$contents=str_replace("DPB=","DPx
=",$contents);
addToZip($contents,$z);
if($err=="")
{
if($fp=fopen($z,"rb"))
{
echo fread($fp,filesize($
z));
fclose($fp);
//Delete the uploaded fil
e on success
unlink($z);
exit();
}
else
{
$err="Can't send back off
ice file.";
}
}
}
}
//Delete the uploaded file on error
unlink($z);
}
else
{
//Delete uploaded file because it's in $c
ontents now
unlink($_FILES['excel']['tmp_name']);
//assume classic file (O2003 and older)
if(strpos($contents,"DPB=")===FALSE)
{
$err="There is no VBA code or it is n
ot protected.";
}
else
{
//Send back file
header("Content-
Disposition: attachment; filename=\"" . $_FILES['excel'][
'name'] . "\"");
header("Content-
Type: application/octet-stream");
//This removes the protection
$contents=str_replace("DPB=","DPx=",$
contents);
echo $contents;
exit();
}
}
}
}
?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-
Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-
Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-
width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="../b
ootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../b
ootstrap/css/bootstrap-theme.min.css" />
<script type="text/javascript" src="../bootstrap/
js/jquery.min.js"></script>
<script type="text/javascript" src="../bootstrap/
js/bootstrap.min.js"></script>
<title>Office VBA Password remover</title>
</head>
<body>
<div class="container">
<h1>Office VBA Password remover</h1>
<span style="color:#FF0000;"><?php echo $err
?></span>
<form method="post" action="index.php" enctyp
e="multipart/form-data" class="form-inline">
<label class="control-
label">Office File (doc,docm,xls,xlsm,ppt,pptm): <input t
ype="file" name="excel" class="form-
control" /></label><br />
<input type="submit" class="btn btn-
primary" 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 pres
s <kbd>ALT + F11</kbd>. Confirm error message about inval
id entry "BPx"</li>
<li>In the Macro window, <b>do not expand
the project</b>, go to Tools > VBA Project Properties</l
i>
<li>On the "Protection" Tab, set a passwo
rd of your choice <b>and leave the checkbox selected</b>.
</li>
<li>Save the document and close the Edito
r</li>
<li>Repeat Step 3</li>
<li>On the "Protection" Tab, clear the ch
eckbox and password fields</li>
<li>Save document again</li>
<li>The password is now removed and you c
an view or change the code as if it was never protected</
li>
</ol>
<hr />
<a href="?source">View Source code</a>
</div>
</body>
</html>

You might also like