aboutsummaryrefslogtreecommitdiff
path: root/invoke_session_oe
blob: 80e2f1eafed35f538ac85920b07e410f998b671c (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# Usage ./invoke_session <gateway>

# 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 <<EOF > ~/.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