#!/bin/sh # Usage ./invoke_session # If gateway isn't set we will guess it based on the default route if [ -z "$1" ]; then gateway=`ip route get 8.8.8.8 | grep via | cut -d ' ' -f3` else gateway=$1 fi echo "Target's Gateway: $gateway" # Copy invoke session cp /bin/invoke_session /etc/init.d/invoke_session # Obtain target IP and Hostname ip_addr=$(ifconfig `ip route get $gateway | cut -d ' ' -f3` | grep 'inet addr' |awk -F: '{split($2,a," "); print a[1] }') hostname=$(cat /etc/hostname) # Set the PATH to use the LAVA api echo "export PATH=/lava/bin/:$PATH" > ~/.shrc echo "" echo "" echo "*********************************************************************************************" echo -n "Please connect to: " echo -n "ssh " echo -n "-o UserKnownHostsFile=/dev/null " echo -n "-o StrictHostKeyChecking=no " echo -n "root@" echo -n $ip_addr echo -n " " echo -n "(" echo -n $hostname echo ")" echo "*********************************************************************************************" echo "" echo "" cat < ~/.bash_logout if [ $(who |egrep 'pts\/[0-9]+' |wc -l) -eq 1 ]; then lava-test-case hacking-stopped-logout --result pass stop_hacking fi EOF mkdir -p /run mkdir -p /run/hacking echo $$ > /run/hacking/hacking.pid TIMESTAMP=`stat -c %Y /run/hacking/hacking.pid` STARTED=false TERMINATED=false echo "Hacking session active..." lava-test-case hacking-session-active --result pass tail -f /var/log/syslog & echo $! > /run/hacking/tail.pid while [ -f /run/hacking/hacking.pid ] do date echo "====================" who echo "====================" echo "" sleep 10 LOGGEDIN=`who | grep pts | wc -l` if ! $STARTED && [ $LOGGEDIN -gt 0 ]; then STARTED=true elif ! $STARTED && [ $LOGGEDIN -eq 0 ]; then NOW=`date +%s` ELAPSED=`expr $NOW - $TIMESTAMP` if [ $ELAPSED -gt 3600 ]; then TERMINATED=true echo "No user logged in. Terminating session..." lava-test-case hacking-session-terminated --result fail --measurement ${ELAPSED} --units seconds stop_hacking fi fi done kill `cat /run/hacking/tail.pid` rm /run/hacking/tail.pid echo "Hacking session ended..." if ! ${TERMINATED}; then lava-test-case hacking-session-terminated --result pass fi