-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploit.sh
50 lines (42 loc) · 1.09 KB
/
exploit.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Validate the URL format
if ! [[ "$1" =~ ^https:\/\/([A-Za-z0-9-]+\.)*picoctf\.net\/* ]]; then
echo "Error: please provide a valid URL as an argument."
echo "Usage: $0 <URL>"
exit 1
fi
URL=$1
get_flag() {
# Download the files.zip
wget -q "$URL" -O files.zip
if [ $? -ne 0 ]; then
echo "Error: Failed to download file."
exit 1
fi
# Unzip the downloaded file
unzip -q files.zip
if [ $? -ne 0 ]; then
echo "Error: Failed to unzip file."
exit 1
fi
# Check if the directory 'files' exists after unzipping
if [ ! -d "files" ]; then
echo "Error: 'files' directory not found."
exit 1
fi
# Extract the flag from the git show output
grep -RoE 'picoCTF{.*?}' files | cut -d ':' -f 2
if [ $? -ne 0 ]; then
echo "Error: Failed to extract flag."
exit 1
fi
}
# Call the function and store the flag
flag=$(get_flag)
# Check if the flag is found and print it
if [ -z "$flag" ]; then
echo "Error: Flag not found."
else
echo "Flag: $flag"
rm -rf files && rm files.zip
fi