Excel VBA 代码的密码保护如何工作?
这个问题与我的上一篇。
您能否解释一下或提供一个链接来说明 Excel VBA 代码密码保护在 2007 年之前的版本中实际上是如何工作的? Excel 2007和以前的版本在密码保护方面有什么区别?
Excel 的密码保护是否真的对代码进行了加密? 如果代码被加密,Excel如何执行该代码?
最后,Excel密码清除软件如何工作?
This question is related to my previous one.
Can you explain or provide a link to an explanation of how Excel VBA code password protection actually works in versions prior to 2007? What is the difference in Excel 2007 and previous versions in terms of password protection?
Also does Excel's password protection actually encrypt the code? How does Excel execute the code if it is encrypted?
Lastly, how does password removal software for excel work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
人们普遍认为 VBA 安全性相当差。 VBA 代码未编译,源代码可在 Excel 文件中找到。 密码保护很容易被绕过。
据我了解,Office 2003 及更早版本将 vba 代码保存为工作表(或文档/演示文稿)的二进制格式的一部分。 当您启动 VBA IDE 时,它只是查看 VBA 代码是否已受到“保护”。 这并不意味着它已加密 - 只是无法查看。 理论上,这可以阻止用户干扰您的代码,但硬核编码人员将能够绕过密码。
因此 Excel 不需要解密任何代码 - 它只需要阻止人们查看它。
Office 2007 确实加密宏(不要问我如何加密或使用什么算法)。 这可能是必要的,因为 XLSM 文件(或任何 Office 2007 文件)只是具有不同扩展名的 zip 文件。 任何人都可以进入这些文件并进行浏览。
为了回答你的最后一个问题 - 密码删除如何在旧版 Office 格式上工作,我不完全确定。 不同的供应商可能会以不同的方式解决这个问题,但我怀疑最常见的方法是对密码进行暴力攻击,直到找到匹配项。
Excel VBProject 对象具有 Protection 属性,该属性将根据宏的保护状态返回不同的枚举(例如,如果宏受保护,则为
vbext_pp_locked
)。 如果您继续以编程方式尝试密码,直到vbext_pp_locked
评估为 false,您就会找到密码。VBA security is widely considered to be pretty poor. The VBA code isn't compiled, and the source is available in the excel file. The password protection is pretty easy to circumvent.
As I understand it, Office 2003 and earlier saves the vba code as part of the binary format of the worksheet (or document / presentation). When you fire up the VBA IDE, it simply looks to see whether the VBA code has been "protected" or not. This doesn't mean it's encrypted - just unavailable for viewing. The theory is that this stops your users from meddling with your code, but a hard-core coder would be able to get around the password.
So Excel doesn't need to unencrypt any code - it just needs to stop people from viewing it.
Office 2007 does encrypt macros (don't ask me how or what algorithm). This is necessary presumably because XLSM files (or any Office 2007 file) are just zip files with a different extension. Anyone can get into those files and poke around.
To answer your last question - how does the password removal work on older Office formats, I'm not entirely sure. Different vendors will possibly approach the problem different ways, but I suspect the most common approach will be a brute-force attack on the passwords until a match is found.
The Excel VBProject object has a Protection property which will return different enumerations depending on the protection status of the macro (
vbext_pp_locked
if the macro is protected, for example). If you were to keep trying passwords programmatically until thevbext_pp_locked
evaluated to false, you would have found your password.菲尔是正确的 - 密码阻止您查看模块,它们本身没有加密。 我知道在 excel 2007 中文件本质上是 XML 和其他文件的压缩集合,但我不知道如何处理加密的详细信息。 对于早期版本 - Excel 2、3、4、5、95、97、2000、XP 和 2003 年,出现了全面的 OpenOffice.org 的 Microsoft Excel 文件格式文档:
密码块存储根据工作表或工作簿保护密码计算得出的 16 位哈希值。
Phil is correct - the password prevent you from looking at the modules, they are not encrypted themselves. I know in excel 2007 a file is essentially a zipped collection of XML and other files, but I don't know the details of how encryption is handled. For earlier versions - excel 2, 3, 4, 5, 95, 97, 2000, XP, & 2003, there is the comprehensive OpenOffice.org's Documentation of the Microsoft Excel File Format:
The password block stores a 16-bit hash value, calculated from the worksheet or workbook protection password.
有人编写了一个有效的 vba 代码,将所有 excel 文件(包括 .xlsm(2007+ 版本))的 vba 保护密码更改为“macro”。 你可以通过浏览他的代码来了解它是如何工作的。
这是该人的博客:http://lbeliarl.blogspot。 com/2014/03/excel-removing-password-from-vba.html
这是执行此操作的文件:https://docs.google.com/file/d /0B6sFi5sSqEKbLUIwUTVhY3lWZE0/edit
粘贴自他的博客上一篇文章:
对于 Excel 2007/2010 (.xlsm) 文件,请执行以下步骤:
从参数 DPB 中查找并复制值(引号中的值),例如:
DPB =“282A84CBA1CBA1345FCCB154E20721DE77F7D2378D0EAC90427A22021A46E9CE6F17188A”。 (此值是为“宏”密码生成的。您可以使用此 DPB 值跳过步骤 1-8)
对密码未知的文件(要解锁的文件)执行步骤 4-7。
将此文件中的 DBP 值更改为您在步骤 8 中复制的值。
<块引用>
<块引用>
如果复制的值比加密文件中的值短,您应该用 0(零)填充缺失的字符。 如果值较长 - 这不是问题(按原样粘贴)。
保存“vbaProject.bin”文件并退出十六进制编辑器。
只是宏观的(如我在这里展示的示例)。
Someone made a working vba code that changes the vba protection password to "macro", for all excel files, including .xlsm (2007+ versions). You can see how it works by browsing his code.
Here's the guy blog: http://lbeliarl.blogspot.com/2014/03/excel-removing-password-from-vba.html
Here's the file that does the work: https://docs.google.com/file/d/0B6sFi5sSqEKbLUIwUTVhY3lWZE0/edit
Pasted from a previous post from his blog:
For Excel 2007/2010 (.xlsm) files do following steps:
Find and copy the value from parameter DPB (value in quotation mark), example:
DPB="282A84CBA1CBA1345FCCB154E20721DE77F7D2378D0EAC90427A22021A46E9CE6F17188A". (This value generated for 'macro' password. You can use this DPB value to skip steps 1-8)
Do steps 4-7 for file with unknown password (file you want to unlock).
Change DBP value in this file on value that you have copied in step 8.
Save the 'vbaProject.bin' file and exit from hex editor.
will simply be macro (as in the example I'm showing here).