File: test.sh

package info (click to toggle)
stenographer 0.0~git20180422.0.73ce5dd-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 19,112 kB
  • sloc: cpp: 2,062; sh: 782; yacc: 257; makefile: 102
file content (170 lines) | stat: -rwxr-xr-x 4,518 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash

# Copyright 2014 Google Inc. All rights reserved.
#
# 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.

DUMMY="${DUMMY-dummy0}"
PORT="${PORT-9123}"
BASEDIR="${BASEDIR-/tmp}"
SKIP_CLEANUP="${SKIP_CLEANUP}"
SANITIZE="${SANITIZE}"
PCAP_URL="ftp://ftp.ll.mit.edu/outgoing/darpa/data/2000/LLS_DDOS_1.0/data_and_labeling/tcpdump_inside/LLS_DDOS_1.0-inside.dump.gz"

set -e
cd $(dirname $0)
source ../lib.sh

function PullDownTestData {
  if [ ! -f $BASEDIR/steno_integration_test.pcap ]; then
    Info "Pulling down pcap data"
    curl -L "$PCAP_URL" > $BASEDIR/steno_integration_test.pcap.gz
    gunzip $BASEDIR/steno_integration_test.pcap.gz
  fi
}

function TestCountPackets {
  FILTER="$1"
  WANT="$2"
  Info "Looking $WANT packets from filter '$FILTER'"
  GOT="$(STENOGRAPHER_CONFIG="$OUTDIR/config" ../stenoread "$FILTER" -n | wc -l)"
  if [ "$GOT" != "$WANT" ]; then
    Error " - FAILED for filter '$FILTER': Want: $WANT  Got: $GOT"
    exit 1
  else
    Info " - SUCCESS: Got $GOT packets from filter '$FILTER'"
  fi
}

Info "Testing sudo access"
sudo cat /dev/null

InstallPackage tcpreplay

PullDownTestData

Info "Building stenographer"
pushd ../
go build
pushd stenotype
make SANITIZE=$SANITIZE
SetCapabilities stenotype
STENOTYPE_BIN="$(pwd)/stenotype"
popd
popd

Info "Setting up output directory"
OUTDIR="$(mktemp -d $BASEDIR/steno.XXXXXXXXXX)"
/bin/chmod g+rx "$OUTDIR"
Info "Writing output to directory '$OUTDIR'"

mkdir $OUTDIR/{pkt,idx,certs}

Info "Setting up $DUMMY interface"
sudo /sbin/modprobe dummy
sudo ip link add $DUMMY type dummy || Error "$DUMMY may already exist"
sudo ifconfig $DUMMY promisc up
set +e

STENOGRAPHER_PID=""
STENOTYPE_PID=""
function CleanUp {
  if [ -z "$SKIP_CLEANUP" ]; then
    Info "Cleaning up"
    if [ ! -z "$STENOGRAPHER_PID" ]; then
      Info "Killing stenographer ($STENOGRAPHER_PID)"
      KILLCMD=kill ReallyKill $STENOGRAPHER_PID
    fi
    if [ ! -z "$STENOTYPE_PID" ]; then
      Info "Killing stenotype ($STENOTYPE_PID)"
      KILLCMD=kill ReallyKill $STENOTYPE_PID
    fi
    Info "Deleting $DUMMY interface"
    sudo ifconfig $DUMMY down
    sudo ip link del dummy0
    Info "--- LOG ---"
    /bin/cat "$OUTDIR/log"
    Info "Removing $OUTDIR"
    sudo find "$OUTDIR" -ls
    rm -rfv "$OUTDIR"
  fi
}
trap CleanUp EXIT

cat > $OUTDIR/config << EOF
{
  "Threads": [
    { "PacketsDirectory": "$OUTDIR/pkt"
    , "IndexDirectory": "$OUTDIR/idx"
    , "DiskFreePercentage": 1
    }
  ]
  , "StenotypePath": "$STENOTYPE_BIN"
  , "Interface": "$DUMMY"
  , "Port": $PORT
  , "Host": "127.0.0.1"
  , "Flags": ["-v", "-v", "-v", "--filesize_mb=16", "--aiops=16"]
  , "CertPath": "$OUTDIR/certs"
}
EOF

Info "Setting up certs"
CURR_USR="$(id -u -n)"
CURR_GRP="$(id -g -n)"
STENOGRAPHER_CONFIG="$OUTDIR/config" ../stenokeys.sh $CURR_USR $CURR_GRP

Info "Starting stenographer"
../stenographer --config=$OUTDIR/config --syslog=false --v=4 >$OUTDIR/log 2>&1 &
STENOGRAPHER_PID="$!"

xterm -e "tail -f $OUTDIR/log" &

Info "Waiting for stenographer to start up"
Sleep 15
STENOTYPE_PID="$(ps axww |
    grep -v grep |
    grep -v Z |
    grep $STENOTYPE_BIN |
    awk '{print $1}')"
if [ -z "$STENOTYPE_PID" ]; then
  Error "Stenotype not running"
  exit 1
fi

Info "Sending packets to $DUMMY"
sudo tcpreplay -i $DUMMY --topspeed $BASEDIR/steno_integration_test.pcap
Sleep 80

Info "Looking for packets"
TestCountPackets "port 21582" 1018
TestCountPackets "host 0.100.194.86" 2
TestCountPackets "net 0.0.0.0/8" 580
TestCountPackets "net 172.0.0.0/8 and port 23" 292041

Info "Sending packets to $DUMMY a second time"
sudo tcpreplay -i $DUMMY --topspeed $BASEDIR/steno_integration_test.pcap
Sleep 80

Info "Looking for packets a second time, in parallel"
TESTPIDS=""
TestCountPackets "port 21582" 2036 &
TESTPIDS="$TESTPIDS $!"
TestCountPackets "host 0.100.194.86" 4 &
TESTPIDS="$TESTPIDS $!"
TestCountPackets "net 0.0.0.0/8" 1160 &
TESTPIDS="$TESTPIDS $!"
TestCountPackets "net 172.0.0.0/8 and port 23" 584082 &
TESTPIDS="$TESTPIDS $!"
wait $TESTPIDS

Info "Done"