moth/packages/rlyeh/service/rlyeh/rlyeh-ctf

45 lines
815 B
Bash
Executable File

#! /bin/sh
STATE=$CTF_BASE/state
echo -n "Team hash: "
read -r teamhash
if ! [ -f $STATE/teams/names/"$teamhash" ]; then
echo 'No such team.'
exit
fi
cd $STATE/rlyeh
if [ -f $teamhash ]; then
now=$(date +%s)
ts=$(stat -c %Y $teamhash)
d=$(expr $now - $ts)
if [ $d -lt 60 ]; then
echo 'You are trying to connect too fast.'
exit
fi
else
echo 1 > $teamhash
fi
read level < $teamhash
(
if ! flock -n 8; then
echo 'Your team is already logged in.'
exit
fi
echo "Your team is on level $level."
echo
if setuidgid nobody rlyeh $level; then
arc4 $CTF_BASE/packages/rlyeh/tokens/rlyeh/enc.key < $$CTF_BASE/state/rlyeh/tokens.txt
echo
expr $level + 1 > $teamhash
else
touch $teamhash
fi
) 8<$teamhash