chrono, PW Crack 5


Код решение (вторая задача):

import hashlib

### THIS FUNCTION WILL NOT HELP YOU FIND THE FLAG --LT ########################
def str_xor(secret, key):
    #extend key to secret length
    new_key = key
    i = 0
    while len(new_key) < len(secret):
        new_key = new_key + key[i]
        i = (i + 1) % len(key)
    return "".join([chr(ord(secret_c) ^ ord(new_key_c)) for (secret_c,new_key_c) in zip(secret,new_key)])
###############################################################################

flag_enc = open('level5.flag.txt.enc', 'rb').read()
correct_pw_hash = open('level5.hash.bin', 'rb').read()
'''
-rw-r--r--  1 kolya080808 kolya080808 327680 Mar 16  2023 dictionary.txt
-rw-r--r--  1 kolya080808 kolya080808     31 Mar 16  2023 level5.flag.txt.enc
-rw-r--r--  1 kolya080808 kolya080808     16 Mar 16  2023 level5.hash.bin
-rw-r--r--  1 kolya080808 kolya080808   1367 Apr 14 23:09 level5.py
'''



def hash_pw(pw_str):
    pw_bytes = bytearray()
    pw_bytes.extend(pw_str.encode())
    m = hashlib.md5()
    m.update(pw_bytes)
    return m.digest()

def grab_password():
    pw_list = []
    with open('dictionary.txt') as wordlist:
        for word in wordlist:
            pw_list.append(word.strip('\n'))
    return pw_list

def level_5_pw_check():
    user_pw = input("Please enter correct password for flag: ")
    pw_list = grab_password()
    for password in pw_list:
        user_pw = password
        user_pw_hash = hash_pw(password)
        if( user_pw_hash == correct_pw_hash ):
            print("Welcome back... your flag, user:")
            decryption = str_xor(flag_enc.decode(), user_pw)
            print(decryption)
            return
        print("That password is incorrect")



level_5_pw_check()

Видео выполнения:


Загрузки

Download files archive