-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_engine.sh
executable file
·99 lines (90 loc) · 2.56 KB
/
run_engine.sh
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
#!/bin/bash
# TODO - show list of available images for useage
# TODO - argument validate
# image is present
HELP="NO"
if [ $# -eq 0 ]; then
HELP="YES"
fi
#for key in "$@"
while [[ $# > 0 ]]
do
key="$1"
case $key in
-i|--image)
IMAGE="$2"
shift
;;
-e|--engine)
ENGINE="$2"
shift
;;
-r|--ruleset)
RULESET="$2"
shift
;;
-p|--pcap)
PCAP="$2"
if [ ! -f "$(pwd)"/pcaps/"$PCAP" ] ; then
echo "PCAP FILE NOT FOUND"
echo "./pcaps/"$PCAP" does not exist"
exit 1
fi
shift
;;
-x|--extra)
EXTRAS="$2"
shift
;;
-h|--help)
HELP="YES"
shift
;;
*)
# unknown option
;;
esac
shift
done
#exit
# ensure engine is set and a supported engined options are there
if [ -z "$ENGINE" ] ; then
HELP="YES"
echo "-e|--engine flag missing"
fi
if [ "$ENGINE" != "snort" ] && [ "$ENGINE" != "suricata" ] ; then
echo "$ENGINE is not currently supported"
HELP="YES"
fi
# ensure ruleset is set and is there
if [ -z "$RULESET" ] ; then
HELP="YES"
echo "-r|--ruleset flag missing"
fi
if [ ! -d ./policies/"$ENGINE"/"$RULESET" ] ; then
echo "RULESET NOT FOUND"
echo "Ruleset Directory ./policies/"$ENGINE"/"$RULESET" does not exist"
exit 1
fi
if [[ "$HELP" = "YES" ]] ; then
echo "Usage: $0 -i [image_name] -e [engine] -r [ruleset] -p [pcap] -x [extra options]";
echo "";
echo "-i|--image image name to use";
echo "-e|--engine IDS engine to run (currently snort or suricata)";
echo "-r|--ruleset ruleset name to for which to load the config file";
echo "-p|--pcap packet capture file to read";
echo "-x|--extra any other options to the IDS engine you'd like ('-k none')";
echo "-h|--help display this helpful information";
echo "";
echo "Everything but -x is required";
echo "";
exit 1;
fi
LOGDIR=$(date +%Y%m%d-%H%M%S)
if [ "$ENGINE" = "snort" ]; then
docker run --rm -v "$(pwd)"/policies/"$ENGINE"/"$RULESET":/usr/local/etc/"$ENGINE" -v "$(pwd)"/pcaps/:/tmp/ -v "$(pwd)"/logs/"$ENGINE"/"$LOGDIR"_"$PCAP":/var/log/"$ENGINE"/ "$IMAGE" "$ENGINE" -c /usr/local/etc/"$ENGINE"/snort.conf -r /tmp/"$PCAP" -H $EXTRAS
#cat ./logs/"$ENGINE"/"$LOGDIR"_"$PCAP"/alert_fast.log
elif [ "$ENGINE" = "suricata" ]; then
docker run --rm -v "$(pwd)"/policies/"$ENGINE"/"$RULESET":/usr/local/etc/"$ENGINE" -v "$(pwd)"/pcaps/:/tmp/ -v "$(pwd)"/logs/"$ENGINE"/"$LOGDIR"_"$PCAP":/var/log/"$ENGINE"/ "$IMAGE" "$ENGINE" -c /usr/local/etc/"$ENGINE"/suricata.yaml -r /tmp/"$PCAP" $EXTRAS
#cat ./logs/"$ENGINE"/"$LOGDIR"_"$PCAP"/fast.log
fi