A modern SMTP honeypot designed to capture and log email-based attacks with database integration.
Mailoney is a low-interaction SMTP honeypot that simulates a vulnerable mail server to detect and log unauthorized access attempts, credential harvesting, and other SMTP-based attacks. This version (2.0.0) is a complete rewrite with modern Python packaging practices and database logging.
- π§ Simulates an SMTP server accepting connections on port 25
- π Captures authentication attempts and credentials
- πΎ Stores all session data in a database (PostgreSQL recommended)
- π³ Containerized for easy deployment via Docker
- π οΈ Modern, maintainable Python code base
- π Structured data for easy analysis and integration
Pull and run the container with a single command:
docker run -p 25:25 ghcr.io/phin3has/mailoney:latest
The most convenient way to run Mailoney with proper database persistence:
- Create a
docker-compose.yml
file:
version: '3.8'
services:
mailoney:
image: ghcr.io/phin3has/mailoney:latest
restart: unless-stopped
ports:
- "25:25"
environment:
- MAILONEY_BIND_IP=0.0.0.0
- MAILONEY_BIND_PORT=25
- MAILONEY_SERVER_NAME=mail.example.com
- MAILONEY_LOG_LEVEL=INFO
- MAILONEY_DB_URL=postgresql://postgres:postgres@db:5432/mailoney
depends_on:
- db
db:
image: postgres:15
restart: unless-stopped
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=mailoney
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
volumes:
postgres_data:
- Start the services:
docker-compose up -d
- View logs:
docker-compose logs -f mailoney
For development or customization:
# Clone the repository
git clone https://github.com/phin3has/mailoney.git
cd mailoney
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install the package in development mode
pip install -e .
# Run Mailoney
python main.py
Variable | Description | Default |
---|---|---|
MAILONEY_BIND_IP |
IP address to bind to | 0.0.0.0 |
MAILONEY_BIND_PORT |
Port to listen on | 25 |
MAILONEY_SERVER_NAME |
SMTP server name | mail.example.com |
MAILONEY_DB_URL |
Database connection URL | sqlite:///mailoney.db |
MAILONEY_LOG_LEVEL |
Logging level | INFO |
When running directly:
python main.py --help
Available arguments:
-i
,--ip
: IP address to bind to-p
,--port
: Port to listen on-s
,--server-name
: Server name to display in SMTP responses-d
,--db-url
: Database URL--log-level
: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Mailoney can use various SQL databases:
SQLite (simplest, for testing):
sqlite:///mailoney.db
PostgreSQL (recommended for production):
postgresql://username:password@hostname:port/database
MySQL/MariaDB:
mysql+pymysql://username:password@hostname:port/database
Mailoney creates two main tables:
-
smtp_sessions
: Stores information about each SMTP session- Session ID, timestamp, IP address, port, server name
- Full JSON log of the entire session
-
credentials
: Stores captured authentication credentials- Credential ID, timestamp, session ID, auth string
# Install test dependencies
pip install pytest pytest-cov
# Run tests
pytest
# Run tests with coverage
pytest --cov=mailoney
# Create a new migration
alembic revision --autogenerate -m "Description of changes"
# Apply migrations
alembic upgrade head
# Install build tools
pip install build
# Build the package
python -m build
mailoney/
βββ mailoney/ # Main package
β βββ __init__.py # Package initialization
β βββ core.py # Core server functionality
β βββ db.py # Database handling
β βββ config.py # Configuration management
β βββ migrations/ # Database migrations
βββ tests/ # Test suite
βββ main.py # Clean entry point
βββ docker-compose.yml # Docker Compose configuration
βββ Dockerfile # Docker configuration
βββ pyproject.toml # Package configuration
βββ ... other files
- Mailoney is a honeypot and should be deployed in a controlled environment
- Consider running with limited privileges
- Firewall appropriately to prevent misuse
- Regularly backup and analyze collected data
Mailoney stores all interaction data in the database. To integrate with SIEM or other security tools:
- Direct Database Integration: Connect your security tools to the PostgreSQL database
- Log Forwarding: Use a separate service to monitor the database and forward events
- API Development: Extend Mailoney to provide a REST API for data access
MIT License - See LICENSE file for details.
This project is a modernized rewrite of the original Mailoney by @phin3has.