Help Fixing Code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help Fixing Code (/thread-26753.html) |
Help Fixing Code - kianwalters05 - May-12-2020 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. 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.')
RE: Help Fixing Code - buran - May-12-2020 Post your code here on the forum - in python tags, full traceback - in error tags. See BBcode help for more info. RE: Help Fixing Code - snippsat - May-12-2020 extractFile need pwd paramenter to be bytes not string.Can do it in the function call. if extractFile(zip_file, password.encode()):The basic is. >>> s = 'Secret' >>> s 'Secret' >>> type(s) <class 'str'> >>> >>> s_byte = s.encode() #Same as s.encode('utf-8') >>> s_byte b'Secret' >>> type(s_byte) <class 'bytes'> RE: Help Fixing Code - kianwalters05 - May-12-2020 (May-12-2020, 11:26 AM)buran Wrote: Post your code here on the forum - in python tags, full traceback - in error tags. Should i do it in a separate post or in a reply? RE: Help Fixing Code - buran - May-12-2020 (May-12-2020, 11:58 AM)kianwalters05 Wrote: Should i do it in a separate post or in a reply?I edited your post to include the code and error RE: Help Fixing Code - kianwalters05 - May-12-2020 (May-12-2020, 12:05 PM)buran Wrote:Wasnt showing up for me, thanks(May-12-2020, 11:58 AM)kianwalters05 Wrote: Should i do it in a separate post or in a reply?I edited your post to include the code and error |