I am trying to build a small CommandoLine-app that can bruteforce a password for an encrypted Zip. My approach is to generate passwords and then try them using CheckZipPassword(). However I get this error:
Unhandled Exception: Ionic.Zlib.ZlibException: Bad state (invalid distance code)
at Ionic.Zlib.InflateManager.Inflate(FlushType flush)
at Ionic.Zlib.ZlibCodec.Inflate(FlushType flush)
at Ionic.Zlib.ZlibBaseStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at Ionic.Zlib.DeflateStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at Ionic.Crc.CrcCalculatorStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at Ionic.Zip.ZipEntry.ExtractAndCrc(Stream archiveStream, Stream targetOutput, Int16 compressionMethod, Int64 compressedFileDataSize, Int64 uncompressedSize)
at Ionic.Zip.ZipEntry.ExtractToStream(Stream archiveStream, Stream output, EncryptionAlgorithm encryptionAlgorithm, Int32 expectedCrc32)
at Ionic.Zip.ZipEntry.InternalExtractToStream(Stream outStream, String password, ZipContainer zipContainer, ZipEntrySource zipEntrySource, String fileName)
at Ionic.Zip.ZipFile.CheckZipPassword(String zipFileName, String password)
at SuperZipCracker.Program.Main(String[] args) in C:\..\Program.cs:line 54
This is the code where I check the password:
for (int j = 0; j < 100; j++)
{
var pwString = pw.GenerateString();
Console.Write($"{pwString}\n");
var bingo = ZipFile.CheckZipPassword(pathFdf, pwString);
if (bingo != false)
{
finalPassword = pwString;
}
}
Line 54 is "var bingo...".
If I run this loop less than 93 times i terminates fine. But at j < 93 it crashes with the shown exception, always the same place. The password tested in that loop is "cde". I don't know if this value has anything to do with it, I might be misleading myself.
This is the password generator is basically this one in the answer here.
What am I doing wrong?