Post

Free Flags

Free Flags

Description

Author: @John Hammond

WOW!! Look at all these free flags!!

But… wait a second… only one of them is right??

NOTE, bruteforcing flag submissions is still not permitted. I will put a “max attempts” limit on this challenge at 1:00 PM Pacific to stop participants from automating submissions. There is only one correct flag, you can find a needle in a haystack if you really know what you are looking for.

Exploitation

So we downloaded the free_flags.txt file and it’s a huge file of flags as it contains 500 lines with a size of 117 KB:

1
2
> wc -l free_flags.txt 
500 free_flags.txt

From here we went back to the following page1 to look at the flag format as shown below: accessing-the-chal So we got the following format of flag => flag\{[0-9a-f]{32}\} This is how the following python script that will actually disclose the only flag having the correct format according the regular expression mentioned above, was made:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import re

def find_valid_flags(file_path):
    flag_pattern = r"flag\{([0-9a-f]{32})\}"

    with open(file_path, 'r') as file:
        content = file.read()

    flags = re.findall(flag_pattern, content)

    return flags

file_path = 'free_flags.txt'

valid_flags = find_valid_flags(file_path)

if valid_flags:
    print("Valid flags found:")
    for flag in valid_flags:
        print(f"flag{{{flag}}}")  
else:
    print("No valid flags found.")

Running it, disclosed the flag:

1
2
3
> python script.py 
Valid flags found:
flag{REDACTED}

Flag

flag{ae6b6fb0686ec594652afe9eb6088167}

References

  1. https://ctf.nahamcon.com/rules 

This post is licensed under CC BY 4.0 by the author.