-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun
executable file
·40 lines (31 loc) · 1022 Bytes
/
run
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
#!/bin/bash -eu
# Copyright (c) 2015, Heye Voecking <heye.voecking+exploit-exercises.com@gmail.com>
if [[ $1 = --help ]]
then
echo "Usage: $0 <HOST> <PORT> <CHALLENGE_NAME> <LEVEL>"
fi
source common/utils
HOST=$1; shift
PORT=$1; shift
CHALLENGE_NAME=$1; shift
LEVEL=level$1; shift
KEYS_DIR=.keys
ID_RSA=$KEYS_DIR/$LEVEL
SSH_CMD="ssh $SSH_OPTIONS -i $ID_RSA -p $PORT"
if [ ! -f $ID_RSA ]
then
mkdir -p $KEYS_DIR
ssh-keygen -t rsa -b 1024 -f $ID_RSA -C "$(whoami)@$(hostname)" -N "" >/dev/null
fi
# Always upload our key to ensure we can always connect
ID_RSA_PUB=${ID_RSA}.pub
socat_exec $LEVEL "ssh $SOCAT_SSH_OPTIONS -p $PORT $LEVEL@$HOST '
rm -rf .ssh;
mkdir .ssh;
chmod 700 ~/.ssh;
touch ~/.ssh/authorized_keys;
chmod 600 ~/.ssh/authorized_keys;
echo $(cat $ID_RSA_PUB) > .ssh/authorized_keys'" 2>/dev/null >/dev/null
FILES="common $CHALLENGE_NAME/$LEVEL"
rsync -e "$SSH_CMD" -az $FILES $LEVEL@$HOST: >/dev/null
$SSH_CMD $LEVEL@$HOST "cd ~/$LEVEL; ./$CHALLENGE_NAME-$LEVEL.sh; rm -rf $FILES"