-
-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to conduct an attack correctly? #49
Comments
? |
I use the command: bkcrack -C plain001.zip -c plain001.txt -P plain.zip -p plain.txt -d end.txt But I don't get the expected result. |
See if there is more keys... |
It always turns out something like this: TOP SECRET! сњМ_и эајЂџвxћлкF�ѕ |
And that "TOP SECRET! " text is at the top of that encrypted file? Try with this. It has it at the start of the file. |
Yes. Password from the archive: 1234554321
bkcrack -C plain007.zip -c plain007.txt -k 28bfec92 767080fe 8c0f6a93 -d end01.txt This vector came up. Following my example, the keys were found, but they did not fit. :( |
The 7-zip says its method to be "ZipCrypto Deflate:Maximum". Maybe it has something to do with it that it doesn't crack? @kimci86 I had a case that was packed a bit exotic way. There was five byte header in files when extracted with bkcrack. |
So you also made the plain.zip with the same program and compression? |
|
There might compression difference anyway. Seems that small files are just stored by these programs. ---> Try using bigger files. |
|
Okay, tested TC Android version. Uses that Deflate:Maximum even when Fastest is used. Used bigger files while at it. No keys. Enhanced deflate The "enhanced deflate" method is similar to the original deflate but operates on larger chunks of data at a time, often resulting in improved compression. It can be particularly useful for compressing large files containing large amounts of highly compressible data such as large text files and text-based database files. Earlier versions of WinZip referred to this compression method as Maximum (enhanced deflate). |
Here it's said that Deflate64 and Enhanced Deflate is the same. 7zip though sees them differently. Flagged your file as Deflate64 but in vain. So, Total Commander probably compress files somehow differently depending if encrypted or not... Maybe file size matters too??? Your file's keys work as expected, so it is like others - besides that TC's oddity. |
Hello! Sorry for the delay. Let us go through this example (assuming a Unix environment).
Inspect metadata by running
The difficult part for a successful attack is to have correct plaintext. You known in your case that this text file So in this case, we can just compress "TOP SECRET! ", for example with the script
So we have 12 bytes of compressed known plaintext. 12 bytes is the minimum and there might be some collisions, so an exhaustive search is recommended. Now, a trick: the encryption header prepended to the compressed data before encryption is not completely random. The last byte at least is set to the CRC's most significant byte (or a timestamp in some cases), also available in the entry's metadata. It is used to quickly check if a password seems correct in regular zip file managers. We can include it in our known plaintext. So we now have 13 bytes of known plaintext. There should not be collisions and the exhaustive search is not needed, which saves time.
(Update to version 1.3.3 or higher to do this because there was a small bug with negative offsets.) With some patience, it gives a solution
If the password is also wanted, it can be recovered quickly because it is short. The conclusion for me is that I should write more documentation on how to use bkcrack :) |
This is most instructive. That -p value is quite confusing. Can be plain text, deflated plain text or zipped plain text. And somewhere there was that -p can be also just a line of text -p "The quick brown fox jumps over the lazy dog". I don't understand why then zipped one doesn't work if deflated one does. You could remove that end of data marker from that deflate.py . Or add removing it if that's needed. This could be in the beginning of the readme.md. And then if necessary how use them. usage: bkcrack [options]Mandatory:
-k X Y Z Internal password representation as three 32-bits integers Optional: -P plainzip Zip archive containing plainfile -e Exhaustively try all the keys remaining after Z reduction -d decipheredfile File to write the deciphered text (requires -c) -r length charset Try to recover the password up to the given length using
|
For small files without patterns, compression makes files larger so zippers prefer not to use compression. Both 7zip and Info-ZIP's |
So it does compress like deflate.py so it should work really?? |
Yes making an archive with Total commander is ok as it uses deflate compression even on a small file. You still need to ignore the last two bytes though with |
Thank you very much for the answer. What does this mean: "-1 eb"? A byte is added to plain text? At the beginning, at the end? |
EB is one byte written in hexadecimal. It comes from the CRC of the encrypted entry which is EBF8553B. |
Thanks. I see. |
You need at least 8 more. How many continuously it was? It's written somewhere. |
8 contiguous bytes are required to generate 2 ^ 32 internal password representation candidates, and 4 more bytes (contiguous or not) are used to filter those candidates to have only one solution on average. Even if filtering was done in some other way, the bare minimum is 8 contiguous bytes. |
Hello. |
You need to provide the offset. If you do not know the offset, you can try several possible values, starting with what seems the most likely, until you try with the right one. It might take a long time though. |
That's only viable if it's stored. If it's deflated I'd say it's virtually impossible. |
If password is short and amount of offsets is reasonable, I cannot see why it's not possible. |
The offset is needed to recover the internal keys, not to recover the password. The password complexity has no impact on this part. The time needed for an attack if the offset is not known would depend of the contiguous plaintext length (the longer, the better) and the number of offsets tried before finding the right one (the lower, the better). In addition, if plaintext has to be compressed, not knowing the uncompressed plaintext offset makes it very difficult to get the corresponding compressed plaintext. It is already hard to guess how deflate compression behaves when only a small part of the uncompressed plaintext is known. Not knowing where the uncompressed plaintext starts makes it harder because symbols are not necessarily byte-aligned. |
Yes, the keys. And keys for passwords between 1 to 12 are tested in seconds. |
Exactly. We'd even have to be able to give the offset ( |
I close this as I understand you have no more questions. Feel free to reopen or open a new issue otherwise. Thank you all for your contribution to this discussion. |
Hello. What do you have in the file "compressed", what bytes? |
I got those bytes:
What do you mean? |
|
Hello. |
Compressing Regarding the CRC value 922FF13B, I don't see where it comes from. The archive metadata tells a CRC value of 7814e216. So this is how you can run the attack on your example archive:
After a couple of minutes, it gives the internal password representation. Then, getting the password:
Gives the password |
Works. Thanks again. |
Can I use the program to stream encrypted data? |
Sorry, I do not understand your question. Could you elaborate? |
If I do not have an archive, but only part of it in the form of encrypted text. |
If you have ciphertext in a file on its own (including 12 bytes of encryption header), you can pass it with the -c argument without specifying an archive with -C. For example, below is the result of calling
I am curious to know how you end up having encrypted data without a ZIP archive. Could you explain? Is it a scenario that bkcrack could better support? |
Hello. I seem to have misunderstood you again. I saved the highlighted binary data to a secret.txt file. And used the command: |
I don't know, that command works for me. |
Yes, it worked. I didn't wait. But why is searching slower? Option 1 (zip): Option 2 (stream): |
Great. The difference is that, when loading ciphertext from a ZIP archive, bkcrack automatically loads one additional byte of plaintext which is derived from ZIP metadata. (This can be disabled with |
Thanks for the answer! What open byte are you talking about? Can I include it in the stream? |
The check byte is the last byte of the file's encryption header, a chunk of 12 bytes which is put right before actual compressed data before being encrypted. It is usually the most significant byte of the original file's CRC. Depending on some flag in ZIP metadata, the check byte can be a byte of the file's last modification time instead. When loading data from a ZIP archive, bkcrack loads the check byte automatically. The check byte can be passed manually as additional plaintext at offset -1 with But if we did not have the ZIP archive, then we could not derive the check byte from encrypted data alone. So I don't think it is ever needed to pass the check byte manually. Letting bkcrack get it from the ZIP archive is simpler. |
Thank you so much for your patience and replies.
|
In this case, your plain uncompressed data starts like this:
If encrypted data was not compressed, this command would work:
If encrypted data was compressed, this will not work and we need to guess how known data was compressed. Let's try by making the following assumptions on the original file:
Assumption 1 means deflate compression probably uses fixed Huffman codes when compressing the original file. Those fixed Huffman codes are defined by deflate format specification and do not depend on input data (which is convenient for us). This is how I would do it: compress a string that has the known bytes where we expect and characters to fill up unknown bytes without repetition.
Running infgen confirms the compressed string we just created uses fixed Huffman codes and does not have pointers to duplicated strings.
Let's have a look at the compressed bits:
With some knowledge about deflate compression, we can find the bytes that correspond to our known bytes. So our known data corresponds to bytes at offset 6, 7, and 13 to 21 (respectively 6, 7, d and 15 in hexadecimal) in the compressed file. Conclusion: this command should work, if our assumptions are correct and if I did not make any mistake.
|
Thank you so much!
|
If dynamic Huffman codes are used, the compressed stream starts with a Huffman tree, itself encoded in a compact way (section 3.2.7. of RFC1951 - DEFLATE Compressed Data Format Specification). This Huffman tree is a statistical model built from characters frequencies. |
As far as I understand, your questions have been answered so I close this. Feel free to reopen or create a new issue if you have more questions or feedback. |
Hello.
How to conduct an attack correctly? Plaintext: "TOP SECRET! ". There is a space at the end of the text.
Archive ZIP: UEsDBBQAAwAIAM8EZFM7VfjrKwAAAB0AAAAMAAAAcGxhaW4wMDEudHh04Tlvb+niDagMDzYfQkqGINYMQ4yRlVDUg7pRSncttBoiwDmBAbNambU1HlBLAQIUABQAAwAIAM8EZFM7VfjrKwAAAB0AAAAMAAAAAAAAAAEAIAAAAAAAAABwbGFpbjAwMS50eHRQSwUGAAAAAAEAAQA6AAAAVQAAAAAA
Thanks.
The text was updated successfully, but these errors were encountered: