[GH-ISSUE #467] pkzip format fails on ChristmasGIFts.zip #186

Closed
opened 2026-10-14 02:55:33 +07:00 by bsakaguchi · 8 comments
Owner

Originally created by @magnumripper on GitHub (Jan 6, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/467

Originally assigned to: @jfoug on GitHub.

http://www.openwall.com/lists/john-users/2013/12/23/1
http://corkami.googlecode.com/files/ChristmasGIFts.zip

Solar: "I think zip2john might be confused by the very first entry in the .zip file being a directory, or it could be some other issue."

Originally created by @magnumripper on GitHub (Jan 6, 2014). Original GitHub issue: https://github.com/openwall/john/issues/467 Originally assigned to: @jfoug on GitHub. http://www.openwall.com/lists/john-users/2013/12/23/1 http://corkami.googlecode.com/files/ChristmasGIFts.zip Solar: "I think zip2john might be confused by the very first entry in the .zip file being a directory, or it could be some other issue."
bsakaguchi 2026-10-14 02:55:33 +07:00
Author
Owner

@magnumripper commented on GitHub (Jan 6, 2014):

Had a look. The directory entry is not a problem. Using -nm and/or -co does not seem to help but I do not know the correct password for the file.

<!-- gh-comment-id:31645637 --> @magnumripper commented on GitHub (Jan 6, 2014): Had a look. The directory entry is not a problem. Using -nm and/or -co does not seem to help but I do not know the correct password for the file.
Author
Owner

@magnumripper commented on GitHub (Jan 6, 2014):

  • default stores simple.exe, simple.pdf and simple.com, last one inline.
  • -co stores simple.com, simple.exe and simple.pdf
  • -nm stores macho.asm, elf.asm and and simple.com, last one inline.

Of all above, simple.com is stored, the rest are compressed.

I'm starting to think it's actually a bug (eg. false early reject) in the format, not in zip2john.

<!-- gh-comment-id:31647376 --> @magnumripper commented on GitHub (Jan 6, 2014): - default stores simple.exe, simple.pdf and simple.com, last one inline. - `-co` stores simple.com, simple.exe and simple.pdf - `-nm` stores macho.asm, elf.asm and and simple.com, last one inline. Of all above, simple.com is stored, the rest are compressed. I'm starting to think it's actually a bug (eg. false early reject) in the format, not in zip2john.
Author
Owner

@magnumripper commented on GitHub (Jan 6, 2014):

OK, password was 123456 (doh! How could I not try that!?)

Bug fixed in 829ea4c, maybe in a coarse way: Two early-rejection tests had to be disabled. Hopefully @jfoug can re-enable them after investigation and tuning.

<!-- gh-comment-id:31651781 --> @magnumripper commented on GitHub (Jan 6, 2014): OK, password was 123456 (doh! How could I not try that!?) Bug fixed in 829ea4c, maybe in a coarse way: Two early-rejection tests had to be disabled. Hopefully @jfoug can re-enable them after investigation and tuning.
Author
Owner

@jfoug commented on GitHub (Jun 11, 2014):

Looking into this issue again. I reopened it.

NOTE, the hash in question has 3 hashes in it. The 3rd is a 0x2a .com file, that is STORED. If you remove that hash, then pkzip detects the 123456 password just fine. SO, the logic appears to be in stored files. THAT MAKES SENSE, since we are not dealing with an implode stream. All of the quick out logic was for an implode stream. If certain bit patterns were seen there, then it could NOT be a valid stream. But for a stored object, this would not make sense (also a shrunk type, i.e. older zip, but I do not think those can be encrypted).

I will be continuing this, but it MAY be that we can re-enable, and simply change the zip2john to NOT insert stored blobs. The nice thing about stored blobs was that if it was a small one, then we could put the whole thing in the file, and 'know' that we had a good decode.

It has been so long since i worked on pkzip, I will have to dig in deeper, and simply remember what I did.

<!-- gh-comment-id:45806122 --> @jfoug commented on GitHub (Jun 11, 2014): Looking into this issue again. I reopened it. NOTE, the hash in question has 3 hashes in it. The 3rd is a 0x2a .com file, that is STORED. If you remove that hash, then pkzip detects the 123456 password just fine. SO, the logic appears to be in stored files. THAT MAKES SENSE, since we are not dealing with an implode stream. All of the quick out logic was for an implode stream. If certain bit patterns were seen there, then it could NOT be a valid stream. But for a stored object, this would not make sense (also a shrunk type, i.e. older zip, but I do not think those can be encrypted). I will be continuing this, but it MAY be that we can re-enable, and simply change the zip2john to NOT insert stored blobs. The nice thing about stored blobs was that if it was a small one, then we could put the whole thing in the file, and 'know' that we had a good decode. It has been so long since i worked on pkzip, I will have to dig in deeper, and simply remember what I did.
Author
Owner

@jfoug commented on GitHub (Jun 14, 2014):

814c81e fixes some of the issues. I moved the check for if((C&6)==6) bail_fail to after the detection of a stored file. Checking a byte like this in a stored file, can not be done. I also added ability to have 0 byte checksum test (the first test). There were 2 an 1. It looks like version 0x314 is made with 7z, and it looks like it does not use check sum detection. HOWEVER, the ChristmasGIFts.zip file was a 'normal' 0x14 version, and it did not use checksum test code either :( I added new switches to zip2john to allow forcing 0 bytes. Unfortunately, there is no way to know in advance, unless you are able to crack one of the .zip's in some set, and know the rest have been built that way. I do not have a work around at this time. It may be that there is some hardening project for some *nix distro, that has removed the checksum validation, and that is what ChristmasGIFts.zip was made with. I would like to be able to auto-detect this, and set a 0 byte amount to test for checksums, but I do not know how to do it at this time.

The code does work better, BUT it still is not fully correct. I added ability to choose a single file (in zip2john), to force set 2 byte or 0 byte checksum logic, and a few other things. With that logic in there, I was able to crack every file within ChristmasGIFts.zip EXCEPT bin/simple.zip That one still has inflate problems within the code. It trips the if((C&6)==6) bail_fail, but even if you comment that out, it still fails, falling down into the fixed lookup table section, and failing. I need to dig into the code, and also look at zip dumps for this non-encrypted, to just SEE wtf this zip-blob is doing. I have not started on that yet.

But I did want to get these fixes out there. They get past a lot of the issues. Even with the original code (commented out), this failure would have been there (the bin/simple.zip failing). But these quick out tests are back. I just have to figure out HOW to detect when checksum tests are not used.

<!-- gh-comment-id:46088904 --> @jfoug commented on GitHub (Jun 14, 2014): 814c81e fixes some of the issues. I moved the check for if((C&6)==6) bail_fail to after the detection of a stored file. Checking a byte like this in a stored file, can not be done. I also added ability to have 0 byte checksum test (the first test). There were 2 an 1. It looks like version 0x314 is made with 7z, and it looks like it does not use check sum detection. HOWEVER, the ChristmasGIFts.zip file was a 'normal' 0x14 version, and it did not use checksum test code either :( I added new switches to zip2john to allow forcing 0 bytes. Unfortunately, there is no way to know in advance, unless you are able to crack one of the .zip's in some set, and know the rest have been built that way. I do not have a work around at this time. It may be that there is some hardening project for some *nix distro, that has removed the checksum validation, and that is what ChristmasGIFts.zip was made with. I would like to be able to auto-detect this, and set a 0 byte amount to test for checksums, but I do not know how to do it at this time. The code does work better, BUT it still is not fully correct. I added ability to choose a single file (in zip2john), to force set 2 byte or 0 byte checksum logic, and a few other things. With that logic in there, I was able to crack every file within ChristmasGIFts.zip EXCEPT bin/simple.zip That one still has inflate problems within the code. It trips the if((C&6)==6) bail_fail, but even if you comment that out, it still fails, falling down into the fixed lookup table section, and failing. I need to dig into the code, and also look at zip dumps for this non-encrypted, to just SEE wtf this zip-blob is doing. I have not started on that yet. But I did want to get these fixes out there. They get past a lot of the issues. Even with the original code (commented out), this failure would have been there (the bin/simple.zip failing). But these quick out tests are back. I just have to figure out HOW to detect when checksum tests are not used.
Author
Owner

@jfoug commented on GitHub (Jun 15, 2014):

Found all problems.

  1. ChristmasGIFts.zip was a 2 byte checksum zip, but the checksum came from the timestamp, not from the crc. Not sure how to do this automatically.
  2. The if ((C & 6)==6) goto fail had to move until after the decompress of a stored object.
  3. the file bin/simple.zip when decompressed was less than 128 bytes. 128 bytes was a buffer used to decrypt 'enough' data to check for a signature. It is also used as the first 'quick' unzip check. We simply checked that quick unzip check for Z_OK. Well, if the full inflated blob was 128 bytes or less, then Z_OK was not returned. Z_END_OF_STREAM was returned, BUT it is valid, as long as the decryption size was the same as the zip stream decryted count. There is now a check in for that.

When I get these changes tested, pkzip will have the quick checks BACK in, AND the zip2john has many more flags for force creating different things (singleton files, 2 byte, 0 byte check sums, etc, and forcing getting the checksum data from timestamp). NOW the problem is when presented with an unknown zip file, where you do not know where it was created. zip2john likely will not have enough smarts to always create the zip data properly.

What we MAY have to do, is to change the structure of the .zip blob. We may have to put out the timestamp AND crc blob as a checksum, and simply check both of them. If either match, we assume we have a checksum match. BUT this will change the signature of the .zip blob. I guess I could do a pkzipv2 signature, or something like that, and have zip_fmt handle both types?

I was going to close this bug out, but now I think I have to leave it for a while :(

<!-- gh-comment-id:46114779 --> @jfoug commented on GitHub (Jun 15, 2014): Found all problems. 1. ChristmasGIFts.zip was a 2 byte checksum zip, but the checksum came from the timestamp, not from the crc. Not sure how to do this automatically. 2. The if ((C & 6)==6) goto fail had to move until after the decompress of a stored object. 3. the file bin/simple.zip when decompressed was less than 128 bytes. 128 bytes was a buffer used to decrypt 'enough' data to check for a signature. It is also used as the first 'quick' unzip check. We simply checked that quick unzip check for Z_OK. Well, if the full inflated blob was 128 bytes or less, then Z_OK was not returned. Z_END_OF_STREAM was returned, BUT it is valid, as long as the decryption size was the same as the zip stream decryted count. There is now a check in for that. When I get these changes tested, pkzip will have the quick checks BACK in, AND the zip2john has many more flags for force creating different things (singleton files, 2 byte, 0 byte check sums, etc, and forcing getting the checksum data from timestamp). NOW the problem is when presented with an unknown zip file, where you do not know where it was created. zip2john likely will not have enough smarts to always create the zip data properly. What we MAY have to do, is to change the structure of the .zip blob. We may have to put out the timestamp AND crc blob as a checksum, and simply check both of them. If either match, we assume we have a checksum match. BUT this will change the signature of the .zip blob. I guess I could do a $pkzipv2$ signature, or something like that, and have zip_fmt handle both types? I was going to close this bug out, but now I think I have to leave it for a while :(
Author
Owner

@jfoug commented on GitHub (Jun 15, 2014):

Speed went from:

$ ../run/john -test=5 -form=pkzip
Benchmarking: PKZIP [32/32]... DONE
Many salts: 1688K c/s real, 1688K c/s virtual
Only one salt: 1825K c/s real, 1841K c/s virtual

to

$ ../run/john -test=5 -form=pkzip
Benchmarking: PKZIP [32/32]... DONE
Many salts: 5941K c/s real, 5957K c/s virtual
Only one salt: 4160K c/s real, 4160K c/s virtual

That checksum test is huge. It eliminates 255 out of 256 (or 65535 out of 65536 for 2 byte checksums). The 2nd test eliminated 1/2 of anything left over. Those 2 tests are the big ones for speed.

<!-- gh-comment-id:46115073 --> @jfoug commented on GitHub (Jun 15, 2014): Speed went from: $ ../run/john -test=5 -form=pkzip Benchmarking: PKZIP [32/32]... DONE Many salts: 1688K c/s real, 1688K c/s virtual Only one salt: 1825K c/s real, 1841K c/s virtual to $ ../run/john -test=5 -form=pkzip Benchmarking: PKZIP [32/32]... DONE Many salts: 5941K c/s real, 5957K c/s virtual Only one salt: 4160K c/s real, 4160K c/s virtual That checksum test is huge. It eliminates 255 out of 256 (or 65535 out of 65536 for 2 byte checksums). The 2nd test eliminated 1/2 of anything left over. Those 2 tests are the big ones for speed.
Author
Owner

@jfoug commented on GitHub (Jun 15, 2014):

b7a49ae should fix it all. There is only 1 pkzip2 item within our test data, and it is from the ChristmasGIFts.zip data. I used 2 byte checksum, since that file IS 2 byte checksum. It was simply using the timestamp data, and NOT the crc.

Within john2zip, I removed a lot of the extra options (not needed). I did keep -f2 (force 2 byte). Now zip2john simply makes pkzip2 hashes, which contain both type of checksums (top of crc32 and the timestamp). pkzip_fmt will test them both.

pkzip_fmt still uses the pkzip hashes. In that case, it will simply copy the checksum data into checksum2, so that the if logic will simply test the same value twice.

This bug is now close, as far as I can tell.

<!-- gh-comment-id:46116526 --> @jfoug commented on GitHub (Jun 15, 2014): b7a49ae should fix it all. There is only 1 $pkzip2$ item within our test data, and it is from the ChristmasGIFts.zip data. I used 2 byte checksum, since that file IS 2 byte checksum. It was simply using the timestamp data, and NOT the crc. Within john2zip, I removed a lot of the extra options (not needed). I did keep -f2 (force 2 byte). Now zip2john simply makes $pkzip2$ hashes, which contain both type of checksums (top of crc32 and the timestamp). pkzip_fmt will test them both. pkzip_fmt still uses the $pkzip$ hashes. In that case, it will simply copy the checksum data into checksum2, so that the if logic will simply test the same value twice. This bug is now close, as far as I can tell.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#186
No description provided.