In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you how to use Python to solve simple zip file decompression password, I hope you have something to gain after reading this article, let's discuss it together!
file creation
First, the test file is test.txt (containing only one line of text). After compression, the file is test.zip. The compression password is 2340. After compression, delete the txt file under the directory.
Note that traditional encryption is checked in the above picture.
pure numeric cipher
A password that does not begin with a zero. A zero begins with a combination of letters. The principle is that when the zipfile module decompresses the compressed file, once the password is incorrect, the program will terminate. In the try statement, only the successfully decompressed password will be executed to the statement after the extract function call.
Code:
import zipfileimport timeimport threadingstartTime = time.time()#Determine whether the thread needs to terminate flag = True def extract(password, file): try: password = str(password) file.extractall(path='. ', pwd=password.encode('utf-8')) print("the password is {}".format(password)) nowTime = time.time() print("spend time is {}".format(nowTime-startTime)) global flag #Successfully decompresses the remaining threads and terminates flag = False except Exception as e: print(e) def do_main(): zfile = zipfile.ZipFile("test.zip", 'r') #Start trying for number in range(1, 9999): if flag is True: t = threading.Thread(target=extract, args=(number, zfile)) t.start() t.join() if __name__ == '__main__': do_main()
Obviously, the decompression succeeded. It is mentioned that this method of encoding passwords only applies to traditional zip encryption. Winrar has a new default encryption method that is not allowed.
alphanumeric cipher
There are too many password combinations in this case. In order to prevent memory overflow, iterators are used instead. This situation takes a long time and can be idle hanging scripts. Here the file is compressed again and the password is python.
import zipfileimport randomimport timeimport sys class MyIterator(): #Unit Character Set letters = 'abcdefghijklmnopqrstuvwxyz012345678' min_digits = 0 max_digits = 0 def __init__(self, min_digits, max_digits): #When instantiating an object, give the password number range, usually 4 to 10 digits if min_digits < max_digits: self.min_digits = min_digits self.max_digits = max_digits else: self.min_digits = max_digits self.max_digits = min_digits #iterator access definition def __iter__(self): return self def __next__(self): rst = str() for item in range(0, random.randrange(self.min_digits, self.max_digits+1)): rst += random.choice(MyIterator.letters) return rst def extract(): start_time = time.time() zfile = zipfile.ZipFile("test.zip") for p in MyIterator(5, 6): try: zfile.extractall(path=". ", pwd=str(p).encode('utf-8')) print("the password is {}".format(p)) now_time = time.time() print("spend time is {}".format(now_time-start_time)) sys.exit(0) except Exception as e: pass if __name__ == '__main__': extract()
There are many combinations of character sequences and you need to wait.
After reading this article, I believe you have a certain understanding of "how to use Python to solve simple zip file decompression password". If you want to know more about it, please pay attention to the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.