All Projects → Vnet-as → Postfwd Anti Geoip Spam Plugin

Vnet-as / Postfwd Anti Geoip Spam Plugin

Licence: gpl-3.0
Postfwd plugin for blocking international spam botnets based on geographical location of IP addresses used to login to postfix via sasl.

Programming Languages

perl
6916 projects

Projects that are alternatives of or similar to Postfwd Anti Geoip Spam Plugin

Free Email Forwarding
The best free email forwarding for custom domains. Visit our website to get started (SMTP server)
Stars: ✭ 2,024 (+4960%)
Mutual labels:  email, mail, postfix
Sieve
Sieve Script Editor
Stars: ✭ 452 (+1030%)
Mutual labels:  email, mail
Gatsby Mail
A Gatsby email *application*
Stars: ✭ 450 (+1025%)
Mutual labels:  email, mail
Mfcmapi
MFCMAPI
Stars: ✭ 501 (+1152.5%)
Mutual labels:  email, mail
Mum
A web-based user management tool for Postfix and Dovecot that is easy to use and still very powerful.
Stars: ✭ 31 (-22.5%)
Mutual labels:  email, postfix
Mailcow Dockerized
mailcow: dockerized - 🐮 + 🐋 = 💕
Stars: ✭ 4,573 (+11332.5%)
Mutual labels:  postfix, mail
Sendria
Sendria (formerly MailTrap) is a SMTP server designed to run in your dev/test environment, that is designed to catch any email you or your application is sending, and display it in a web interface instead of sending to real world.
Stars: ✭ 30 (-25%)
Mutual labels:  email, mail
ProtonClient
An unofficial desktop client for ProtonMail done with electron nativefier
Stars: ✭ 50 (+25%)
Mutual labels:  mail, email
Php Mime Mail Parser
A fully tested email parser for PHP 7.2+ (mailparse extension wrapper).
Stars: ✭ 687 (+1617.5%)
Mutual labels:  email, mail
Node Dkim Key
DKIM (DomainKeys Identified Mail) Key
Stars: ✭ 5 (-87.5%)
Mutual labels:  email, mail
Pydnsbl
Async dnsbl spam lists checker based on asyncio/aiodns.
Stars: ✭ 18 (-55%)
Mutual labels:  mail, spam
imapx
A cross-platform IMAP library for .NET, supporting .Net 2.0 - 4.5, Mono and Windows Phone
Stars: ✭ 28 (-30%)
Mutual labels:  mail, email
smf-spf
It's a lightweight, fast and reliable Sendmail milter that implements the Sender Policy Framework
Stars: ✭ 12 (-70%)
Mutual labels:  email, postfix
Vimbadmin
Virtual Mailbox Administration
Stars: ✭ 441 (+1002.5%)
Mutual labels:  email, postfix
laravel-mjml
Laravel MJML offers support for rendering MJML syntax into in-line HTML that can be sent within mails.
Stars: ✭ 26 (-35%)
Mutual labels:  mail, email
Astroid
A graphical threads-with-tags style, lightweight and fast, e-mail client for Notmuch
Stars: ✭ 476 (+1090%)
Mutual labels:  email, mail
Docker Mailserver
Production-ready fullstack but simple mail server (SMTP, IMAP, LDAP, Antispam, Antivirus, etc.) running inside a container.
Stars: ✭ 8,115 (+20187.5%)
Mutual labels:  mail, postfix
himalaya
Command-line interface for email management
Stars: ✭ 1,715 (+4187.5%)
Mutual labels:  mail, email
ESP-Mail-Client
⚡️Arduino Mail Client Library to send, read and get incoming mail notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.
Stars: ✭ 78 (+95%)
Mutual labels:  mail, email
Core
Dovecot mail server
Stars: ✭ 540 (+1250%)
Mutual labels:  email, mail

Table of Contents

Postfwd GeoIP Botnet Block Plugin

This is a plugin to postfix firewall postfwd (also located on github) intended to block international spam botnets. International spam botnets are logging into hacked mail addresses via sasl login from multiple IP addresses based in usually more than 30 unique countries. After successful login, the hackers send spam from huge amount of unique IP addresses which circumvents traditional rate limits per IP address.

If you are interested in theory about how botnet spam works and motivation for creating this plugin, look at the blog on Medium.

If you are interested in how your users got their mail accounts hacked, check out bsdly blog about slow distributed brute force attack on SSH passwords, which also applies to pop3/imap logins Hail Mary Cloud.

Plugin Compatility Matrix

  • Release v1.21 works with postfwd1 and postfwd2 versions 1.XX (eg. 1.39) and higher minor versions.
  • Releases v1.30 and higher are compatible only with postfwd3 versions 2.XX.
  • master branch is compatible only with postfwd3 versions 2.XX.
  • Supported database backends are MySQL and PostgreSQL.

Running with Docker

Prebuilt ready-to-use Docker image is located on DockerHub and can be simply pulled by command:

# Postfwd3 tags
docker pull lirt/postfwd-anti-geoip-spam-plugin:latest
docker pull lirt/postfwd-anti-geoip-spam-plugin:v1.40
# Postfwd1, Postfwd2 tags
docker pull lirt/postfwd-anti-geoip-spam-plugin:v1.21

To run postfwd with geoip-plugin, run docker with configuration files mounted as volumes:

docker run \
    -v </absolute/path/to/anti-spam.conf>:/etc/postfwd/anti-spam.conf \
    -v </absolute/path/to/postfwd.cf>:/etc/postfwd/postfwd.cf \
    lirt/postfwd-anti-geoip-spam-plugin:latest

This will run postfwd2 or postfwd3 (based on docker tag) with default arguments, reading postfwd rules file from your mounted volume file postfwd.cf and using anti-spam configuration from your file anti-spam.conf.

Development and Prototyping with Docker

Complete development environment with postfwd, anti-spam plugin and mysql/postgresql database correctly configured together can be run with command docker-compose -f dev-compose-mysql.yml up or docker-compose -f dev-compose-postgresql.yml up from directory ./tests/.

Note for overriding postfwd arguments:

  • Most important arguments to run postfwd in Docker are --stdout and --nodaemon. These arguments configure postfwd to log into standard output and stay in foreground.
  • For running postfwd plugin, you also need to set argument --plugins <path-to-plugin> to correct location of plugin.

Installation

To install this plugin follow next steps:

  • Clone this repository.
  • Install dependencies according to chapter Dependencies.
  • Run script install.sh to install plugin into /etc/postfix/.
  • To load plugin to postfwd you must add argument --plugins <PATH TO PLUGIN> to postfwd command (or update it in /etc/default/postfwd).
  • Configure postfwd rules according to chapter Postfwd configuration.
  • Create database table with indexes using following SQL statements (database is created on plugin startup but indexes can not be).
CREATE TABLE IF NOT EXISTS postfwd_logins (
   sasl_username varchar(100),
   ip_address varchar(16),
   state_code varchar(4),
   login_count int,
   last_login timestamp
);
CREATE INDEX postfwd_sasl_client_state_index ON postfwd_logins (sasl_username, ip_address, state_code);
CREATE INDEX postfwd_sasl_username ON postfwd_logins (sasl_username);

Dependencies

  • Postfwd2 or Postfwd3.
  • Database (MySQL or PostgreSQL).
  • Perl modules - Geo::IP, DBI, Time::Piece, Config::Any, Net::Subnet, DBD::mysql or DBD::Pg.
  • GeoIP database located in /usr/local/share/GeoIP/GeoIP.dat.

Dependencies on RedHat based distributions

Install GeoIP, Time, Config, DBI and database modules with following command:

yum install -y 'perl(Geo::IP)' \
               'perl(Time::Piece)' \
               'perl(Config::Any)' \
               'perl(DBI)' \
               'perl(DBD::mysql)' \
               'perl(DBD::Pg)' \
               'perl(Net::Subnet)'

Dependencies on Debian based distributions

Install GeoIP, Time, Config, DBI and database modules with following command:

apt-get install -y libgeo-ip-perl \
                   libtime-piece-perl \
                   libconfig-any-perl \
                   libdbi-perl \
                   libdbd-mysql-perl \
                   libdbd-pg-perl \
                   libnet-subnet-perl \
                   geoip-database

Configuration

Plugin configuration file anti-spam.conf is INI style configuration file, in which values must NOT be quoted!

Postfwd configuration

Add following rules to postfwd configuration file postfwd.cf. You can use your own message and value of parameters:

  • client_uniq_country_login_count: Sets maximum number of unique countries to allow user to log in via sasl.
  • client_uniq_ip_login_count: Sets maximum number of unique IP addresses to allow user to log in via sasl.
# Anti spam botnet rule:
# This example shows how to limit e-mail address defined by `sasl_username`
# to be able to login from max. 5 different countries or 20 different IP
# addresses, otherwise it will be blocked from sending messages.

id=BAN_BOTNET_COUNTRY ;
   sasl_username=~^(.+)$ ;
   client_uniq_country_login_count > 5 ;
   action=rate(sasl_username/1/3600/554 Your mail account ($$sasl_username) was compromised. Please change your password immediately after next login.) ;

id=BAN_BOTNET_IP ;
   sasl_username=~^(.+)$ ;
   client_uniq_ip_login_count > 20 ;
   action=rate(sasl_username/1/3600/554 Your mail account ($$sasl_username) was compromised. Please change your password immediately after next login.) ;

Database backend configuration

Update configuration file /etc/postfix/anti-spam.conf with your credentials to selected database backend (tested with MySQL/PostgreSQL). Don't forget to use proper driver and port.

In case you use different path as /etc/postfix/anti-spam.conf and /etc/postfix/anti-spam-sql-st.conf to main configuration file, export environment variables POSTFWD_ANTISPAM_MAIN_CONFIG_PATH and POSTFWD_ANTISPAM_SQL_STATEMENTS_CONFIG_PATH with your custom path.

[database]
# driver = Pg
driver = mysql
database = test
host = localhost
# port = 5432
port = 3306
userid = testuser
password = password

Application configuration

The plugin is by default configured to remove records for users with last login date older than 24 hours. This interval can be changed in configuration app.db_flush_interval.

Plugin looks by default for GeoIP database file in path /usr/local/share/GeoIP/GeoIP.dat. You can override this path in configuration app.geoip_db_path.

You can whitelist set of IP addresses or subnets in CIDR format by using configuration setting app.ip_whitelist. Whitelisting means, that if client logs into email account from IP address, which IS in whitelist, it will NOT increment login count for this pair of sasl_username|client_address.

[app]
# Flush database records with last login older than 1 day
db_flush_interval = 86400
geoip_db_path = /usr/local/share/GeoIP/GeoIP.dat
# IP whitelist must be valid comma separated strings in CIDR format without whitespaces.
# It specifies IP addresses which will NOT be counted into user logins database.
ip_whitelist = 198.51.100.0/24,203.0.113.123/32
# ip_whitelist_path = /etc/postfwd/ip_whitelist.txt

Logging

Plugin is by default logging into standard output. This can be changed in configuration file by setting value for statement logfile in [logging] section.

You can disable logging completely by updating value of statement debug to 0 in section [debugging].

Example configuration of file anti-spam.conf:

[logging]
# Remove statement `logfile`, or set it to empty `logfile = ` to log into STDOUT
logfile = /var/log/postfwd_plugin.log
autoflush = 0

[debugging]
# Enable(1) or disable(0) logging
debug = 1
# Make log after exceeding unique country count limit
country_limit = 5
# Make log after exceeding unique ip count limit
ip_limit = 20

If you use logrotate to rotate anti-spam logs, use option copytruncate which prevents logging errors when log file is rotated.

Useful database queries

Located in separate README file DB-Queries.md.

Development and testing

Check for proper linting with perlcritic postfwd-anti-spam.plugin.

Change into directory ./test and execute docker-compose -f dev-compose-mysql.yml up or docker-compose -f dev-compose-postgresql.yml up to get postfwd and mysql/postgresql database up.

Send SMTP requests to postfwd policy server, or use testing script to check functionality:

# Manually send postfwd request
export CLIENT_ADDRESS='1.2.3.4'
export SASL_USERNAME='[email protected]'
nc 127.0.0.1 10040 < <(envsubst < dev-request)

# Run testing script
cd tests
DATABASES="mysql postgresql" RUN_COMPOSE=1 ./integration-compose-test.sh
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].