Example of using Python brute force to crack zip file password method

Source: Internet
Author: User
Tags md5 encryption zipinfo
Through the python built-in zipfile module to extract the zip file, add material to complete password cracking. This article mainly introduces the use of Python brute force to crack the zip file password of the relevant information, the text through the sample code introduced in very detailed, to everyone's study or work has a certain reference learning value, hope to help everyone.

Objective

The ZipFile module is used for compression and decompression of zip format encoding, there are two very important classes in ZipFile, respectively ZipFile and Zipinfo, in the vast majority of cases, we only need to use these two class. ZipFile is the primary class that is used to create and read Zip files while zipinfo is storing information for each file in a zip file.

For example, to read a Python ZipFile module, this assumes that filename is the path to a file:


Import ZipFile z = zipfile. ZipFile (filename, ' r ') for I in Z.infolist (): Print i.file_size, I.header_offset

This uses z.infolist (), which returns information about all the files in the package, which is a list of zipinfo. A Zipinfo object contains information about a file within a compressed package, which is more commonly used as filename, file_size, Header_offset, respectively, file name, size, and file data offset in the compressed package.

Preparation phase

First you need a zip file, and give it a password, look like this


And then you get a zip file with your own password, okay, that's it.

Brute Force hack

First we know what is a brute force, in fact, simple and brutal point, that is, by round the way, we must all know MD5 encryption, then MD5 is irreversible, that online those so-called MD5 decrypt the site is how to do, in fact, is also a violent way of cracking.

For a chestnut, you encrypt a string by MD5 the str="abc" result is "3cd24fb0d6963f7d" such a long string of people must not understand, MD5 decryption site How to do, they own nothing to do when the time began to blind try, the AA/CC/BB/ABC What are beginning to use MD5 encryption again, stored in their own database, when you go to query, they will be based on the "3cd24fb0d6963f7d" you provide in the database, if the coincidence can not find, most of the case your encryption string is slightly more complex point can not find, This is called MD5 decryption, which is the brute force.

On the Code


Import ZipFile #导入模块, it is to do compression and decompression password= "123" #我们设定的口令zfile = ZipFile. ZipFile ("Test.zip") #要解压缩的压缩包zfile. Extractall (path= ' c:\\users\\administrator\\desktop\\ ', members=zfile.namelist (), Pwd=password.encode (' Utf-8 ') #进行解压缩操作, path for output

We run the above code (of course, your encryption password to 123), you will find on the desktop has been test.zip extracted out, perfect ending, not a brute force crack, I know the password also to crack what useful, don't worry, continue to look down


Import ZipFile zfile = ZipFile. ZipFile ("Test.zip") passfile=open (' pwd.txt ') #读取你设定的密码文件for line in Passfile.readlines ():  try:    password = Line.strip (' \ n ')    zfile.extractall (path= ' c:\\users\\administrator\\desktop\\ ', members=zfile.namelist (), pwd= Password.encode (' Utf-8 '))    break  except:    print ("Wrong Again")

Pwd.txt inside the contents are as follows


1223abcaaa123

OK, this completes the zip file password of the brute force, in fact, just very clever use of the try except abnormal mechanism, when the normal normal password decompression, decompression failure will report abnormal, try it out

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.