diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2017-12-18 06:57:15 -0500 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2017-12-18 11:27:52 -0500 |
commit | 0d2eea29ed02406bcd761a6b43a04262aa98c2a9 (patch) | |
tree | 7df2b0018a2ef3d1cca40b96533f7ebae1775696 | |
parent | ff6119f99a9a4c804936a8e07f69a2d94795a77a (diff) |
add pingbot detection modulepingbot-detection
-rw-r--r-- | bot_settings.sh | 2 | ||||
-rw-r--r-- | modules/m_pingbot_detection.sh | 105 |
2 files changed, 106 insertions, 1 deletions
diff --git a/bot_settings.sh b/bot_settings.sh index ec68006..b821561 100644 --- a/bot_settings.sh +++ b/bot_settings.sh @@ -186,7 +186,7 @@ config_transport_dir="transport" # # The list should normally start with "modules rehash services umodes autojoin" # Some modules should be placed last. "factoids" and "karma are such modules. -config_modules="modules rehash services umodes autojoin ctcp" +config_modules="modules rehash services umodes autojoin ctcp pingbot_detection kick_ban" # Where are modules stored, this can be a relative path from the # main script of the bot, or an absolute path. diff --git a/modules/m_pingbot_detection.sh b/modules/m_pingbot_detection.sh new file mode 100644 index 0000000..49a48d4 --- /dev/null +++ b/modules/m_pingbot_detection.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# -*- coding: utf-8 -*- +########################################################################### +# # +# envbot - an IRC bot in bash # +# Copyright (C) 2007-2008 Arvid Norlander # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +# # +########################################################################### +#--------------------------------------------------------------------- +## This module detects and kicks pingbots. +## That is, the sender of any message containing +## more than some un-reasonable number of nicks in the roster. +#--------------------------------------------------------------------- + +readonly PINGBOT_DETECTION_MODULE_DEPS='nicktracking' +readonly PINGBOT_DETECTION_N_NICK_PINGS=4 +readonly PINGBOT_DETECTION_CHANNEL='#av-caster' +readonly PINGBOT_DETECTION_BAN_NOTICE="has been banned for mentioning too many nicks at once." + + +module_pingbot_detection_INIT() +{ + modinit_API='2' + modinit_HOOKS='after_load on_raw' + helpentry_module_pingbot_detection_description="Provides support for detecting and kicking pingbots." +} + +module_pingbot_detection_UNLOAD() +{ + unset module_pingbot_detection_after_load +} + +module_pingbot_detection_REHASH() +{ + return 0 +} + +module_pingbot_detection_after_load() +{ + for module_dep in $PINGBOT_DETECTION_MODULE_DEPS + do if ! modules_depends_register "pingbot_detection" "$module_dep" + then if ! list_contains "modules_loaded" "$module_dep" + then log_error "'pingbot_detection' could not load module dependency: '$module_dep'." + fi + + return 1 + fi + done +} + +module_pingbot_detection_on_raw() +{ +# echo "module_pingbot_detection_on_raw() server_name='$server_name' line='$line'" + + [[ "$line" =~ ^:${server_name}\ +([0-9]{3})\ +([^ ]+)\ +(.*) ]] && return 0 # numeric + [[ "$line" =~ ^:([^ ]*)\ +PRIVMSG\ +([^:]+)\ +:(.*) ]] || return 0 # user msg + + local sender="${BASH_REMATCH[1]}" + local target="${BASH_REMATCH[2]}" + local query="${BASH_REMATCH[3]}" + + local n_pings=0 + module_nicktracking_get_channel_nicks "$target" 'nicks' + for nick in $nicks ; do [[ " $query " =~ " $nick " ]] && n_pings=$(($n_pings+1)) ; done ; + +# echo "module_pingbot_detection_on_raw() sender='$sender'" +# echo "module_pingbot_detection_on_raw() target='$target'" +# echo "module_pingbot_detection_on_raw() query='$query'" +# echo "module_pingbot_detection_on_raw() nicks=$nicks" +# echo "module_pingbot_detection_on_raw() n_pings=$n_pings" + + [[ "$n_pings" -le "$PINGBOT_DETECTION_N_NICK_PINGS" ]] && return 0 + [[ "$target" != "$PINGBOT_DETECTION_CHANNEL" ]] && return 0 + +# echo "!!!pingbot_detection!!! pingbot=$sender" + + parse_hostmask "$sender" 'sender_nick' 'sender_ident' 'sender_host' + + # quiet user + send_modes "$PINGBOT_DETECTION_CHANNEL" "+b $sender" + # or by host + # send_modes "$PINGBOT_DETECTION_CHANNEL" "+b *!*@$sender_host" + + # quiet user and prevent nick change + # send_modes "$PINGBOT_DETECTION_CHANNEL" "+bb ~q:$sender ~n:$sender" + # or by host + # send_modes "$PINGBOT_DETECTION_CHANNEL" "+bb ~n:*!*@$sender_host ~q:*!*@$sender_host" + + send_notice "$PINGBOT_DETECTION_CHANNEL" "$sender_nick $PINGBOT_DETECTION_BAN_NOTICE" + + return 1 +} |