我被要求更新一些Excel 2003宏,但是VBA项目有密码保护,而且似乎缺乏文档…没人知道密码。
是否有一种方法可以删除或破解VBA项目的密码?
我被要求更新一些Excel 2003宏,但是VBA项目有密码保护,而且似乎缺乏文档…没人知道密码。
是否有一种方法可以删除或破解VBA项目的密码?
当前回答
删除VBA项目密码的一个简单方法是执行以下操作:
将xlsm文件转换为zip 打开VBAProject.bin文件(我更喜欢使用notepad++ (https://notepad-plus-plus.org/downloads/)) 搜索DPB字段 用DPx替换它 保存文件 将zip文件转换为XLSM 打开excel文件 如果出现消息框,请单击“是” 为VBA项目属性设置新密码 关闭并再次打开该文件 输入新密码取消保护
其他回答
对于Windows 10机器上的Excel 2016 64位,我使用了十六进制编辑器来更改受保护的xla的密码(尚未对任何其他扩展进行测试)。 提示:在执行此操作之前创建备份。
我采取的步骤:
在十六进制编辑器中打开vba(例如XVI) 搜索这个DPB 将DPB更改为其他内容,如DPX 保存它! 重新打开.xla,将出现一条错误消息,继续。 您现在可以通过打开属性并转到password选项卡来更改.xla的密码。
我希望这对你们中的一些人有所帮助!
事实上,大多数启用宏的Office文档的代码文件都没有加密,密码只会阻止使用Office程序打开项目。 这意味着,正如其他答案所建议的那样,您通常可以使用Office替代品来访问和编辑该文件。
但是,如果你只是需要访问代码,你可以使用oldump .py这样的工具来提取宏代码。这对于恶意软件分析非常有用,还可以从文件中获取大部分代码,这样如果忘记密码,就不必从头开始了。
此外,许多excel文件在打开时动态设置密码。这意味着如果您可以阅读代码,您通常可以找到明文密码或消除混淆。
oledump.py例子:
列出一个办公文档中的所有“流”(嵌入式二进制文件或代码文件):
python oledump.py -v yourExcelFile.xlsm
输出:
A: xl/vbaProject.bin
A1: 2000 'PROJECT'
A2: 1500 'PROJECTwm'
A3: M 1224 'VBA/Module1'
A4: M 18694 'VBA/Module2'
A5: M 11877 'VBA/Module3'
...
旁边带M的流是宏,这是未加密的VBA代码
提取流
python oledump.py -s A3 -v yourExcelFile.xlsm > Module1.vba
这将把A3流中包含的代码输出到Module1.vba。
我通常将此与循环结合起来,将所有文件解压缩到一个文件夹中。这个快速的PowerShell脚本将提取大多数文件中的所有流:
New-Item -ItemType Directory "Output"
# just hardcode the highest stream outputted by oledump.py -v
$max = 5
for ($i = 1; $i -le $max; $i++) {
python oledump.py -s "A$i" -v yourExcelFile.xlsm > ".\Output\A$i"
}
注意,这将只提取人类可读的文件。
对于.xlsm或.dotm文件类型,您需要以稍微不同的方式进行操作。
Change the extension of the .xlsm file to .zip. Open the .zip file (with WinZip or WinRar etc) and go to the xl folder. Extract the vbaProject.bin file and open it in a Hex Editor (I use HxD, its completely free and lightweight.) Search for DPB and replace with DPx and save the file. Replace the old vbaProject.bin file with this new on in the zipped file. Change the file extension back to .xlsm. Open workbook skip through the warning messages. Open up Visual Basic inside Excel. Go to Tools > VBAProject Properties > Protection Tab. Put in a new password and save the .xlsm file. Close and re open and your new password will work.
Access、Excel、Powerpoint或Word文档上的VBA项目密码(带有扩展名. accdb . xlsm . xltm . docm . dotm . potm . ppsm的2007、2010、2013或2016版本)可以轻松删除。
这只是将文件名扩展名更改为. zip,解压缩文件,并使用任何基本的十六进制编辑器(如XVI32)来“打破”现有密码的问题,这会“混淆”Office,因此它会在下次打开文件时提示输入新密码。
步骤总结:
rename the file so it has a .ZIP extension. open the ZIP and go to the XL folder. extract vbaProject.bin and open it with a Hex Editor "Search & Replace" to "replace all" changing DPB to DPX. Save changes, place the .bin file back into the zip, return it to it's normal extension and open the file like normal. ALT+F11 to enter the VB Editor and right-click in the Project Explorer to choose VBA Project Properties. On the Protection tab, Set a new password. Click OK, Close the file, Re-open it, hit ALT+F11. Enter the new password that you set.
此时,如果您愿意,您可以完全删除密码。
完整的说明和我制作的“way back when”视频在YouTube上。
令人震惊的是,这种解决方法已经存在多年了,而微软还没有解决这个问题。
这个故事的寓意是什么?
Microsoft Office VBA项目密码不依赖于任何敏感信息的安全。如果安全性很重要,请使用第三方加密软件。
保护是Excel中的一个简单的文本比较。 在你最喜欢的调试器中加载Excel (Ollydbg是我选择的工具),找到进行比较的代码并将其修复为总是返回true,这应该可以让你访问宏。