Playing with password protected Microsoft Excel (.xlsx) files

Contents

Recently, at work, we have faced an issue where we want to resurrect one of the old Excel files and we found out that, when a file on its own can be opened without any problem, some options, like Workbook Structure or individual Sheets been protected with a password.

The problem was that the person, who initially create the file, was no longer with the company and nobody knew what password was used. As we were able to open the file on its own, as it wasn’t protected, knowing about how XLSX files are constructed, I decided to use the brute method to remove restrictions.

Here’s how it goes…

Before we move forward, I am not covering here removing passwords from files that are encrypted and require a password to open, as that is not as simple.

The XLSX files are created in a specific structure, that shortly speaking we can treat them as a compressed ZIP file containing XML files.

We can unpack them like a ZIP file and look for a structure in plain XML files. Thanks to that, by manipulating XML files, we can remove relevant password strings, compress files back into a single file and open without protections.

To do this, we will need a tool like 7-Zip.

For purpose of this article, I prepared 4 files.

4 Test files prepared for play purpose

By right-clicking on the file we will be using the 7-Zip sub-menu (in Windows 11 we need to click at the bottom to show more options and revile 7-Zip) to Open archive, Extract to… and after work is done, Add to archive….

Starting with the extraction of our XLSX file, we will head into a folder created and see the following structure.

File structure of extracted XLSX file

Each folder will contain more XML files. These are the files that we will be manipulating.

For manipulation purposes, I will be using Microsoft Visual Studio Code and by right-clicking on my folder, with extracted content of the file, I will choose option Open with Code.

Removing password - Protect Sheet #

\Book1-protected sheet.xlsx

Let’s unpack our file by right-clicking and selecting from the 7-Zip menu option Extract to Book1-protected sheet then right-clicking on the folder Book1-protected sheet and selecting Open with Code.

From VS Code top menu select Edit > Find in Files, and the search field type word protect.

This will bring you a file that contains protection like (<sheetProtection ...).

XML file with string sheetProtection in VS Code

Let’s remove the whole string, from <sheetProtection ... until it’s closing tag /> and save our file.

Going back to file explorer we head inside our folder Book1-protected sheet, selecting all files and folders there and right-clicking on selection, choosing from the 7-Zip menu Add to archive….

Compressing back to XLSX file

If it is not selected already, in the 7-Zip window, let’s select Archive format zip and on top change the desired file name from Book1-protected sheet.zip to Book1-protected sheet.xlsx and press OK to compress.

Now you can open your newly created XLSX file in Excel and your previously protected sheet will be without a password.

Quite simple, but raising the question, is this protection method shall be so easy to remove in the first place?

Removing password - Protect Workbook Structure #

\Book1-protected workbook structure.xlsx

Similarly to the above let’s unpack it by right-clicking and selecting from the 7-Zip menu option Extract to Book1-protected workbook structure, then right-clicking on the folder Book1-protected workbook structure and selecting Open with Code.

From VS Code top menu select Edit > Find in Files and in the search field type once again the word protect.

This will bring you a workbook file that contains the string <workbookProtection ....

XML file with string workbookProtection in VS Code

Let’s remove the whole string, from <workbookProtection ... until it’s closing tag /> and save our file.

Follow into your Book1-protected workbook structure folder, select all files and folders there and right-click on the selection, choose from the 7-Zip menu Add to archive….

Archive into zip format changing the desired filename to Book1-protected workbook structure.xlsx.

Once again compressing back to XLSX file

Now you can open your newly created XLSX file in Excel and your previous Workbook Structure is not protected anymore.

Removing password - Password to modify #

Removing passwords from files that require a password to modify the content (but allow to view) can be done in a similar way, but by searching the password phrase.

This will look like reservationPassword="E5F2"

XML file with string reservationPassword in VS Code

The password displayed is not in plain text form.

By removing just this part reservationPassword="E5F2" and saving our file, compressing, as before, into our XLSX file it will allow us easily to remove this type of restriction as well.

Similarly, we can experiment with any other restrictions and protection in excel files, especially on files that are freshly converted from old XLS format into new XLSX.

This will however not work on XLSX files Encrypted and protected with a password.

XLSX Files Encrypted with Password #

\Book1-encrypted with password.xlsx

If you looking into protecting your file more securely, always Encrypt with a Password which will require a password to open a file. This type of file you cannot simply unpack like a ZIP file (or you can, but data will be mangled).

Error in 7-Zip when trying to extract Enctyptex XLSX file

File structure of encrypted XLSX file

For cracking passwords on them you may need to look somewhere else.


Even if we cannot remove all restrictions without specialistic software, with the above methods we can at least regain access to some of the restricted files.

Regards.

Comments