Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honeypot Mode #42

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/erooster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ auditable = "0.2"
[features]
default = []
jaeger = ["dep:opentelemetry-jaeger"]
honeypot = ["erooster_smtp/honeypot"]

[build-dependencies]
clap = { version = "3.1", features = ["derive", "color", "suggestions","env"] }
Expand Down
5 changes: 5 additions & 0 deletions crates/erooster_smtp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ cfdkim = {version = "0.2.3", git = "https://github.com/erooster-mail/dkim"}
time = {version = "0.3.13", features = ["formatting"]}
reqwest = {version = "0.11.11", features = ["json","rustls-tls","trust-dns"]}
serde_json = "1.0.85"
cfg-if = "1.0.0"

[features]
default = []
honeypot = []

[[bench]]
name = "smtp_bench"
Expand Down
57 changes: 30 additions & 27 deletions crates/erooster_smtp/src/commands/data.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
use crate::{
commands::Data,
servers::{
sending::{send_email_job, EmailPayload},
state::State,
},
utils::rspamd::Response,
};
use crate::{commands::Data, servers::state::State, utils::rspamd::Response};
use color_eyre::eyre::ContextCompat;
use erooster_core::{
backend::{
database::{Database, DB},
database::DB,
storage::{MailStorage, Storage},
},
config::{Config, Rspamd},
Expand All @@ -19,6 +12,11 @@ use std::{collections::HashMap, path::Path, sync::Arc, time::Duration};
use time::{macros::format_description, OffsetDateTime};
use tracing::{debug, instrument};

#[cfg(not(feature = "honeypot"))]
use crate::servers::sending::{send_email_job, EmailPayload};
#[cfg(not(feature = "honeypot"))]
use erooster_core::backend::database::Database;

#[allow(clippy::module_name_repetitions)]
pub struct DataCommand<'a> {
pub data: &'a Data,
Expand Down Expand Up @@ -112,30 +110,35 @@ impl DataCommand<'_> {
data
};

let email_payload = EmailPayload {
to,
from: write_lock
.sender
.clone()
.context("Missing sender in internal state")?,
body: data,
sender_domain: config.mail.hostname.clone(),
dkim_key_path: config.mail.dkim_key_path.clone(),
dkim_key_selector: config.mail.dkim_key_selector.clone(),
};
let pool = database.get_pool();
send_email_job
.builder()
.set_json(&email_payload)?
.spawn(pool)
.await?;
debug!("Email added to queue");
cfg_if::cfg_if! {
if #[cfg(not(feature = "honeypot"))] {
let email_payload = EmailPayload {
to,
from: write_lock
.sender
.clone()
.context("Missing sender in internal state")?,
body: data,
sender_domain: config.mail.hostname.clone(),
dkim_key_path: config.mail.dkim_key_path.clone(),
dkim_key_selector: config.mail.dkim_key_selector.clone(),
};
let pool = database.get_pool();
send_email_job
.builder()
.set_json(&email_payload)?
.spawn(pool)
.await?;
debug!("Email added to queue");
}
}
}

lines.send(String::from("250 OK")).await?;

State::Authenticated(username.clone())
} else if matches!(write_lock.state, State::ReceivingData(None)) {
// TODO rewrite to also have some extra honeypot info logging and make it not pass into inbox but into top level of the address
debug!("No authenticated user");
for receipt in receipts {
let folder = "INBOX".to_string();
Expand Down
17 changes: 12 additions & 5 deletions crates/erooster_smtp/src/commands/rcpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ use crate::{
servers::state::State,
};
use color_eyre::eyre::bail;
use erooster_core::backend::database::{Database, DB};
use erooster_core::backend::database::DB;
use futures::{channel::mpsc::SendError, Sink, SinkExt};
use tracing::{info, instrument};

#[cfg(not(feature = "honeypot"))]
use erooster_core::backend::database::Database;

pub struct Rcpt<'a> {
pub data: &'a Data,
}
Expand Down Expand Up @@ -36,10 +39,14 @@ impl Rcpt<'_> {
{
let mut write_lock = self.data.con_state.write().await;
if matches!(&write_lock.state, State::NotAuthenticated) {
for receipt in &receipts {
if !database.user_exists(&receipt.to_lowercase()).await {
lines.send(String::from("550 No such user here")).await?;
return Ok(());
cfg_if::cfg_if! {
if #[cfg(not(feature = "honeypot"))] {
for receipt in &receipts {
if !database.user_exists(&receipt.to_lowercase()).await {
lines.send(String::from("550 No such user here")).await?;
return Ok(());
}
}
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions crates/erooster_smtp/src/servers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::servers::sending::send_email_job;
use erooster_core::{
backend::{
database::{Database, DB},
Expand All @@ -12,10 +11,15 @@ use std::error::Error;
use std::sync::Arc;
use tracing::instrument;

#[cfg(not(feature = "honeypot"))]
use crate::servers::sending::send_email_job;

pub(crate) mod encrypted;
pub(crate) mod sending;
pub(crate) mod state;

#[cfg(not(feature = "honeypot"))]
pub(crate) mod sending;

// TODO make this only pub for benches and tests
#[allow(missing_docs)]
pub mod unencrypted;
Expand Down Expand Up @@ -74,7 +78,13 @@ pub async fn start(
let pool = database.get_pool();

// Construct a job registry from our job.
let mut registry = JobRegistry::new(&[send_email_job]);
cfg_if::cfg_if! {
if #[cfg(not(feature = "honeypot"))] {
let mut registry = JobRegistry::new(&[send_email_job]);
} else {
let mut registry = JobRegistry::new(&[]);
}
}
// Here is where you can configure the registry
registry.set_error_handler(|name: &str, error: Box<dyn Error + Send + 'static>| {
tracing::error!("Job `{}` failed: {}", name, error);
Expand Down