Skip to content

Instantly share code, notes, and snippets.

@sirdarckcat
Last active June 22, 2019 22:23
Show Gist options
  • Save sirdarckcat/087e32982bd77bddbd9c46ccbc72edf7 to your computer and use it in GitHub Desktop.
Save sirdarckcat/087e32982bd77bddbd9c46ccbc72edf7 to your computer and use it in GitHub Desktop.
gctf.sh download all CTF tasks

gctf.sh

Usage:

wget https://gist.githubusercontent.com/sirdarckcat/087e32982bd77bddbd9c46ccbc72edf7/raw/gctf.sh && chmod +x gctf.sh
mkdir -p google-ctf-2019
DATABASE_URL=https://gctf-2019-da0962m957mnki9l.firebaseio.com ./gctf.sh google-ctf-2019/ctf
DATABASE_URL=https://gctf-2019-da0962m957mnki9l.firebaseio.com/beginners ./gctf.sh google-ctf-2019/bq
#!/bin/bash
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ -z "$1" ]; then
echo "Please pass as first argument the directory." >&2
exit
fi
if [ -z "$DATABASE_URL" ]; then
echo "Please set DATABASE_URL as an env variable." >&2
exit
fi
TASKS_URL="$DATABASE_URL/tasks.json"
TASKS_QUERY_URL="$TASKS_URL?orderBy=\"visible\"&equalTo=true"
TASKS=$((curl "$TASKS_QUERY_URL" 2>/dev/null) | jq keys | jq -r 'join(" ")')
if [ -z "$TASKS" ]; then
echo "Invalid database-url" >&2
exit
fi
if [ "$TASKS" == "error" ]; then
echo "Error fetching tasks" >&2
echo $TASKS_QUERY_URL
curl "$TASKS_QUERY_URL"
exit
fi
echo $TASKS_QUERY_URL
mkdir -p $1
pushd $1
for task in $TASKS; do
mkdir -p $task
pushd $task
(curl "$TASKS_QUERY_URL" 2>/dev/null) | jq '.["'$task'"]' > .metadata.json
visible=$(jq .visible .metadata.json)
if [ "$visible" == "false" ]; then
echo This task is not released > README.md
else
name=$(jq -r .name .metadata.json)
echo "# $name" > README.md
label=$(jq -r .label .metadata.json)
if [ "$label" != "null" ]; then
echo "*$label*" >> README.md
fi
echo '## Description' >> README.md
jq -r .description .metadata.json >> README.md
echo '## Aritfacts' >> README.md
attachment=$(jq -r .attachment .metadata.json)
if [ "$attachment" != "null" ]; then
(curl -o attachment.zip $attachment 2>/dev/null)
unzip -o attachment.zip
echo "### Attachments" >> README.md
zip -sf attachment.zip >> README.md
fi
host=$(jq -r .host .metadata.json)
if [ "$host" != "null" ]; then
echo "nc $host" > connect.sh
chmod +x connect.sh
echo "### Remote Server" >> README.md
echo $host >> README.md
fi
link=$(jq -r .link .metadata.json)
if [ "$link" != "null" ]; then
echo "xdg-open $link" > open.sh
chmod +x open.sh
echo "### Website" >> README.md
echo "[$link]($link)" >> README.md
fi
fi
popd
done
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment