How to ban IPs from ThreatHive using CrowdSec CLI script
Save the following script to /usr/local/bin/import_threathive.sh
and make it executable:
#!/bin/bash
BLOCKLIST_URL="https://threathive.net/hiveblocklist.txt"
TMPFILE="/tmp/hiveblocklist.txt"
IMPORTFILE="/tmp/hiveblocklist_bulk.json"
# Download blocklist
curl -s "$BLOCKLIST_URL" -o "$TMPFILE" || exit 1
# Remove existing imported decisions
sudo cscli decisions delete --origin "cscli-import" > /dev/null
# Create bulk JSON
echo "[" > "$IMPORTFILE"
first=1
while read -r ip; do
[[ "$ip" =~ ^#.*$ || -z "$ip" ]] && continue
if [ $first -eq 0 ]; then
echo "," >> "$IMPORTFILE"
fi
echo "{\"type\": \"ban\", \"value\": \"$ip\", \"origin\": \"threathive\", \"scenario\": \"external blocklist\", \"duration\": \"24h\"}" >> "$IMPORTFILE"
first=0
done < "$TMPFILE"
echo "]" >> "$IMPORTFILE"
# Import in bulk
sudo cscli decisions import -i "$IMPORTFILE" --duration 24h
Make it executable:
sudo chmod +x /usr/local/bin/import_threathive.sh
sudo /usr/local/bin/import_threathive.sh
INFO[0000] 0 decision(s) deleted
Parsing json
You are about to add 88994 decisions, this may take a while
sudo cscli decisions list
| 204335 | threathive | Ip:1.0.254.208 | threathive | ban | ... |
sudo crontab -e
0 0 * * * /usr/local/bin/import_threathive.sh > /dev/null 2>&1