Skip to content

Instantly share code, notes, and snippets.

@x86demon
Created May 15, 2020 14:21
Show Gist options
  • Select an option

  • Save x86demon/be8fd8f8f3358254c70713c4d7469348 to your computer and use it in GitHub Desktop.

Select an option

Save x86demon/be8fd8f8f3358254c70713c4d7469348 to your computer and use it in GitHub Desktop.
Block asterisk password brute force in Asus RT-n66u
#!/bin/sh
IPS=$(cat /opt/var/log/asterisk/messages | grep -oE "failed for '([^:]*)" | grep -oE '[0-9]+\.[0-9]+\.[0-9+]+\.[0-9]+' | sort | uniq)
[ -z "$IPS" ] && exit 0
for ip in ${IPS}
do
echo "Blocking IP: ${ip}"
iptables -I INPUT -s ${ip} -j DROP
echo "iptables -I INPUT -s ${ip} -j DROP" >> /jffs/scripts/firewall-start
done
# Send notification
python /opt/bin/telegram_send "Asterisk blocked IPs ${IPS}"
# Clear messages to prevent double blocking
echo "" > /opt/var/log/asterisk/messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment