Is it just me or is the amount of spam increasing at an unreasonable rate?
You join channels on IRC and get spammed by half a dozen trojin bots to download “free porn” and the likes (which usualy are trojins designed to turn your pc into YAZ
Well, later I might deal with the PM side of the spam, but today I’m going to give you a script that will help identify and remove these bots/hosts from your channel.
While it’s fair to say not every host that has an open proxy spams, and not every spammer is an open proxy.
It is also fair to say that a large number of attack drones from large botnets go unreported
The idea is not to catch every one, you’d go insane – but every one that you can catch, that’s one less for you to deal with.
As an added bonus, this script can back end into mysql for reporting and analysis if you chose to enable that feature.
## DNS Blacklist Checker- Version 1.0
## INSTRUCTIONS
###############################################################################
# This script will check the hosts of people joining channels against one or
# RBLs. Choose your RBLs wisely, some of them list DIALUP &/or DYNAMIC IP SPACE
# and that would be a bad thing to be matching your IRC users against
#
# Enable the 'dnsblcheck' flag for channels you want the script active on
# --> .chanset #somechannel +dnsblcheck
#
# To enable manual queries enable the 'dnsblmanual' flag
# --> .chanset #somechannel +dnsblmanual
#
# Users who are +o, +v, or +f in your bot (local or global) won't be checked.
#
# Turn on console level d on the partyline to see some debug from the script
# --> .console +d (to enable)
# --> .console -d (to disable)
## Mysql Table Creation (if you choose to use mysql. Default OFF)
###############################################################################
# CREATE TABLE `DNSBLLog` (
# `Stamp` timestamp(14) NOT NULL,
# `Nick` char(15) default NULL,
# `Hostmask` char(255) NOT NULL default '',
# `Chan` char(201) default NULL,
# `IP` int(10) unsigned default NULL,
# `DNSBL` char(60) default NULL,
# `Response` int(10) unsigned default NULL,
# KEY `Nick` (`Nick`),
# KEY `Chan` (`Chan`),
# KEY `DNSBL` (`DNSBL`)
# ) TYPE=MyISAM;
## Contact
##############################################################################
# You'll see me (Freman) floating around IRC
#
# Undernet:
##australia, #freak, #ozchat, #brisbane, #gentoo, #mysql, #php, #xchat
#
# EnterTheGame:
##ign
#
# Or you can send me email via the contact form at http://fremnet.net/contact
## CONFIG
###############################################################################
# Space-separated list of RBLs to look in
set dnsblcheck("RBLs") { "cbl.abuseat.org" "opm.blitzed.org" "dnsbl.ahbl.org" }
# Space-seperated list of domains to ignore
set dnsblcheck("Ignore") { "undernet.org" }
# Time in minutes to ban for
set dnsblcheck("Bantime") 15
# Flags we don't match
set dnsblcheck("SafeFlags") "fov"
# MySQL Details
# - Set UseMySQL to 1 if you intend to use mysql for logging and reporting
set dnsblcheck("UseMySQL") 0
set dnsblcheck("MySQLHost") "hostname"
set dnsblcheck("MySQLUser") "username"
set dnsblcheck("MySQLPass") "password"
set dnsblcheck("MySQLDB") "database"
set dnsblcheck("MySQLTable") "DNSBLLog"
# Now would be a good time to turn back
## CODE
###############################################################################
# Add our channel flags
setudef flag dnsblcheck
setudef flag dnsblmanual
# Bind our events
bind join - *!*@* dnsblcheck_join
bind pub - "!dnsblcheck" dnsblcheck_manual
# Process Manual Requests
proc dnsblcheck_manual { nick host handle chan rest } {
global dnsblcheck
# Check that we are active on this channel
if {![channel get $chan dnsblmanual]} {
return 0
}
# Fill out the rest of the hostmask
if {![string match "*\@*" $rest]} {
set rest "manual@$rest"
}
# Off to our first set of checks
dnsblcheck_check1 $nick $rest $chan 1
}
# Catch joins
proc dnsblcheck_join { nick host handle chan } {
global dnsblcheck
# Check that we are active on this channel
if {![channel get $chan dnsblcheck]} {
return 0
}
# Check that the joiner doesn't match our flags
if {[matchattr $handle $dnsblcheck("SafeFlags")|$dnsblcheck("SafeFlags") $chan]} {
return 0
}
dnsblcheck_check1 $nick $host $chan 0
}
# First check (Makes sure we get an IP Address)
proc dnsblcheck_check1 {nick host chan manual} {
global dnsblcheck
# Check to see if it's an ignored domain
foreach ignore $dnsblcheck("Ignore") {
if [string match "*$ignore" $host] {
if {$manual == 1} {
putchan $chan "\[DNSBL\] Unable to check host, ignored by $ignore"
}
return 0
}
}
# Get the actual host
regexp ".+@(.+)" $host matches newhost
if [regexp {[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$} $newhost] {
# It's an IP Address, we don't need to do a lookup on this
dnsblcheck_check2 $newhost $newhost 1 $nick $newhost $chan $manual $host
} else {
putloglev d * "dnsblcheck: doing dns lookup on $newhost to get IP"
dnslookup $newhost dnsblcheck_check2 $nick $newhost $chan $manual $host
}
}
# Second check (runs RBL checks)
proc dnsblcheck_check2 { ip host status nick orighost chan manual hostmask} {
global dnsblcheck
if {$status} {
putloglev d * "dnsblcheck: $host resolves to $ip"
# Reverse the IP Address
regexp {([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})} $ip matches a b c d
set newip "$d.$c.$b.$a"
# Look it up in the blacklists
foreach rbl $dnsblcheck("RBLs") {
putloglev d * "dnsblcheck: looking up $newip.$rbl"
dnslookup "$newip.$rbl" dnsblcheck_check3 $nick $host $chan $rbl $manual $hostmask $ip
}
} else {
if {$manual == 1} {
putchan $chan "\[DNSBL\] Couldn't resolve $host."
} else {
putlog "dnsblcheck: Couldn't resolve $host. (No further action taken.)"
}
}
}
# Third check (catches RBL results)
proc dnsblcheck_check3 { ip host status nick orighost chan rbl manual hostmask origip} {
global dnsblcheck
if {$status} {
if {$manual == 1} {
putchan $chan "\[DNSBL\] RBL $rbl returned $ip for $host (This means it's bannable)"
} else {
putlog "dnsblcheck: got host $host = ip $ip from RBL $rbl ... banning"
newchanban $chan "*@$orighost" "dnsbl" "Failed DNSBL Check: $rbl" $dnsblcheck("Bantime")
if {$dnsblcheck("UseMySQL")} {
set h [ mysqlconnect -host $dnsblcheck("MySQLHost") -user $dnsblcheck("MySQLUser") -password $dnsblcheck("MySQLPass") -db $dnsblcheck("MySQLDB") ]
mysqlexec $h "INSERT INTO $dnsblcheck("MySQLTable") VALUES (NOW(),'$nick','$hostmask','$chan',inet_aton('$host'),'$rbl',inet_aton('$ip'))"
mysqlclose $h
}
}
} else {
if {$manual == 1} {
putchan $chan "\[DNSBL\] RBL $rbl did not return for $host (Either DNS failure, or host is clean)"
}
}
#if we didn't get a host, they're not in RBL
}
putlog "DNSBLCheck 1.0 by Freman loaded"
if {$dnsblcheck("UseMySQL")} {
package require mysqltcl
putlog "DNSBLCheck 1.0 - Using MySQL for Logging and Reporting"
}