easycrack

first let's run the binary

so we can see that this binary asking for which is the flag let's open the file using ghidra

we have one function called main

  1. first thing a user is prompted to enter a key

  2. The program calculates the sum of ASCII values of characters in the entered key

  3. It checks if the sum is equal to 0x539 (1337) and if the length of the key is 0xc (12).

  4. If the conditions are met, it prints "Nice key :)" along with the entered key; otherwise, it prints "Bad Key :(" with the entered key.

so we know that the flag starts with flag{ and ends with } so we know 6 characters from the key we need to find the other 6 characters by bruteforcing them and checking if the sum is equal to 1337

we know from the previous found flags the flag is always constructed using lowercase characters and numbers and _

Exploit :

def generate_key():
    # Known prefix and suffix
    prefix = "flag{"
    suffix = "}"

    # Iterate through all ASCII characters for the middle part
    for char1 in 'abcdefghijklmnopqrstuvwxyz_0123456789':
        for char2 in 'abcdefghijklmnopqrstuvwxyz_0123456789':
            for char3 in 'abcdefghijklmnopqrstuvwxyz_0123456789':
                for char4 in 'abcdefghijklmnopqrstuvwxyz_0123456789':
                    for char5 in 'abcdefghijklmnopqrstuvwxyz_0123456789':
                        for char6 in 'abcdefghijklmnopqrstuvwxyz_0123456789':
                            middle_part = f"{char1}{char2}{char3}{char4}{char5}{char6}"

                            # Concatenate the parts to form the complete key
                            generated_key = f"{prefix}{middle_part}{suffix}"

                            # Calculate the sum of ASCII values of characters
                            key_sum = sum(ord(char) for char in generated_key)
                            
                            # Check conditions
                            if key_sum == 0x539 and len(generated_key) == 0xc:
                                return generated_key

# Generate a key and print it
generated_key = generate_key()
print(f"Generated key: {generated_key}")

executing the script and waiting for a couple of minutes we get the correct key

Flag :

flag{aawzzz}

Last updated

Was this helpful?