How to hack password - protected Microsoft Office documents - doc files and Excel spreadsheets

Hacker

Professional
Messages
1,046
Reputation
9
Reaction score
743
Points
113
4c55d8c4a0f4b3f56280d.jpg


Hello hackers today we will analyze the hacking of password-protected Microsoft Office documents-doc files and Excel spreadsheets. To prevent fraud and ensure data integrity, Microsoft Office files are password protected. But protected documents from earlier versions of Office are vulnerable to having their hashes extracted using a simple program called office2john. The hashes obtained in this way can be cracked using John the Ripper and Hashcat.
Extracting the hash itself from a password-protected Microsoft Office file using office2john takes only a couple of seconds. Although the encryption standards in various Office products have changed over the years, none of them can resist the extraction of hashes using office2john.

This utility is written in Python and can be run directly from the terminal. As for compatibility with Office Files, office2john is known to work with any password-protected Word, Excel, PowerPoint, OneNote, Project, Access, and Outlook files created in Office 97, Office 2000, Office XP, Office 2003, Office 2007, Office 2010, and Office 2013, including the Mac versions of Office. It may not work with newer versions of Office, but we saved the DOCX file in Office 2016 and marked it as an Office 2013 file.

Step 1. Install Office2John
First, we need to download this utility from GitHub, since office2john is not included in the standard version of John the Ripper (which should already be installed on your Kali system). You can download it using wget.
Code:
wget https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/office2john.py
--2019-02-05 14:34:45-- https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/office2john.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.148.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.148.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 131690 (129K) [text/plain]
Saving to: ‘office2john.py’

Step 2. Make sure everything is in the same directory
To run office2john using Python, we need to go to the directory where it was installed. By default, for most of you, this will be the Home directory (just type cd in the console), but you can create any other directory.
For our tests, you will need a suitable file. We will use a simple DOCX file named "dummy.docx", which we created using Word 2007 and closed with a password. Download it to have something to work with. The password for the file is "password123", however, you will already know it. You can also download documents created in Word 2010 and (which appears as created in Word 2013). The password for them is the same - "password123".

Step 3. Get the hash using Office2john
The first step is to extract the hash of our secure Office file. Run the following command and write the output to a file "hash.txt", which we will use later.
python office2john.py dummy.docx > hash.txt

To verify that the hash was successfully extracted, use the cat command. We can see that the saved hash corresponds to Microsoft Office 2007. Great!
Code:
cat hash.txt
dummy.docx:$office$*2007*20*128*16*a7c7a4eadc2d90fb22c073c6324b6b49*abc5f80409f5f96f97e184e44aacd0b7*930b0c48a7eb5e13a57af4f3030b48e9402b6870

Step 4. Crack the hash you just saved
We'll show you two ways to crack the hash of a secure Microsoft Office file that you just saved. Both methods work perfectly, so choose the one that you prefer.

Option 1: Hacking with John the Reaper
Set the —wordlist flag and pass it the path to your favorite wordlist. The wordlist included in Nmap is perfect for our purposes, but for more complex passwords, you should use a more detailed wordlist.
Code:
john --wordlist=/usr/share/wordlists/nmap.lst hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (Office, 2007/2010/2013 [SHA1 128/128 SSE2 4x / SHA512 128/128 SSE2 2x AES])
Cost 1 (MS Office version) is 2007 for all loaded hashes
Cost 2 (iteration count) is 50000 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status

John will start hacking, and depending on the complexity of the password, it will finish working when it finds a match. To view the current status of the process, press any key. When the hash is cracked, a message with the document password will appear on the screen. Since our password was very simple, it took only a few seconds to crack it.
Code:
password123 (dummy.docx)
1g 0:00:00:03 DONE (2019-02-05 15:00) 0.2824g/s 415.8p/s 415.8c/s 415.8C/s lacoste..cooldude
Use the "--show" option to display all of the cracked passwords reliably
Session completed

We can also use the -show option to display it like this:
Code:
john --show hash.txt
dummy.docxassword123

1 password hash cracked, 0 left

Now that we know one method for hacking a password-protected Microsoft Office file, let's look at another method, using the fairly powerful Hashcat tool.

Option 2: Hacking with Hashcat
You can start working with Hashcat by displaying its help (-help). This command provides quite a lot of information, including usage parameters, hash modes, and other functions. There is a lot of it here, so we won't show its output, but if you really want to know Hashcat, then you should carefully study its help.
Code:
hashcat --help

From all this abundance of information, we need MS Office hashing modes. At the bottom of the help, we'll find the MS Office mode settings and their corresponding numbers. From our hash, we know that this is an Office 2007 file, so find its number-ID *9400*.
Code:
9700 | MS Office <= 2003 $0/$1, MD5 + RC4 | Documents
9710 | MS Office <= 2003 $0/$1, MD5 + RC4, collider #1 | Documents
9720 | MS Office <= 2003 $0/$1, MD5 + RC4, collider #2 | Documents
9800 | MS Office <= 2003 $3/$4, SHA1 + RC4 | Documents
9810 | MS Office <= 2003 $3, SHA1 + RC4, collider #1 | Documents
9820 | MS Office <= 2003 $3, SHA1 + RC4, collider #2 | Documents
9400 | MS Office 2007 | Documents
9500 | MS Office 2010 | Documents

You can now set the remaining parameters using the following command:
Code:
hashcat -a 0 -m 9400 --username -o cracked_pass.txt hash.txt /usr/share/wordlists/nmap.lst

  • The -a flag sets the attack type, which is simply 0 by default.
  • The -m flag sets the mode we want to use, i.e. the one we just found.
  • The -username option ignores any user names in this hash file.
  • With the -o flag, we can specify the output file as cracked.txt.
  • And finally, we can pass to the command hash.txt, which contains the hash, and specify the wordlist, as we did earlier.
And then Hashcat will start the hacking process.
Code:
hashcat (v5.1.0) starting...

* Device #2: Not a native Intel OpenCL runtime. Expect massive speed loss.
You can use --force to override, but do not report related errors.
OpenCL Platform #1: Intel(R) Corporation
========================================
* Device #1: Intel(R) Core(TM) i5 CPU M 480 @ 2.67GHz, 934/3736 MB allocatable, 4MCU

...

After some time, the Status field will show us that the hash has been hacked, and you can view the password.
Code:
Session..........: hashcat
Status...........: Cracked
Hash.Type........: MS Office 2007
Hash.Target......: $office$*2007*20*128*16*a7c7a4eadc2d90fb22c073c6324...2b6870
Time.Started.....: Tue Feb 5 15:08:00 2019 (4 secs)
Time.Estimated...: Tue Feb 5 15:08:04 2019 (0 secs)
Guess.Base.......: File (/usr/share/wordlists/nmap.lst)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 610 H/s (8.51ms) @ Accel:512 Loops:128 Thr:1 Vec:4
Recovered........: 1/1 (100.00%) Digests, 1/1 (100.00%) Salts
Progress.........: 2048/5084 (40.28%)
Rejected.........: 0/2048 (0.00%)

Just view the specified output file using the cat command, where you will see the hash, and at the end the open decrypted text.
Code:
cat cracked_pass.txt
$office$*2007*20*128*16*a7c7a4eadc2d90fb22c073c6324b6b49*abc5f80409f5f96f97e184e44aacd0b7*930b0c48a7eb5e13a57af4f3030b48e9402b6870assword123

Super! Now we know two ways to crack the hash after extracting it from a secure office file using office2john.

How to protect yourself from hacking
When it comes to cracking any type of password, the best way to protect yourself is to use unique and strong passwords, i.e. those that are long and difficult to guess. This means using combinations of uppercase and lowercase letters, numbers, and special characters, although recent research shows that simply using long phrases with high entropy is more effective. Even better, use long, randomly generated passwords that make them almost impossible to crack.
For this particular attack, using Microsoft Office 2016, 2019, or newer documents may not be effective, because office2john is designed to work with earlier versions of Office. However, as you can see above, Office 2016 can easily produce a 2013 document without even knowing it. Therefore, using newer versions of Microsoft Office does not mean that the "new" file cannot be hacked.

Conclusion
Today we learned that password-protected Microsoft Office files are not as secure as you might think. We used a tool called office2john to extract a hash from a DOCX file, and then cracked that hash using the John the Ripper and Hashcat programs. These file types are still widely used, so if you encounter a file with a password, know that there is a way to crack it.
 
Top