Tip
🇪🇸 Leer en español: Haz clic aquí
This script monitors your OpenWrt router (specifically tested on fw4 / nftables based firewalls) and sends real-time notifications to Telegram regarding:
- Successful and failed logins to the web interface (LuCI).
- SSH login attempts (Keys and passwords).
- New WireGuard VPN connections (identifying the device by its description in
uci). - Auto-Ban: Automatically blocks IPs that fail login for 3 minutes using
nftables.
For the banning to work, you need to create a list named banlist in your firewall. Run these commands on the router:
uci add firewall ipset
uci set firewall.@ipset[-1].name='banlist'
uci set firewall.@ipset[-1].family='ipv4'
uci set firewall.@ipset[-1].match='src_ip'
uci set firewall.@ipset[-1].timeout='180'
uci commit firewall
/etc/init.d/firewall restart- Create a Telegram Bot with @BotFather and get your Token.
- Get your Chat ID (you can use @userinfobot).
- Download the
telegram-ntfy.shscript to/usr/bin/and edit theTOKENandIDvariables. - Give it execution permissions:
chmod +x /usr/bin/telegram-ntfy.sh.
To make the script start automatically with the router, create the file /etc/init.d/ntfy:
#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command /bin/sh /usr/bin/telegram-ntfy.sh
procd_set_param respawn
procd_close_instance
}Enable the service:
chmod +x /etc/init.d/ntfy
/etc/init.d/ntfy enable
/etc/init.d/ntfy start- OpenWrt 21.02 or higher (with
fw4). curlpackage installed (opkg update && opkg install curl).jsonfilterpackage (usually comes by default).
Este script monitoriza tu router OpenWrt (especialmente probado en firewalls basados en fw4 / nftables) y envía notificaciones en tiempo real a Telegram sobre:
- Conexiones exitosas y fallidas a la interfaz web (LuCI).
- Inicios de sesión por SSH (Llaves y contraseñas).
- Nuevas conexiones VPN WireGuard (identificando el dispositivo por su descripción en
uci). - Auto-Ban: Bloquea automáticamente las IPs que fallan en el login durante 3 minutos mediante
nftables.
Para que el baneo funcione, necesitas crear una lista llamada banlist en tu firewall. Ejecuta estos comandos en el router:
uci add firewall ipset
uci set firewall.@ipset[-1].name='banlist'
uci set firewall.@ipset[-1].family='ipv4'
uci set firewall.@ipset[-1].match='src_ip'
uci set firewall.@ipset[-1].timeout='180'
uci commit firewall
/etc/init.d/firewall restart- Crea un Bot en Telegram con @BotFather y obtén tu Token.
- Obtén tu Chat ID (puedes usar @userinfobot).
- Descarga el script
telegram-ntfy.shen/usr/bin/y edita las variablesTOKENeID. - Dale permisos de ejecución:
chmod +x /usr/bin/telegram-ntfy.sh.
Para que el script arranque solo con el router, crea el archivo /etc/init.d/ntfy:
#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command /bin/sh /usr/bin/telegram-ntfy.sh
procd_set_param respawn
procd_close_instance
}Habilita el servicio:
chmod +x /etc/init.d/ntfy
/etc/init.d/ntfy enable
/etc/init.d/ntfy start- OpenWrt 21.02 o superior (con
fw4). - Paquete
curlinstalado (opkg update && opkg install curl). - Paquete
jsonfilter(suele venir por defecto).