From 33f53a74039108641a61bd4df9547e0b41f02f46 Mon Sep 17 00:00:00 2001 From: ps Date: Wed, 21 Mar 2012 22:10:07 +0000 Subject: [PATCH] ADD: number_of_unimplemented_commands_allowed and related code --- src/Configfile.tmpl | 5 +++++ src/Proxy.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Configfile.tmpl b/src/Configfile.tmpl index fa352f2..1851801 100644 --- a/src/Configfile.tmpl +++ b/src/Configfile.tmpl @@ -80,6 +80,11 @@ bool,throttle,true * don't set this too high (more than 3), as that will drop MANY connections int,throttling_time,1 +* number of unimplemented responses allowed +* this is the total number of "503 Unimplemented" responses allowed from the server +* -1 = unlimited +int,number_of_unimplemented_commands_allowed,-1 + * whether we should check if there is data before we send the SMTP banner. * if there is data the email is almost certainly spam. bool,allow_data_before_banner,false diff --git a/src/Proxy.cpp b/src/Proxy.cpp index 1359cde..f5d009b 100644 --- a/src/Proxy.cpp +++ b/src/Proxy.cpp @@ -45,6 +45,7 @@ void Proxy::run(string &peer_address) string ehlostr=""; string resolvedname=""; unsigned char last_state=SMTP_STATE_WAIT_FOR_HELO; + long unimplemented_requests=0; try { @@ -299,6 +300,20 @@ void Proxy::run(string &peer_address) //or to not advertise it as the last capability. if("250 pipelining"==Utils::strtolower(strtemp)||"250 chunking"==Utils::strtolower(strtemp)) strtemp="250 x-noextension"; + + //try to annoy spammers who send us too many senseless commands by delaying their connection a lot + if("502"==code) //502 unimplemented -> count them, if bigger than a certain number, terminate connection + { + if(cfg.getNumberOfUnimplementedCommandsAllowed()!=-1&&++unimplemented_requests>cfg.getNumberOfUnimplementedCommandsAllowed()) + { + inside.writeLine("QUIT"); + inside.close(); //close the socket now and leave server alone + sleep(60); + outside.writeLine("502 Too many unimplemented commands, closing connection"); + return; + } + } + if(strtemp.length()) outside.writeLine(strtemp); }