2018-05-23 13:02:19 +00:00
|
|
|
#!/bin/ash
|
2017-10-13 18:58:14 +00:00
|
|
|
|
|
|
|
|
# Let's ensure normal operation on exit or if interrupted ...
|
|
|
|
|
function fuCLEANUP {
|
|
|
|
|
exit 0
|
|
|
|
|
}
|
|
|
|
|
trap fuCLEANUP EXIT
|
|
|
|
|
|
2018-03-30 16:41:46 +00:00
|
|
|
### Vars
|
|
|
|
|
myOINKCODE="$1"
|
|
|
|
|
|
|
|
|
|
function fuDLRULES {
|
|
|
|
|
### Check if args are present then download rules, if not throw error
|
|
|
|
|
if [ "$myOINKCODE" != "" ] && [ "$myOINKCODE" == "OPEN" ];
|
|
|
|
|
then
|
|
|
|
|
echo "Downloading ET open ruleset."
|
2019-10-22 15:20:23 +00:00
|
|
|
wget -q --tries=2 --timeout=2 https://rules.emergingthreats.net/open/suricata-5.0/emerging.rules.tar.gz -O /tmp/rules.tar.gz
|
2018-03-30 16:41:46 +00:00
|
|
|
else
|
|
|
|
|
if [ "$myOINKCODE" != "" ];
|
|
|
|
|
then
|
|
|
|
|
echo "Downloading ET pro ruleset with Oinkcode $myOINKCODE."
|
2019-10-22 15:20:23 +00:00
|
|
|
wget -q --tries=2 --timeout=2 https://rules.emergingthreatspro.com/$myOINKCODE/suricata-5.0/etpro.rules.tar.gz -O /tmp/rules.tar.gz
|
2018-03-30 16:41:46 +00:00
|
|
|
else
|
|
|
|
|
echo "Usage: update.sh <[OPEN, OINKCODE]>"
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 14:12:18 +00:00
|
|
|
function fuENRULES {
|
|
|
|
|
# Cleanup old files and extract new files.
|
|
|
|
|
rm -rf /tmp/rules /tmp/tpotce.rules
|
|
|
|
|
tar xfz /tmp/rules.tar.gz -C /tmp/ 2>&1 > /dev/null
|
|
|
|
|
# Create the new ruleset by:
|
|
|
|
|
# - looping through rule files, except deleted ones;
|
|
|
|
|
# - enabling all disabled rules (performance should be OK);
|
|
|
|
|
# - removing unnecessary empty/comment lines.
|
|
|
|
|
ls /tmp/rules/*.rules | grep -v deleted.rules | while read f;
|
|
|
|
|
do
|
|
|
|
|
cat $f | sed "s/^#alert/alert/" | grep -Ev "^(#|$)" >> /tmp/tpotce.rules
|
|
|
|
|
done
|
|
|
|
|
# Copy the new ruleset and config to where they belong.
|
|
|
|
|
cp -f /tmp/tpotce.rules /tmp/rules/classification.config /etc/suricata/rules
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 13:02:19 +00:00
|
|
|
# Check internet availability
|
|
|
|
|
function fuCHECKINET () {
|
|
|
|
|
mySITES=$1
|
|
|
|
|
error=0
|
|
|
|
|
for i in $mySITES;
|
|
|
|
|
do
|
|
|
|
|
curl --connect-timeout 5 -Is $i 2>&1 > /dev/null
|
|
|
|
|
if [ $? -ne 0 ];
|
|
|
|
|
then
|
|
|
|
|
let error+=1
|
|
|
|
|
fi;
|
|
|
|
|
done;
|
|
|
|
|
echo $error
|
|
|
|
|
}
|
2018-03-30 16:41:46 +00:00
|
|
|
|
2018-05-23 13:02:19 +00:00
|
|
|
# Check for connectivity and download rules
|
|
|
|
|
myCHECK=$(fuCHECKINET "rules.emergingthreatspro.com rules.emergingthreats.net")
|
|
|
|
|
if [ "$myCHECK" == "0" ];
|
|
|
|
|
then
|
|
|
|
|
fuDLRULES 2>&1 > /dev/null
|
2020-11-25 14:12:18 +00:00
|
|
|
fuENRULES 2>&1 > /dev/null
|
2018-05-23 13:02:19 +00:00
|
|
|
echo "/etc/suricata/capture-filter.bpf"
|
|
|
|
|
else
|
|
|
|
|
echo "/etc/suricata/null.bpf"
|
|
|
|
|
fi
|