LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-24-2015, 12:23 PM   #1
w_hairst
LQ Newbie
 
Registered: Feb 2015
Posts: 19

Rep: Reputation: 0
sendmail login tarpit


I've been running a small (mostly just me!) mail/web/game server for years. I get a lot of login attempts on SMTP 25 (I'm running sendmail). On my server, the only legitimate use for logging in on port 25 is Webmail sending a message - and it logs in from/to localhost.

Is there a reasonably easy way to tarpit login attempts on port 25 that aren't coming from 127.0.0.1 / on the loopback interface, while leaving non-login (incoming) mail delivery alone?
 
Old 03-03-2015, 11:24 AM   #2
agentbuzz
Member
 
Registered: Oct 2010
Location: Texas
Distribution: Debian, Ubuntu, CentOS, RHEL
Posts: 131

Rep: Reputation: 25
You can't "log in" to a sendmail box on port 25. All you can do is connect to the sendmail daemon and issue commands that it understands.

Code:
user@sendmail ~]$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 sendmail.domain.com ESMTP Sendmail 8.14.4/8.14.8; Tue, 3 Mar 2015 10:53:47 -0600
ehlo x
250-sendmail.domain.com Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-STARTTLS
250-DELIVERBY
250 HELP
quit
Connection closed by foreign host.
Tarpitting is something you do to slow down spammers once they know sendmail is there. I think you mean you'd like to block some foreign IP space from even making a connection.
Here's one way of doing that:

Code:
#!/bin/bash
### Block all traffic from AFGHANISTAN (af) and CHINA (CN) and RUSSIA (RU). Use ISO code ###
ISO="af cn ru"

### Set PATH ###
IPT=/sbin/iptables
WGET=/usr/bin/wget
EGREP=/bin/egrep

### No editing below ###
SPAMLIST="countrydrop"
ZONEROOT="/root/iptables"
DLROOT="http://www.ipdeny.com/ipblocks/data/countries"

cleanOldRules(){
$IPT -F
$IPT -X
$IPT -t nat -F
$IPT -t nat -X
$IPT -t mangle -F
$IPT -t mangle -X
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD ACCEPT
}

# create a dir
[ ! -d $ZONEROOT ] && /bin/mkdir -p $ZONEROOT

# clean old rules
cleanOldRules

# create a new iptables list
$IPT -N $SPAMLIST

for c  in $ISO
do
        # local zone file
        tDB=$ZONEROOT/$c.zone

        # get fresh zone file
        $WGET -O $tDB $DLROOT/$c.zone

        # country specific log message
        SPAMDROPMSG="$c Country Drop"

        # get
        BADIPS=$(egrep -v "^#|^$" $tDB)
        for ipblock in $BADIPS
        do
           $IPT -A $SPAMLIST -s $ipblock -j LOG --log-prefix "$SPAMDROPMSG"
           $IPT -A $SPAMLIST -s $ipblock -j DROP
        done
done
You could put rules in your /etc/sysconfig/iptables, instead:

Code:
-A INPUT -s 182.61.0.0/16 -j LOG
-A INPUT -s 182.61.0.0/16 -j DROP
 
Old 03-04-2015, 07:09 AM   #3
w_hairst
LQ Newbie
 
Registered: Feb 2015
Posts: 19

Original Poster
Rep: Reputation: 0
When I said "log in", I was referring to SMPT AUTH - provide a username and password to get higher-than-nobody privileges, like sending outgoing mail. I get dozens or hundreds of AUTH attempts a day (once got 13,000+), and NONE are legitimate. The spammers/crackers know the server is there. Yes, I'd like to tarpit them, based on the fact that they are performing illegitimate AUTH attempts (any AUTH attempt is illegitimate here!). Since I don't necessarily know all countries where legitimate email is coming from, I don't want to block connections by country.

Summary - "login" meaning AUTH, and tarpit meaning tarpit.
 
Old 03-04-2015, 08:06 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by w_hairst View Post
When I said "log in", I was referring to SMPT AUTH - provide a username and password to get higher-than-nobody privileges, like sending outgoing mail. I get dozens or hundreds of AUTH attempts a day (once got 13,000+), and NONE are legitimate. The spammers/crackers know the server is there. Yes, I'd like to tarpit them, based on the fact that they are performing illegitimate AUTH attempts (any AUTH attempt is illegitimate here!). Since I don't necessarily know all countries where legitimate email is coming from, I don't want to block connections by country.

Summary - "login" meaning AUTH, and tarpit meaning tarpit.
You can use fail2ban to block repeating offenders IPs for a certain amount of time
 
Old 03-04-2015, 09:34 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
If the only "login" is from the local host, you could set the sendmail configuration to only listen on localhost, rather than the default of any network connection.

You can also use IP tables to just drop any connection to port 25 on any interface EXCEPT "lo".
 
Old 03-04-2015, 09:34 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
If the only "login" is from the local host, you could set the sendmail configuration to only listen on localhost, rather than the default of any network connection.

You can also use IP tables to just drop any connection to port 25 on any interface EXCEPT "lo".
 
Old 03-04-2015, 07:21 PM   #7
w_hairst
LQ Newbie
 
Registered: Feb 2015
Posts: 19

Original Poster
Rep: Reputation: 0
The tough part of the configuration is that it needs to accept incoming mail (addressed to accounts on this server) on port 25, while not permitting any AUTH attempt to succeed if it's not coming from localhost. I'm not positive that an AUTH command from localhost needs to be permitted - I'll have to look at SquirrelMail's requirements for outgoing mail.

Ideally I'd like to tarpit the illegitimate AUTH attempts, as an attempt to slow down the crackers. My second choice would be to simply not allow AUTH attempts on non-localhost connections.
 
  


Reply

Tags
login, sendmail, tarpit



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: GPLv2 goes to court: More decisions from the Versata tarpit LXer Syndicated Linux News 0 12-15-2014 02:12 PM
sendmail and dovecot login failed sunlinux Linux - Server 3 06-05-2011 07:19 AM
TARPIT and newer kernels felosi Linux - Security 25 05-10-2008 12:10 AM
Spam Tarpit Advice Needed jusme Linux - Server 4 11-16-2006 10:31 PM
explain honeypot and tarpit? servnov Linux - Networking 3 09-30-2004 07:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration