I'm doing a cybersecurity course and one of the levels requires editing a python script to brute force a .zip file. I edited some very easy errors like adding parenthesis etc. But when I run the code I get these errors and I dont know how to fix them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import zipfile import itertools import time # Function for extracting zip files to test if the password works! def extractFile(zip_file, password): try : zip_file.extractall(pwd = password) return True except KeyboardInterrupt: exit( 0 ) # Main code starts here... # The file name of the zip file. zipfilename = 'planz.zip' # The first part of the password. We know this for sure! first_half_password = 'Super' # We don't know what characters they add afterwards... # This is case sensitive! alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' zip_file = zipfile.ZipFile(zipfilename) # We know they always have 3 characters after Super... # For every possible combination of 3 letters from alphabet... for c in itertools.product(alphabet, repeat = 3 ): # Slowing it down on purpose to make it work better with the web terminal # Remove at your peril time.sleep( 0.001 ) # Add the three letters to the first half of the password. password = first_half_password + ''.join(c) # Try to extract the file. print ( "Trying: %s" % password) # If the file was extracted, you found the right password. if extractFile(zip_file, password): print ( '*' * 20 ) print ( 'Password found: %s' % password) print ( 'Files extracted...' ) exit( 0 ) # If no password was found by the end, let us know! print ( 'Password not found.' ) |
Error:Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:\Users\kianw\Desktop\zipcrack.py =================
Trying: Superaaa
Traceback (most recent call last):
File "C:\Users\kianw\Desktop\zipcrack.py", line 33, in <module>
if extractFile(zip_file, password):
File "C:\Users\kianw\Desktop\zipcrack.py", line 8, in extractFile
zip_file.extractall(pwd=password)
File "C:\Users\kianw\AppData\Local\Programs\Python\Python38\lib\zipfile.py", line 1647, in extractall
self._extract_member(zipinfo, path, pwd)
File "C:\Users\kianw\AppData\Local\Programs\Python\Python38\lib\zipfile.py", line 1700, in _extract_member
with self.open(member, pwd=pwd) as source, \
File "C:\Users\kianw\AppData\Local\Programs\Python\Python38\lib\zipfile.py", line 1497, in open
raise TypeError("pwd: expected bytes, got %s" % type(pwd).__name__)
TypeError: pwd: expected bytes, got str
>>>