-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL07C04.py
38 lines (30 loc) · 1.04 KB
/
L07C04.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#
# One of the agents has intercepted a file from the aliens
# The flag is hidden in large amount of non alphanumeric characters.
# The file lives at /tmp/destroymoonbase.gif
#
import re
def extract_flag(file_path):
try:
with open(file_path, 'r') as file:
file_contents = file.read()
# Use regular expression to extract alphanumeric characters
alphanumeric_characters = re.findall(r'[a-zA-Z0-9]+', file_contents)
# Join the alphanumeric characters to form a potential flag
potential_flag = ''.join(alphanumeric_characters)
return potential_flag
except FileNotFoundError:
print(f"Error: File '{file_path}' not found.")
return None
except Exception as e:
print(f"Error: {e}")
return None
# Path to the intercepted file
file_path = '/tmp/destroymoonbase.gif'
# Extract potential flag from the file
flag = extract_flag(file_path)
# Print the potential flag
if flag:
print(f"Potential flag: {flag}")
else:
print("Failed to extract the potential flag.")