Import the ThreatHive blocklist into CrowdSec decisions via a script and automate it with cron.
/usr/local/bin/import_threathive.sh:
#!/bin/bash
BLOCKLIST_URL="https://threathive.net/hiveblocklist.txt"
TMPFILE="/tmp/hiveblocklist.txt"
IMPORTFILE="/tmp/hiveblocklist_bulk.json"
# Download the latest blocklist
curl -s "$BLOCKLIST_URL" -o "$TMPFILE" || exit 1
# Clear previous ThreatHive decisions
sudo cscli decisions delete --origin "threathive" > /dev/null 2>&1
# Build bulk JSON payload
echo "[" > "$IMPORTFILE"
first=1
while read -r ip; do
[[ "$ip" =~ ^#.*$ || -z "$ip" ]] && continue
[ $first -eq 0 ] && echo "," >> "$IMPORTFILE"
echo "{\"type\": \"ban\", \"value\": \"$ip\", \"origin\": \"threathive\", \"scenario\": \"external blocklist\", \"duration\": \"24h\"}" >> "$IMPORTFILE"
first=0
done < "$TMPFILE"
echo "]" >> "$IMPORTFILE"
# Import decisions in bulk
sudo cscli decisions import -i "$IMPORTFILE" --duration 24h
Then make it executable:
sudo chmod +x /usr/local/bin/import_threathive.sh
sudo /usr/local/bin/import_threathive.sh
Expected output:
INFO[0000] 0 decision(s) deleted
Parsing json
You are about to add 88994 decisions, this may take a while
sudo cscli decisions list
You should see entries like:
| 204335 | threathive | Ip:1.0.254.208 | threathive | ban | 24h |
sudo crontab -e
0 0 * * * /usr/local/bin/import_threathive.sh > /dev/null 2>&1