Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Sometime ago I made a .ods file with Libreoffice Calc which I password protected. I have now forgotten the password and so am unable to access the file. Is there any way of bypassing the password as root using the terminal or recovering the password? Thanks.

share|improve this question
    
Not really, unless you install a password cracker. –  MiJyn Nov 28 '12 at 18:44
    
Is that possible and safe? –  Kyle Nov 28 '12 at 18:45
    
Possibility depends on how large your password was, how fast your computer is, and how much time until the next thunderstorm :P. Safety is of course an issue, but you can uninstall the cracker afterwards, and while it is running remove internet connection (but that is really being on the uber-safe side, you probably don't need to do that) –  MiJyn Nov 28 '12 at 18:48
    
I think the password is around 10 characters. Would it take hours or days? –  Kyle Nov 28 '12 at 18:50
    
That depends on the speed of your computer (and on the speed of the password cracker). If you have an NVIDIA graphics card with CUDA support, and if the password cracker has CUDA support too, you can drastically improve the speed. I'd say aim for 2 days (to be on the safe side), but it could be 3-5 hours too. –  MiJyn Nov 28 '12 at 18:55

2 Answers 2

Answer was based on the conversation I had with the OP in the comments

There is no way of bypassing the password because if it was possible, it would completely defeat the purpose of having a password-protected document (the only people who would not want to use the password by-passer is the ones who have the password). The only option is to actually use a password cracker. This method is legal if, and only if you are the owner of the document, or the person who sent you the document gave you permission to crack the password. But, of course, these days no one cares about being on the right side of the law :P

So if you are still interested in doing so, here is another drawback of this technique (yay!): It takes a very long time because it has to find every single possible password combination. Just some very basic math here, if it takes 1 millisecond to try a password, and the password is ASCII encoded, 5 characters long, then it would take 56 weeks to find it. If you have a very fast computer (maybe even a supercomputer), it would take around 5-10 microseconds per password, so it would take 1.5-3 days to calculate it. If you use a graphics card instead of your CPU, it will be able to calculate passwords much faster, as GPUs usually have around 32-64 cores.

Another problem, specific to OpenOffice passwords, is that OpenOffice has very good encryption methods, making it much longer and harder to find passwords. This means that only a brute-force attack (the slowest attack) will work!

Now that you have a short introduction to password cracking, some quick googling lead me to this site: http://www.filebuzz.com/fileinfo/37067/OpenOffice_Writer_Password_Recovery.html. Haven't tried it yet, but it should work if you have WINE installed. I did a small virus check with ClamAV and it seems ok.

EDIT: Seems like that one only supports Writer passwords. Here is the same program, apparently engineered for Calc passwords. Notice that I have not tried that one either, but I have virus checed that one with ClamAV too: http://www.sharewareconnection.com/download-openoffice-calc-password-recovery-from-sharecon.html

EDIT 2: Lekensteyn posted a way better way of doing this than using an untrusted .exe file. I highly recommend using his way instead!

EDIT 3: Based on the method Lekensteyn posted, I wrote a little tool that implemented it, located here: https://github.com/MiJyn/ooo-pass-recover/downloads. It is, of course, open-source (just click on "code" from the download link). All it is is just an interface to ODFJlib by Ringlord (same person that made the document Lekensteyn posted). Notice that this tool is written in Java, and is rather slow (243 keys/sec on my computer). I will try to optimize it for multiple cores though.

Example of usage:

java -jar ./ooopassrecover.jar file.ods
share|improve this answer
    
Microseconds (µs) is very optimistic, a millisecond (ms) is more likely. –  Lekensteyn Nov 28 '12 at 20:50
    
right, updated the post :) –  MiJyn Nov 28 '12 at 20:52
    
Equally, most intelligent crackers nowadays don't blindly try different possible permutations of a string; they're normally based in some form on dictionary attacks or sometimes use common password lists –  jackweirdy Nov 29 '12 at 2:06
    
+1 Nice that you wrote an open-source program for it :-) Using Java for this purpose will give you horrible performance, but it works for a small number of keys. –  Lekensteyn Nov 30 '12 at 10:49
    
@Lekensteyn, I know... if I have time I will rewrite it in C (I personally hate java, but I didn't want Kyle to suffer for my lack of knowlege in C.. –  MiJyn Nov 30 '12 at 16:36

Opening the .ods file as root will still not allow you to retrieve the file contents because those are encrypted which is beyond the power of a root user.

MiJyn suggested the use of password crackers for OpenOffice.org. These programs often use brute-force or dictionary-based attacks. I would not use such a closed-source programs from random, untrusted sources as suggested. Virus scanners do not find everything, so you still cannot trust the executable because ClamAV detects nothing.

Since LibreOffice is open source, I'd start with looking up what kind of encryption it uses. Ubuntu 12.04 ships with LibreOffice 3.5. According to http://wiki.documentfoundation.org/ReleaseNotes/3.5#Different_Encryption_Algorithm, it uses a 256-bits AES cipher.

This mailing list post also makes clear that the password is derived using PBKDF2 which means that brute-forcing will be much slower with a sufficient high iteration count.

Since .ods files are just Zip files, I tried to encrypt the file and extracted the contents. As expected, the contents of the document are encrypted and indistinguishable from random bytes. Of course there exist some unencrypted metadata, one of them being META-INF/manifest.xml. My example encrypted spreadsheet contained the following interested parts:

<manifest:encryption-data manifest:checksum-type="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0#sha256-1k" manifest:checksum="48KzqP1PL7Wu/YTtHzlN0buJeUmigGT247dZ6Wrj10s=">
<manifest:algorithm manifest:algorithm-name="http://www.w3.org/2001/04/xmlenc#aes256-cbc" manifest:initialisation-vector="82mrg52Yifh1iIye5W0xuw=="/>
<manifest:key-derivation manifest:key-derivation-name="PBKDF2" manifest:key-size="32" manifest:iteration-count="1024" manifest:salt="hUZrwD1BWkODYVklZiScqA=="/>
<manifest:start-key-generation manifest:start-key-generation-name="http://www.w3.org/2000/09/xmldsig#sha256" manifest:key-size="32"/>

From that we can learn that LibreOffice uses a SHA256 hashing algorithm for checking data integrity, AES256 in CBC mode. The 32-byte password is derived from your password using PBKDF2 with 1024 iterations.

A paper on decrypting ODF files is available here, these contain nice information to craft your own brute-forcer but are probably not suitable for the average user.

As with most encryption products, password recovery is near impossible. I suggest:

  • If the file just contains bookkeeping for a week, just start over and do not waste time on decrypting the file.
  • Try to recall the password if you want to decrypt the file.
  • If you are going to use a brute-force program, do not use a random program found on the internet. Try to find an open-source program. If you only find closed-source programs, download it from a reliable source and ensure that it has good reviews (from several sources), put it through https://www.virustotal.com and check again that the program you are trying is legit.
share|improve this answer
    
Yeah, that technique is way better than mine. I hate giving a link to untrusted .exe files... would be awesome if we could merge answers :) –  MiJyn Nov 28 '12 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.