2015年9月8日星期二

Hack into Password Protected VBA Projects



A few days ago, I had to pull out one of my old tricks to hack into a password protected VBA module. The file I was working on was protected by a former (evil) employee who, for some reason, did not leave the VBA password.
.
I’m notoriously lazy, so there is no way I’m retyping code that’s already there. I’d rather hack into the workbook.
.
Today, I’ll walk you through the steps I use to crack VBA passwords. I learned this trick a while back from one of my Excel Boot Camp students. I can’t remember who. Sorry…whoever you are. Even though I can’t remember your name, I value our friendship greatly.
.
Step 1: Download a Hex Editor
You’ll need a Hex Editor. I use one called XVI32. Why this one? Because it’s the one my mysterious friend showed me. I’m not really into Hex Editors, so I couldn’t tell you if it’s good or bad. I just know it does the trick. Download the XVI32 Hex Editor and have it ready to go.
.
Step 2: Save your Workbook as XLS and MAKE A BACKUP COPY
If you’re working with an XLSM file, you’ll need to save it as an XLS. Be sure you make a backup of your workbook before you start. Because you’re diddling the insides of the workbook, there is always a chance you could royally screw up. You’ll want a backup.
.
Step 3: Open Your Workbook in the Hex Editor
Fire up the Hex Editor you downloaded and then (within the editor) select and open your workbook. In the XVI32 editor, my workbook looks like this:
.
Step 4: Find and Replace the DPB Keyword
In your Hex Editor, look for the text string DPB.
.
This text string apparently indicates Excel’s tag for the VBA Password.

..
In order to confuse Excel and get around the VBA Password prompt, you just need to muddle the tag a little. You can do this by simply changing the DPB to something like DPX (replace the B with an X).

..
Step 5: Save Your Changes
Close the Hex Editor and be sure to save your changes
Step 6: Open your Newly Diddled Workbook
Open the workbook you just finished molesting. You will get a few messages.
First this one, which you will say Yes to:

.
Then you’ll see this one (a few times). Don’t panic, and keep clicking OK.
Step 7: Remove the VBA Protection
When Excel stops its bitching and moaning, go to the Visual Basic Editor (Alt+F11) and then select View>>Project Explorer.




Right click on the VBAProject for your workbook and select VBAProject Properties.
In the Properties dialog box, go to the Protection tab and clear any selections and text you see there.
Step 8: Save a Close your Newly Unprotected Workbook.
Save and close the workbook. At this point, you’ll have full reign over the VBA in the workbook.
.
There you have it – another trick for your toolkit.
I could suggest that you use this trick only for good and righteous purposes, but you won’t listen anyway.
 



-------------------------------------------------------------------------------------------------------------------------------

oTHER METHOD

For older .XLS files:

  1. Open file in any hex editor
  2. Search for the text "DPB=" (no quotes, you should find it just above "[Host Extender Info]"
    1
  3. Change it to "DPx=", save and close the file
    2
  4. Open the file in Excel and press Yes if the following warning pops up:
    3
  5. Open the VBA editor (Alt+F11) and press OK whenever the following warning pops up:
    4
  6. Right-click the VBA project name, select Properties, go to the Protection tab and delete the existing passwords as well as uncheck the Lock project for viewing checkbox:
    5
  7. OK your way out and now the VBA code is accessible!

For newer .XLSM files:

  1. Change the file's extension to .ZIP
  2. Open the file in any archiver such as WinRAR or 7-Zip and you'll see the following directory structure:
    6
  3. Go into the xl directory and extract vbaProject.bin:
    7
  4. Perform steps #1-3 above (from the For older .XLS files section) with vbaProject.bin
  5. Replace the old vbaProject.bin in the ZIP file with the new hex edited version
  6. Change the file's extension back to .XLSM
  7. Perform steps #4-7 above
shareimprove this answer
   
Does this work for MS office 2013 with the older files? I have an impression Microsoft patched this. – maythesource.com Feb 19 at 12:42 
   
When I tried this method in Office 2010 & 2013, it didn't work directly. After following all the steps, I was not able to view the macros, then I tried to export the macro as .bas, I could get the macro out and view it. – Abbas Mar 31 at 14:34
   
This was tested with Office 2010 and that's where the screenshots are from. Also, for those who cannot install a hex editor, there are lots of portable ones available. –  Karan Apr 5 at 2:09
   
Works for .xlam files as well. +1 –  João Mendes Jul 2 at 9:57

protected by Community Mar 31 at 19:16

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

没有评论:

发表评论