혜랑's STORY

[picoCTF] crackme.py - Reverse Engineering 본문

2021 SISS 21기 활동/여름방학 CTF[연합]

[picoCTF] crackme.py - Reverse Engineering

hyerang0125 2021. 8. 5. 18:24

이번에 해결할 문제이다.

crackme.py를 다운받아 주었다.

# Hiding this really important number in an obscure piece of code is brilliant!
# AND it's encrypted!
# We want our biggest client to know his information is safe with us.
bezos_cc_secret = "A:4@r%uL`M-^M0c0AbcM-MFE07b34c`_6N"

# Reference alphabet
alphabet = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"+ \
            "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"



def decode_secret(secret):
    """ROT47 decode

    NOTE: encode and decode are the same operation in the ROT cipher family.
    """

    # Encryption key
    rotate_const = 47

    # Storage for decoded secret
    decoded = ""

    # decode loop
    for c in secret:
        index = alphabet.find(c)
        original_index = (index + rotate_const) % len(alphabet)
        decoded = decoded + alphabet[original_index]

    print(decoded)



def choose_greatest():
    """Echo the largest of the two numbers given by the user to the program

    Warning: this function was written quickly and needs proper error handling
    """

    user_value_1 = input("What's your first number? ")
    user_value_2 = input("What's your second number? ")
    greatest_value = user_value_1 # need a value to return if 1 & 2 are equal

    if user_value_1 > user_value_2:
        greatest_value = user_value_1
    elif user_value_1 < user_value_2:
        greatest_value = user_value_2

    print( "The number with largest positive magnitude is "
        + str(greatest_value) )



choose_greatest()

 

코드를 살펴보니 decode_secret()이란 함수가 있다. 함수에 대한 설명을 읽어보니 ROT47을 해독하는 함수이고 이 함수를 사용하여 flag를 얻어내는 것 같다.

프로그램을 실행하고 bezos_cc_secret 문자열을 decode_secret()함수의 인자로 주어 실행시켰다.

역시 flag를 얻을 수 있었다.