Detect and ban port scanners as well as other forms of abuse (closes #820)

This commit is contained in:
mdecimus
2024-10-08 11:48:03 +02:00
parent 1561a603ab
commit 581533b09c
14 changed files with 303 additions and 62 deletions

View File

@@ -6,7 +6,7 @@
use common::listener::{SessionResult, SessionStream};
use mail_send::Credentials;
use trc::AddContext;
use trc::{AddContext, SecurityEvent};
use crate::{
protocol::{request::Error, Command, Mechanism},
@@ -49,6 +49,27 @@ impl<T: SessionStream> Session<T> {
break;
}
Err(Error::Parse(err)) => {
// Check for port scanners
if matches!(&self.state, State::NotAuthenticated { .. },) {
match self.server.is_scanner_fail2banned(self.remote_addr).await {
Ok(true) => {
trc::event!(
Security(SecurityEvent::ScanBan),
SpanId = self.session_id,
RemoteIp = self.remote_addr,
Reason = "Invalid POP3 command",
);
return SessionResult::Close;
}
Ok(false) => {}
Err(err) => {
trc::error!(err
.span_id(self.session_id)
.details("Failed to check for fail2ban"));
}
}
}
requests.push(Err(trc::Pop3Event::Error.into_err().details(err)));
}
}