Created
September 5, 2020 17:40
-
-
Save arbitraryrw/0e500bf82b48e85f35393fd17c72190c to your computer and use it in GitHub Desktop.
R2con CTF 2020 - Cyber Lock Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import hashlib | |
import string | |
correct_hashes = [ | |
"D9259A378FC0EA75C1828369059854DEF76F91CABD01B56EF548C7ABA6441D59DD2DB9E51BD70C457179A123D53138F88132B29C691A9671F6C80E41E7D682A4", | |
"3F675784DABBC1330806CB4D5FE67860C25E103B75EB7B22821B2D75264B60C4D2E042A1726E1B85E3936A2A95E835E92FEFAC2C2E34A249109D98AED3962C71", | |
"BD605F0A10170EC1F7610BCF696C518AAB31C235CCF47866A71C332368BFE8B7E9FE4E3907B3CD37F111B40EEFFE89287C25033A41369A3236751474AD522537", | |
"B8CA8A22501EAB44AD44E6EB2F87791CA69955BFFC025988418866BDD8A1EAABA97F630A705D68B26370E49DAD9DE65AB478117C4289FFC240A8C85308D116A1", | |
"0694F2776E101C72092994B2F125973CBD3A608B3BA17CF8795DDDEEDE6773E0DE8D832EAE4EE3FF8C748FD6BDBC1BF843081CC6AEEFB09B1C908AD484382884", | |
"F9B4F710E8ADC5D4A32779A865396B019A630E2B1DB475F0F1656BC195ED2E0171932C9629DE5417F5C2D96FECC4B89107C9E28477513F98D5147391DF374C3C", | |
"B8CA8A22501EAB44AD44E6EB2F87791CA69955BFFC025988418866BDD8A1EAABA97F630A705D68B26370E49DAD9DE65AB478117C4289FFC240A8C85308D116A1", | |
"7280E46538FE2158921FA20E7A835E9F4900E8AFDA73E1D1EE03472E0B34D59AC28ABE964652B6EC8DF1B44D3F1B90A7684D470A191BB446FB2149918E69DE38", | |
"F08DF5E5DFDACE8892F03B4475263D72D6999DCC499C741028935D7D167222086F5FB63C793C20BA02E56AB74E901B1E66D178206E91B469F6055E63EE824D7F", | |
"9D9A2B793485D2ADF818DB5DF1D97CD1072F826845940780ECA50B623F8D931DC9533AF77DF2B811645B8B852670188A17736E8A536F672D5639EA40F2D1FC40", | |
"4AC1807EC58C1BD56D177E3F409FBD0FBCDE7D97F9F8A71469FD92817BB866B4D71A0DF10EB501AF6CE4439861E46B89473555B08874CEBA33312AD3495E84F2", | |
"0694F2776E101C72092994B2F125973CBD3A608B3BA17CF8795DDDEEDE6773E0DE8D832EAE4EE3FF8C748FD6BDBC1BF843081CC6AEEFB09B1C908AD484382884" | |
] | |
print("[INFO] we have", len(correct_hashes), "hashy boys") | |
suffix = "_3_r2con2020" | |
alphabet = list(string.ascii_letters) | |
def sha256_hash_string(string): | |
""" | |
Return a SHA-256 hash of the given string | |
""" | |
return hashlib.sha256(string.encode('utf-8')).hexdigest() | |
def sha512_hash_string(string): | |
""" | |
Return a SHA-256 hash of the given string | |
""" | |
return hashlib.sha512(string.encode('utf-8')).hexdigest() | |
solution = "" | |
for index, hash in enumerate(correct_hashes): | |
print(f"[INFO] Solving has {index}") | |
for a in alphabet: | |
sha256_hash_prefix = sha256_hash_string(a) | |
sha256_hash_prefix = sha256_hash_prefix.upper() | |
concatinated_string = sha256_hash_prefix + suffix | |
sha512_complete_hash = sha512_hash_string(concatinated_string) | |
if (sha512_complete_hash.upper() == correct_hashes[index]): | |
print(f"\tMatch found for {sha512_complete_hash}!") | |
print(f"\tKey {index} char is {a}, key is: {sha256_hash_prefix}") | |
solution += sha256_hash_prefix | |
# Verify the length matches 12 sha256 hashes | |
if len(solution) == (64*12): | |
print(f"[INFO] Complete solution:\n{solution}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment