Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use python spyder Assignment Specifications You will be developing a python program that implements the two password cracking methods and allows the user to

Please use python spyder

Assignment Specifications You will be developing a python program that implements the two password cracking methods and allows the user to crack .zip (archive) files. The first task is to implement a driver loop that prompts the user for which file cracking method theyd like to use (brute force, dictionary, or both). After determining which method the user would like to use, call the respective function(s) and show the time each function took to run. The user should be able to quit by typing q. If the attack is both, do a dictionary attack first and do a brute force attack only if the dictionary attack failed. Your second task is to develop a brute force function that generates a strings containing a-z (all lowercase) of length 8 or less as the password to attempt (Hint: start small trying small passwords first). For example ,your string should start out with a, then b, then c, so on and so forth. When you get to z change the first character back to a and append another letter so your string becomes aa then ab. Once the password is cracked you should display the password to the user. Hint: see notes below about itertools. The third task is to then develop the dictionary function. After you have prompted for the name of the dictionary file and the target .zip file your function should go through every line (one password per line) and try opening the .zip file. If it opens successfully, then again, display the password to the user. If you try all the passwords in the source file, display an appropriate error message. Hint: remember to strip() the word read from the file before trying it as a password! The fourth and final task for this project is a research question. With this project we are providing you with two password protected .zip files.

On behalf of the Computer Science Department you have our full permission to attack these two specific files for demonstration and educational purposes only. Breaking into secure computer systems is illegal in the US. (most other countries have similar laws). Your research question is to find out what US federal law youre breaking if you decide to do this without permission. Your program should warn the user what the name of the law is, and what the maximum penalty is before prompting for input.

Assignment Notes You are also not allowed to use sets, or dictionaries. Divide-and-conquer is an important problem solving technique. In fact, inside of every challenging problem is a simpler problem trying to get out. Your challenge is to find those simpler problems and divide the problem into smaller pieces that you can conquer. Functions can assist in this approach. Hint: build the following functions one at a time and test each one before moving on to the next.

1. open_dict_file() function does not take in any arguments and should return a file pointer to the dictionary file. It should keep re-prompting the user if the file doesnt exist.

2. open_zip_file() function does not take in any arguments and should return a file pointer to the zip file. It should keep re-prompting the user if the file doesnt exist.

3. brute_force_attack(zip_file) function takes the zip file pointer as an argument. The brute force function will generate all the possibilities, and attempt them. It should output the correct password once found. If successful, return True, otherwise return False.

4. dictionary_attack(zip_file, dict_file) function takes the zip file pointer and dictionary file pointer as arguments. It should output the correct password once found or print an error message if not successful. If successful, return True, otherwise return False.

5. File reading and closing. The order of reading files is important for testing. When doing a dictionary or both attack, prompt for the dictionary file before prompting for zip file(s). Also, always close() all files after each crack; otherwise with the dictionary file you will start reading passwords where you left off rather than at the beginning.

6. Using the code we provide for you, display the time need to finish each function. This will allow the user to see the time needed to complete various attacks. (You should notice quite a difference between the two methods). Deliverables The deliverable for this assignment is the following file: proj06.py -- your source code solution Be sure to use the specified file name and to submit it for grading via the handin system before the project deadline Working with Archive (zip) Files To properly open zip files in python you need to import the zipfile module. To attempt extracting a password protected zip file, use zip_file = zipfile.ZipFile(filename) to first open the zip file, then apply your password to the opened zip file using zip_file.extractall(pwd=password.encode()) so you can extract all its members. The type of the variable password is string and encode() is a string method that you must apply to the password variable when used as an argument to extractall. Basically, you try to unzip the file using extractall: if it generates an error, the password didnt work; if it doesnt generate an error, the password succeeded. Therefore, you want to put the call to extractall within try-except. Unfortunately, a variety of errors get generated by extractall so you must use except with no error type specified (that is generally not good practice, but necessary in this case). Therefore, your except line is simply except: We provided two password protected zip files. One that can be cracked with the brute force method and one that can be cracked with the dictionary method.

Optional: If you would like to test your program with more than just our two zip files, here are instructions for creating a password protected zip file on Mac and Windows: Mac: http://osxdaily.com/2012/01/07/set-zip-password-mac-os-x/ Windows: (we recommend using the WinRar part of the turial) http://www.intowindows.com/how-to-create-zip-file-with-password-in-windows-78/

Note: when password protecting your own zip file, make sure your password is a-z, lowercase, and less than 8 characters long. Youre welcome to try longer passwords but the time required to break them will increase exponentially. Working with itertools Python has many, many useful modules and itertools is one that is useful in general and a major effort-savor for this project. To brute force passwords you want to try all permutations of characters. The itertools has a function named product that provides exactly that functionality. However, that function generates tuples of characters, e.g. ('a','b','c'), whereas we need a string, e.g. 'abc'. There is a string method named join that allows you to join characters together with a specified character between each one. For example, '-'.join(('a','b','c'))yields the string 'a-b-c', but we dont want any characters in between so we use an empty string as ''.join(('a','b','c'))to yield 'abc'. Experiment with these in the shell. For example, if we want to generate strings (passwords in this project) of length 3 from a string of characters 'abcdef' we use the following: from itertools import product for items in product('abcdef',repeat=3): print(''.join(items)) Working with time To determine time we use yet another module: time. To calculate the time it takes a function to run get the time before calling the function, call time again right after calling the function, and then take the difference and print. Use the time.process_time() function, e.g. to time the dictionary_attack function: start = time.process_time() dictionary_attack(zip_file, dict_file) end = time.process_time() Then take the difference, round to 4 decimal places and print. The time is in seconds and the individual values have no meaning other than that when you take the difference you get the time that the function took.

Sample Output (Note that all passwords are marked with Xs you are to figure them out. Also, the law and prison items are marked with Xs for the same reason.)

Test Case 1 Cracking zip files. Warning cracking passwords is illegal due to law XXXXX and has a prison term of XXXXX What type of cracking ('brute force','dictionary','both','q'): dictionary Dictionary Cracking Enter dictionary file name: rockyou.txt Enter zip file name: dictionary_attack.zip Dictionary password is XXXXXX Elapsed time (sec): 0.2016 What type of cracking ('brute force','dictionary', 'both', 'q'): q

Test Case 2 Cracking zip files. Warning cracking passwords is illegal due to law XXXXX and has a prison term of XXXXX What type of cracking ('brute force','dictionary','both','q'): brute force Brute Force Cracking Enter zip file name: brute_force.zip Brute force password is XXXXXX Elapsed time (sec): 3.0039 What type of cracking ('brute force','dictionary', 'both', 'q'): q

Test Case 3 Cracking zip files. Warning cracking passwords is illegal due to law XXXXX and has a prison term of XXXXX What type of cracking ('brute force','dictionary','both','q'): dictionary Dictionary Cracking Enter dictionary file name: xxx Enter dictionary file name: rockyou.txt Enter zip file name: xxxx Enter zip file name: yyyy Enter zip file name: dictionary_attack.zip Dictionary password is XXXXXX Elapsed time (sec): 0.1957 What type of cracking ('brute force','dictionary', 'both', 'q'): q

Test Case 4 Cracking zip files. Warning cracking passwords is illegal due to law XXXXX and has a prison term of XXXXX What type of cracking ('brute force','dictionary','both','q'): q

Test Case 5 (In Test Case 5 use the short dictionary and the brute_force.zip file so the dictionary attack fails and doesnt take forever to do soforcing the brute force attack to be needed.) Cracking zip files. Warning cracking passwords is illegal due to law XXXXX and has a prison term of XXXXX What type of cracking ('brute force','dictionary','both','q'): both Both Brute Force and Dictionary attack. Enter dictionary file name: short_dict.txt Enter zip file name: brute_force.zip No password found. Dictionary Elapsed time (sec): 0.0188 Brute force password is XXXXXX Brute Force Elapsed time (sec): 2.9494 What type of cracking ('brute force','dictionary', 'both', 'q'): both Both Brute Force and Dictionary attack. Enter dictionary file name: rockyou.txt Enter zip file name: dictionary_attack.zip Dictionary password is XXXXXX Dictionary Elapsed time (sec): 0.2314 What type of cracking ('brute force','dictionary', 'both', 'q'): q

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions