-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploit.sh
52 lines (43 loc) · 1.2 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
51
52
#!/bin/bash
# Validate the URL format
if ! [[ "$1" =~ ^https:\/\/([A-Za-z0-9-]+\.)*picoctf\.net\/.*\/challenge\.zip$ ]]; then
echo "Error: please provide a valid URL as an argument."
echo "Usage: $0 <URL>"
exit 1
fi
URL="$1"
function get_flag() {
# Download the challenge.zip
wget -q "$URL" -O challenge.zip
if [ $? -ne 0 ]; then
echo "Error: Failed to download file."
exit 1
fi
# Unzip the downloaded file
unzip -q challenge.zip
if [ $? -ne 0 ]; then
echo "Error: Failed to unzip file."
exit 1
fi
# Check if the directory 'drop-in' exists after unzipping
if [ ! -d "drop-in" ]; then
echo "Error: 'drop-in' directory not found."
exit 1
fi
# Change directory to 'drop-in'
cd drop-in || exit
# Extract the flag from the git show output
git show | sed -r 's/\x1b\[[0-9;]*m//g' | grep '^-' | sed 's/^-//' | grep -oE 'picoCTF{.*?}'
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"
fi