Executing brute-force attacks for ZIP files
In this section, we will analyze how we can create ZIP files with a password and execute a brute-force dictionary process to obtain the password to extract the contents of the ZIP file.
Handling ZIP files in Python
ZIP is an archive file format that supports lossless data compression. By lossless compression, we mean that the compression algorithm allows the original data to be perfectly reconstructed from the compressed data. So, a ZIP file is a single file containing one or more compressed files, offering an ideal way to make large files smaller and keep related files together.
To create a new file, we can use an instance of the ZipFile
class in write mode w
, and to add files, we can use the write()
method. The following script can be found in the create_zip_file.py
file inside the zipfile
folder:
import os
import zipfile
zf = zipfile.ZipFile("zipfile.zip", "w")
for dirname, subdirs, files in os.walk...