Problem
People are telneting to port 25 of my Openserver machine and they are spamming or relaying mail through my system; how do I prevent this from happening?
Below is an example of how someone would do this: (lines with a * must be entered by user)
* # hostname
client.server.com
* # telnet mail.server.com 25
Trying 10.10.10.10...
Connected to mail.server.com.
Escape character is '^]'.
220 mail.server.com ESMTP Sendmail 8.11.0/SCO5 ready at Thu,
19 Jul 2001 08:33:44 -0700 (PDT)
* HELO client.server.com
250 mail.server.com Hello user@client.server.com [10.10.10.11],
pleased to meet you
* MAIL FROM:<nobody@somewhere.com>
250 2.1.0 <nobody@somewhere.com>... Sender ok
* RCPT TO:<user@anywhere.com>
250 2.1.0 <user@anywhere.com>... Recipient ok
* DATA
354 Enter mail, end with "." on a line by itself
* <message>
* <message>
* .
250 JAA02400 Message accepted for delivery
* quit
221 client.server.com closing connectionThe above example would send an email to user@anywhere.com. This email would appear to come from a user named nobody@somewhere.com, which does not exist.
Cause
Port 25 is the standard port that email is sent and received. Someone can telnet directly to this port and, with a series of commands, they can send mail from my machine to anywhere on the internet; hiding the return email address. This address may not even exist. This is called spam mail, because the return address of the email is not valid according to DNS name resolution.
Solution
The first step to configure a more secure email server is to upgrade
to Sendmail 8.11.0. This is wrapped up in rs506a, which can be
obtained here:https://ftp.scoexpert.com/openserver5/rs506a/rs506a.tarNOTE: Sendmail version 8.11.0a was release in the security supplement
CSSA-2003-SCO.6, available at:https://ftp.scoexpert.com/updates/OpenServer/CSSA-2003-SCO.6After Sendmail 8.11.0 is installed properly, the configuration may begin. The notes for how to do this are documented in /usr/lib/mail/antispam/README.spam.
Using your favorite editor, edit the /usr/lib/sendmail.cf file. An example of what your file should look like will be at the end of this article.
NOTE: mkdev cf cannot do this.1. Be sure the Scheck_rcpt, Parse0 and matchvdom rulesets are
uncommented. Also, the line with the Krelays rule must be
uncommented as well. In OpenServer 5.0.6, these lines are
uncommented by default.With these lines uncommented and the rulesets in place, Sendmail
will reject any mail that attempts to relay through this machine.
If you want specific machines to be able to relay through this
machine, as in Windows clients with Outlook or Netscape mailers,
you must add them to the /usr/lib/mail/antispam/relays file. In
this file, you should have the fully qualified domain name or the
IP address with a <TAB> and an OK. As in:10.10.10.101 OKIf this file has been altered, you will need to rebuild the relays map.
# cd /usr/lib/mail/antispam
# makemap hash relays < relaysNOTE: this is documented in the /usr/lib/mail/antispam/relays file itself.
2. Make sure the Kspammers line and the Scheck_mail lines are uncommented. This ruleset will reject any mail where the FROM: address does not have a fully qualified domain name (using DNS lookups).
To reject specific sites that do have a valid DNS resolution,
insert them into the /usr/lib/mail/antispam/spammers file. Add
the fully qualified domain name or the IP address with a <TAB>
and an error message as in:hostname.domain.com Mail rejected, your domain has been
rejected by our server.If the spammers file has been edited, you must reload the map so that sendmail can use it:
# cd /usr/lib/mail/antispam
# makemap hash spammers < spammersNOTE: this is documented in the /usr/lib/mail/antispam/spammers file itself.
3. Restart Sendmail:# cd /etc/rc2.d
# ./P86sendmail stop
# ./P86sendmail startSUMMARY: 1. Uncomment the lines in your sendmail.cf file as shown
below.2. Add systems that you wish to use this server for email to your /usr/lib/mail/antispam/relays file.
a) If your relays file was altered, run the command:
# makemap hash relays < relays3. Add domains that you wish to reject mail from, regardless of whom it is to or from, into your /usr/lib/mail/antispam/spammers file.
a) If your spammers file was altered, run the command:
# makemap hash spammers < spammers4. Restart Sendmail:# cd /etc/rc2.d
# ./P86sendmail stop
# ./P86sendmail startTO TEST: Telnet to the machine on Port 25, and attempt to hide the email address, as shown below: (lines with a * must be entered by the user)
* # hostname
client.server.com
* # telnet mail.server.com 25
Trying 10.10.10.10...
Connected to mail.server.com.
Escape character is '^]'.
220 mail.server.com ESMTP Sendmail 8.11.0/SCO5 ready at Thu,
19 Jul 2001 08:33:44 -0700 (PDT)
* HELO client.server.com
250 mail.server.com Hello user@client.server.com
[10.10.10.11],
pleased to meet you
* MAIL FROM:<nobody@somewhere.com>
250 2.1.0 <nobody@somewhere.com>... Sender ok
* RCPT TO:<user@anywhere.com>
250 2.1.0 <user@anywhere.com>... Relaying DeniedIf you see the "Relaying Denied" message, you are successful.
##################################################################
# Anti-spam section See /usr/lib/mail/antispam/README.spam
# for a complete description
#
# The relays map is used by the check_rcpt ruleset
Krelays hash -om -a.RELAY /usr/lib/mail/antispam/relays
#
# The spammers map is used by the check_relay or check_mail rulesets
Kspammers hash -om /usr/lib/mail/antispam/spammers
#
##################################################################
Scheck_rcpt# reformat address passed to rule (recipient address)R$+ $: $>3 $1
R$+ % $+ < @ $* > $* $: <ROUTEADDR>
R$+ % $+ < @ $* . > $* $: <ROUTEADDR>
R$* $: $>Parse0 $1
R$+ < @ $* . > $* $: $1 < @ $2 >
R$+ < @ $* > $* $: $1 < @ $2 ># if it terminates locally, it is okR$+ < @ $=w > $@ OK# if it terminates in the domain of this system (we are am MX for $D, for
# example, then it is okR$+ < @ $D > $@ OK# if it terminates in a subdomain of $D, then it should be ok tooR$+ < @ $+.$D > $@ OK# if it terminates in the special case of an entry in class FR, then
# we are ok tooR$+ < @ $=R > $@ OK
R$+ < @ $+.$=R > $@ OK# if it terminates in a virtual domain served by this system
# (created by the SCO Internet Manager), then it should be ok too
# Uncomment this section only if you are using virtual domains
# as defined by the SCO Internet ManagerR$+ < @ $+ > $: $1 < @ $2 > $| $>matchvdom $2
R$+ $| OK $@ OK
R$+ $| NOTOK $: $1# parse out the client address and name of who connectedR$+ $: $(dequote "" $&{client_addr} $)
R$* $: $1 $| $(dequote "" $&{client_name} $)# no client address means local which is okR$| $* $@ OK# check for client name against self and domainR$* $| $=w $@ OK
R$* $| $D $@ OK
R$* $| $+.$D $@ OK# check client name against allowed relays mapR$* $| $* $: $1 $| $(relays $2 $: $2 $)
R$* $| $+.RELAY $@ OK# check for client address against allowed relays mapR$* $| $* $: $(relays $1 $: $1 $) $| $2
R$+.RELAY $| $* $@ OK# allow client names as virtual domains as defined by Inet Mgr.R$* $| $* $: $1 $| $2 $| $>matchvdom $2
R$* $| $* $| OK $@ OK
R$* $| $* $| NOTOK $: $1 $| $2# anything else is probably an invalid relay. rejectR$* $#error $: "550 Relaying Denied"#################################################################
SParse0
R<@> $#local $: <@> special case error msgs
R$* : $* ; <@> $#error $@ 5.1.3 $: "list:; syntax illegal for
recipient addresses"
R<@ $+> $#error $@ 5.1.1 $: "user address required"
R$* $: <> $1
R<> $* < @ [ $+ ] > $* $1 < @ [ $2 ] > $3
R<> $* <$* : $* > $* $#error $@ 5.1.1 $: "colon illegal in host name
part"
R<> $* $1
R$* < @ . $* > $* $#error $@ 5.1.2 $: "invalid host name"
R$* < @ $* .. $* > $* $#error $@ 5.1.2 $: "invalid host name"# handle numeric address spec
R$* < @ [ $+ ] > $* $: $>98 $1 < @ [ $2 ] > $3 numeric internet
spec
R$* < @ [ $+ ] > $* $#esmtp $@ [$2] $: $1 < @ [$2] > $3 still
numeric: send# now delete the local info -- note $=O to find characters that cause
# forwardingR$* < @ > $* $@ $>Parse0 $>3 $1 user@
# => user
R< @ $=w . > : $* $@ $>Parse0 $>3 $2 @here:... -> ...
R$- < @ $=w . > $: $(dequote $1 $) < @ $2 . > dequote "foo"@here
R< @ $+ > $#error $@ 5.1.1 $: "user address required"
R$* $=O $* < @ $=w . > $@ $>Parse0 $>3 $1 $2 $3 ...@here -> ...
R$- < @ $=w . > $: $(dequote $1 $) < @ $2 . > dequote "foo"@here
R< @ $+ > $#error $@ 5.1.1 $: "user address required"
R$* $=O $* < @ $=w . > $@ $>Parse0 $>3 $1 $2 $3 ...@here -> ...#############################################################################Smatchvdom
R$+ $: $(pop $1 $: $1 $)
R$+.POP $@ OK
R$-.$+ $: $>matchvdom $2
ROK $@ OK
R$* $@ NOTOK#############################################################################Scheck_mail
R$* $: <?> $>3 $1 make domain canonical
R<?> $* < @ $+ . > $: <?> $1 < @ $2 > strip dot
R<?> $* < @ $+ > $: <?> $1 < @ $[ $2 $] > see if name resolves
R<?> $* < @ $+ . > $: <OK> name resolved just fine
R<?> $* < @ $+ > $#error $: 451 Domain must resolve# check remote host against spammers database
R$* $: $(spammers $&{client_name} $: $1.<OK> $)
R$*.<OK> $: $(spammers $&{client_addr} $: <OK> $)
R<OK> $@ OK
R$+ $#error $: 551 $1