Review past

Python automatically monitors Github projects and opens web pages

Python implements automatic file categorization

The Python implementation helps you select a bicolor ball number

Python to change bing images to Desktop wallpaper every day

Python implements batch watermarking

preface

Today we will use python script to decrypt the zip package. Directly open the whole ~

Results show

The process is as follows:

  1. Create a password dictionary (common passwords)

  2. Try using each password to extract the file

  3. Decompression success, out of the loop

Password dictionary

For example, a six-digit password “050825” is now purely numeric.

You can iterate from “000000” to “999999”, save all the results to TXT file.

This disadvantage is more rigid, can only be 6 digits, another is more memory.

So, someone wrote a dictionary generator, and all you need to do is pass in two parameters: “dictionary elements” and “length list of passwords.”

For example, for a purely numeric “050825”, you pass in the following arguments:

  • [0,1,2,3,4,5,6,7,8,9] there are only nine numbers
  • [6], the length of the password

In this way, you can get the Python generator for the password you want. As we know, generators are memory free.

If numbers aren’t good enough, for example, some passwords are strings. Consider adding “A-z” and “a-z” to the first parameter.

Zipfile Decompresses the file

The zipfile module comes with Python and is used to read, write, append, and decompress zip files.

The extractall() method of the ZipFile object is mainly used for “decompression”

The Extractall (path=None, members=None, PWD =None) method takes three main arguments.

Let’s look at what each parameter means:

  • Path Specifies the storage location of the decompressed file

  • Members (optional) Specifies the file in the Zip file to extract. This file name must be a subset of the list returned by the namelist() method

  • PWD Specifies the password to decompress the Zip file (utF-8).

Source:

import zipfile 
try:
    with zipfile.ZipFile('test.zip') as zFile:     
        Create a ZipFile object
        Unzip the file
        zFile.extractall(path='/',pwd=b'1234')
        print('Unzip successful! ')
except:
    print('Decompression failed')
Copy the code

Progress bar visualization

The progress bar was created using the TQDM extension library. See the link below to create a visual progress bar in Python

The TQDM in the code takes two arguments:

  • 1. Password iterators
  • 2. Total number of passwords
for pwd in tqdm(chain.from_iterable(all_passwd(dictionaries, maxlen) for maxlen in lengths), total=total):
    if extract(zfile, pwd):    Remember that extract returns a bool
        break
Copy the code

Here are the results of the hack:

5% | ▌ |50691/1000000 [00: 04 "01:23.11389.24it/s]
Password is: 050825
bingo
Copy the code

4s finishes the fight…

This is the end of the article. Thank you for watching

To thank you readers, I’d like to share some of my recent programming favorites to give back to each and every one of you in the hope that they can help you.

Dry goods mainly include:

① Over 2000 Python ebooks (both mainstream and classic books should be available)

②Python Standard Library (Most Complete Chinese version)

③ project source code (forty or fifty interesting and classic practice projects and source code)

④Python basic introduction, crawler, Web development, big data analysis video (suitable for small white learning)

⑤ A Roadmap for Learning Python

⑥ Two days of Python crawler boot camp live access

All done ~ see personal profile or private letter for complete source code.