Hacking The Fender
Hacking The Fender
The Fender,a notorious computer hacker and general villain of the people,
has compromised several top-secret passwords including your own. Your
mission, should you choose to accept it, is threefold. You must acquire
access to The Fender‘s systems, you must update his "passwords.txt" file to
scramble the secret data. The last thing you need to do is add the signature
of Slash Null, a different hacker whose nefarious deeds could be very
conveniently halted by The Fender if they viewed Slash Null as a threat.
If you get stuck during this project, check out the project walkthrough
video which can be found at the bottom of the page after the final step of
the project.
Tasks
0/20Complete
Mark the tasks as complete by checking them off
Reading In The Passwords
1.
Are you there? We’ve opened up a communications link to The Fender‘s
secret computer. We need you to write a program that will read in the
compromised usernames and passwords that are stored in a file
called "passwords.csv".
First import the CSV module, since we’ll be needing it to parse the data.
Hint
You can import the CSV module using the following syntax:
import csv
2.
We need to create a list of users whose passwords have been
compromised, create a new list and save it to the variable compromised_users.
Hint
Creating a new list for a variable called new_list with the following syntax:
new_list = []
3.
Next we’ll need you to open up the file itself. Store it in a file object
called password_file.
Hint
Use with...as syntax to open a file, remember it begins an indented block:
parsed_csv = csv.DictReader(file_object)
5.
Now we’ll want to iterate through each of the lines in the CSV.
Create a for loop and save each row of the CSV into the temporary
variable password_row.
6.
Inside your for loop, print out password_row['Username']. This is the username
of the person whose password was compromised.
my_list.append(my_dict['Key'])
8.
Exit out of your with block for "passwords.csv". We have all the data we need
from that file.
Start a new with block, opening a file called compromised_users.txt. Open this
file in write-mode, saving the file object as compromised_user_file.
Hint
You can open a file in write-mode by passing "w" as an argument to open().
12.
Your boss needs to know that you were successful in retrieving that
compromised data. We’ll need to send him an encoded message over the
internet. Let’s use JSON to do that.
new_dict = {
'key1': 'val1',
'key2': 'val2'
}
15.
Write out boss_message_dict to boss_message using json.dump().
Hint
json.dump() takes two arguments: a Python data object (like a dictionary or
an array) an a file object to write the resulting JSON to.
json.dump(dict_obj, file_obj)
Scrambling the Password
16.
Now that we’ve safely recovered the compromised users we’ll want to
remove the "passwords.csv" file completely.
_ _ ___ __ ____
/ )( \ / __) / \(_ _)
) \/ ( ( (_ \( O ) )(
\____/ \___/ \__/ (__)
_ _ __ ___ __ _ ____ ____
/ )( \ / _\ / __)( / )( __)( \
) __ (/ \( (__ ) ( ) _) ) D (
\_)(_/\_/\_/ \___)(__\_)(____)(____/
____ __ __ ____ _ _
___ / ___)( ) / _\ / ___)/ )( \
(___) \___ \/ (_/\/ \\___ \) __ (
(____/\____/\_/\_/(____/\_)(_/
__ _ _ _ __ __
( ( \/ )( \( ) ( )
/ /) \/ (/ (_/\/ (_/\
\_)__)\____/\____/\____/
Save that as a multiline string to the variable slash_null_sig.
Hint
Remember you can start a multiline string with three quotes:
multiline_str = """
___ __ __ __
/ __)/ \ / \ ( )
( (__( O )( O )/ (_/\
\___)\__/ \__/ \____/
"""
18.
Write slash_null_sig to new_passwords_obj. Now we have the file to
replace passwords.csv with!
19.
What an incredible success! We’ll take care of moving the new passwords
file over the old one in case you want to practice hacking The Fender in the
future.