Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do...

102
1/102 Back Close Sendmail Greg Baker – [email protected]

Transcript of Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do...

Page 1: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

1/102

JJIIJI

Back

Close

SendmailGreg Baker – [email protected]

Page 2: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

2/102

JJIIJI

Back

Close

Some sendmail History

Page 3: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

3/102

JJIIJI

Back

Close

What is sendmail?

• The main mail transfer agent on the in-ternet

• First release called “sendmail” in 1983.• Is the default mail service on most ver-

sions of Unix

Page 4: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

4/102

JJIIJI

Back

Close

Sendmail’s good features

• handles high loads well• is extremely configurable to handle legacy

protocols

Page 5: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

5/102

JJIIJI

Back

Close

Sendmail’s bad features

• had an administrator-unfriendly config-uration file

• a history of security problems• a lot of legacy influences

Page 6: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

6/102

JJIIJI

Back

Close

Sendmail versions

v8.9 anti-spamv8.10 Mail filter APIv8.11 LDAP, SMTP authentication, trans-

port securityv8.12 no longer SUID root

Page 7: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

7/102

JJIIJI

Back

Close

What version am I running?

• telnet localhost 25

• echo ’$Z’ |/usr/sbin/sendmail -bt-d0

Page 8: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

8/102

JJIIJI

Back

Close

Exercise

What version are you running?

Page 9: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

9/102

JJIIJI

Back

Close

On the wire protocols

Page 10: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

10/102

JJIIJI

Back

Close

Method 1: Message Injection Protocol

•Runs on port 587•Can do authentication of the end user•Message may get rewritten•Documented in rfc2476•Otherwise, same as Method 2•New (v8.11) – rarely used.

Page 11: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

11/102

JJIIJI

Back

Close

Method 2: SMTP on port 25

•Greet with HELO•Announce the sender with MAIL FROM:• Say who should receive it with RCPT

TO:• Send email body after DATA• Finish with .• Terminate with QUIT

Page 12: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

12/102

JJIIJI

Back

Close

Odd things about SMTP

1. The From: field in the DATA doesn’thave to match the MAIL FROM

2. Neither does To: have to match RCPTTO

3. None of the header fields need to exist.

Page 13: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

13/102

JJIIJI

Back

Close

Exercise

Talking SMTP manually. . .

Page 14: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

14/102

JJIIJI

Back

Close

How spooled e-mail gets delivered

• The mail server does a DNS lookup forMX records for the domain name

• It gets several names back, each with apriority number

• Try delivering to the smallest number• If it fails, it tries the next lowest• If everything fails, try again later.•Warn after 4 hours. Give up after 4 days.

Page 15: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

15/102

JJIIJI

Back

Close

Exercise

Walking through the lookup process. . .

Page 16: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

16/102

JJIIJI

Back

Close

The configuration file

Page 17: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

17/102

JJIIJI

Back

Close

sendmail.cf

•Only read at startup/SIGHUP time• Solaris /etc/mail/sendmail.cf

HP-UX /etc/mail/sendmail.cf

*BSD /etc/mail/sendmail.cf

Linux /etc/sendmail.cf

• Some versions of Unix still “freeze” it toa sendmail.fc

Page 18: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

18/102

JJIIJI

Back

Close

Configuration file format

• 14 different options•Blank lines•Comments begin with “#”• Lines beginning with tab carry on from

the previous line.

Page 19: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

19/102

JJIIJI

Back

Close

Some easy things to change

DS A smart relay hostDM What domain to masquerade asDj My hostnameO SmtpGreetingMessage What banner to

give on connection.

Page 20: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

20/102

JJIIJI

Back

Close

Exercise

Modifying the sendmail configuration file. . .

Page 21: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

21/102

JJIIJI

Back

Close

Rewriting Rules

Page 22: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

22/102

JJIIJI

Back

Close

What is a ruleset?

•A “subroutine” for rewriting an address•Can get applied to a source address•Can get applied to a destination address•Can get called from other rulesets•Order doesn’t matter• Is defined by Snameand then lots of R...

lines

Page 23: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

23/102

JJIIJI

Back

Close

What import rule sets are there?canonify=3 All addresses

Parse=0 How to send?

1 Process sender address

2 Process recipient address

final=4 Postprocess all addresses

localaddr=5 Rewrite unaliased

check relay, check mail, check rcpt, check compat Is this sender allowedto go to this recipient through our machine?

Page 24: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

24/102

JJIIJI

Back

Close

Rewrites rule OK1. Rleft hand side tokens tab replacements

2. Rleft hand side tokens tab $: replacements

3. Rleft hand side tokens tab $@ final result

4. Rleft hand side tokens tab $# delivery mechanism, host and user

Page 25: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

25/102

JJIIJI

Back

Close

Things on the left hand side

$| Meta-separator$* Match zero or more tokens$+ Match one or more tokens$- Exactly one token$=x Match any phrase in class x

$˜x Match any word not in class x

$@ Match nothing

Page 26: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

26/102

JJIIJI

Back

Close

Things on the right hand side

$n The nth thing that was matched on theleft

$[name$] Canonicalize name$(map key $@arguments $:default $) Find

key in map, otherwise default$>n Call ruleset n with the rest of the lineLetters, symbols, numbers, $| Just sub-

stitute it

Page 27: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

27/102

JJIIJI

Back

Close

More things on the right hand side

Extra TAB Everything following is a com-ment

$#mechanism $@ host $: user Only in rule-set 0 or check rcpt or similar

$#error $@ number $: error string Die withthe error given (including SMTP errorcode number)

Page 28: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

28/102

JJIIJI

Back

Close

Example Ruleset

Sappend domainname

R$@ tab $#error $@ 5.7.1 $: "550 Arrgh"

R$* @ $* tab $@ $1 @ $2

R$* tab $: $1 @ ifost.org.au

Page 29: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

29/102

JJIIJI

Back

Close

How to testsendmail -btADDRESS TEST MODE (ruleset 3 NOT automatically invoked)Enter <ruleset > <address >> append domainname gregbappend domainnam input: gregbappend domainnam returns: gregb @ ifost . org . au

Page 30: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

30/102

JJIIJI

Back

Close

Exercises

Making your own rewrites. . .

Page 31: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

31/102

JJIIJI

Back

Close

Classes and Maps

Page 32: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

32/102

JJIIJI

Back

Close

Class definitions

•CM

•Cw localhost loghost

• FR-o /etc/mail/relay-domains

Page 33: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

33/102

JJIIJI

Back

Close

Some examples

From Canonify2=96 :R$* < @ $=M> $* tab $: $1 < @ $2 . > $3

From Relay okR$=R $* tab $@ RELAY tab relayable IP address

Page 34: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

34/102

JJIIJI

Back

Close

Other class tricks

• FL/etc/passwd %[ˆ:]

• Fg |/some/program

Page 35: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

35/102

JJIIJI

Back

Close

Exercise

Playing with classes. . .

Page 36: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

36/102

JJIIJI

Back

Close

Problems with classes

•Only read at sendmail startup time•Can only copy unchanged to the the right

hand side•A little inflexible

Page 37: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

37/102

JJIIJI

Back

Close

What is a map?

A lookup from something to something else:

• a username → GECOS field•Query DNS, NIS/NIS+ or LDAP• Find an entry in a flat file or indexed file•A regular expression•Run a program with an argument

Page 38: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

38/102

JJIIJI

Back

Close

How do I use a hash map?

1. Create a text file myfile

2. Make a hash from it /etc/stuff

3. Put Kmyhash /etc/stuff in sendmail.cf

4. Make a rule R$* tab $(myhash $1 $)

Page 39: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

39/102

JJIIJI

Back

Close

Exercise

Making and using simple hash maps. . .

Page 40: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

40/102

JJIIJI

Back

Close

Common special flags

-ax append x for successful matches-Tx append x for temporary failures-o Optional-h,-b LDAP server hostname / basename

Page 41: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

41/102

JJIIJI

Back

Close

Classy maps

• F{VirtHosts}@ldap:-k (&(objectClass=virtHosts)(host=*))-v host

• F{MyClass}foo@hash:/etc/mail/classes

Page 42: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

42/102

JJIIJI

Back

Close

Delivery Mechanisms

Page 43: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

43/102

JJIIJI

Back

Close

M sent me

Mprocmail, Path=/usr/local/bin/procmail,Flags=mSDFMhun, S=11, R=21, Argv=procmail-m $h $g $u

Page 44: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

44/102

JJIIJI

Back

Close

Flags

•Expand aliases?•Hidden dot method?• “/” means file or X500?•Email addresses with comments?

Page 45: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

45/102

JJIIJI

Back

Close

Special mailers

local Delivery locallyerror Refuse to senddiscard Silently drop the messageprog Deliver via program*file* Deliver to a filesmtp/esmtp/smtp8/esmtp8 TCP protocolsrelay Forward to something elseprocmail Delivery via procmail

Page 46: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

46/102

JJIIJI

Back

Close

Message flow Part 1

•Recipient address tidied by ruleset 3

•Remember this tidy result•Which mailer to use from ruleset 0

• . . .

Page 47: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

47/102

JJIIJI

Back

Close

Message flow Part 2

• Send the tidy address through 2

• Send the result through the delivery agent’sR= ruleset

•Ruleset 4

Page 48: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

48/102

JJIIJI

Back

Close

Message Flow Part 3

Take the sender address through rulesets:• 3

• 1

• The delivery agent’s S= ruleset• 4

Page 49: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

49/102

JJIIJI

Back

Close

Message Flow Part 4

Check flags (F=) on mailer:

• A flag? Check recipient /etc/mail/aliases.db

• 5 flag and alias didn’t work? Try ruleset5

•w flag? Try recipient .forward file

Run the mailer!

Page 50: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

50/102

JJIIJI

Back

Close

About aliases

•Normally in /etc/mail/aliases.db

• In DBM format (usually)•Created by running newaliases man-

ually• newaliases reads from /etc/mail/aliases

• Should redirect postmaster and any sys-tem accounts.

Page 51: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

51/102

JJIIJI

Back

Close

Exercises

Confusing users terribly. . .

Page 52: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

52/102

JJIIJI

Back

Close

Oddities

Page 53: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

53/102

JJIIJI

Back

Close

Forwarding

• ForwardPath

•Normally just $z/.forward

•Consider /var/mail/forwards/$z

•Checks for stale NFS

Page 54: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

54/102

JJIIJI

Back

Close

Non-standard delivery

/etc/mail/aliases and .forward cancontain:• \user• |program• /some/file

• :include:/some/file• Local addresses•Remote addresses

Page 55: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

55/102

JJIIJI

Back

Close

Fun ideas

• ForwardPath =$z/.forward.$w

• ForwardPath =$z/.forward.$s

• somealias+extra: |program

• somealias+*: /else/where2

• owner-list: root

Page 56: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

56/102

JJIIJI

Back

Close

Vacation

• Program for auto-responding to emails•Run from .forward

• Looks for a file (with headers) called .vacation.msg

•Will reply only once per address per week•Keeps track in .vacation.db

Page 57: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

57/102

JJIIJI

Back

Close

Exercises

Mailing lists and missing users

Page 58: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

58/102

JJIIJI

Back

Close

Header rewriting

Page 59: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

59/102

JJIIJI

Back

Close

Why modify headers?

•Because RFC822 demands it• To include disclaimers• To flag possible spam• To reject messages

Page 60: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

60/102

JJIIJI

Back

Close

A simple header addition

HX-Our-Extra-Stuff: Flumph gloop

HX-Long-Stuff: Garble warble

tab farble

Page 61: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

61/102

JJIIJI

Back

Close

Exercise

Add in your own header. . .

Page 62: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

62/102

JJIIJI

Back

Close

Headers and macros

•HX-Size: ${msg size }•HX-Received-Using: $?rProto $r$.

Page 63: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

63/102

JJIIJI

Back

Close

Conditional headers

•H?x?Full-Name: $x

• Is x in the flags of the mailer handlingthis message?

Page 64: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

64/102

JJIIJI

Back

Close

Exercise

Flags and headers

Page 65: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

65/102

JJIIJI

Back

Close

Complaining about headers

HMessage-Id: $ >CheckMsgId

. . .

SCheckMsgId

R< $+ @ $+ > tab $@ OK

R$* tab $#error $: 553 Header Err

Page 66: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

66/102

JJIIJI

Back

Close

Exercise

Enabling simple censorship. . .

Page 67: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

67/102

JJIIJI

Back

Close

Simplifying everything

Page 68: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

68/102

JJIIJI

Back

Close

Don’t edit sendmail.cf !

• Find your .mc files•Change it•Rerun m4

•Restart/HUP sendmail

Page 69: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

69/102

JJIIJI

Back

Close

A simple .mc file

VERSIONID(‘Client -- sends mail elsewhere’)

OSTYPE(openbsd)

FEATURE(‘nullclient’,‘mailhub.ifost.org’)

Page 70: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

70/102

JJIIJI

Back

Close

Exercise

Autogenerating .cf files . . .

Page 71: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

71/102

JJIIJI

Back

Close

Things in a .mc file

VERSIONID Turns into a comment in sendmail.cf

OSTYPE Where files are foundFEATURE Turn on somethingdefine Set a configuration optiondnl Delete to end of newline (comment)MASQUERADE AS

Page 72: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

72/102

JJIIJI

Back

Close

VERSIONID

•Usually $RCS: rcs id$

•Can be anything•Becomes a comment•Keep in quotes ‘ and ’

Page 73: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

73/102

JJIIJI

Back

Close

OSTYPE

•Essential•Defines where files go•Not all operating systems defined• Look in ostype for complete list

Page 74: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

74/102

JJIIJI

Back

Close

Famous FEATURES

use cw file Read an /etc/mail/local-host-names

redirect Control users who have movedvirtusertable Handle virtual domainslocal procmail Use procmail as a local

mailerdnsbl Stop known spammers

Page 75: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

75/102

JJIIJI

Back

Close

MASQUERADING

•MASQUERADE AS(‘company.com‘)•MASQUERADE DOMAIN(‘oldcompanyname.com‘)•MASQUERADE DOMAIN FILE(‘filename‘)

Page 76: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

76/102

JJIIJI

Back

Close

A better example

VERSIONID(‘A genuine configuration’)OSTYPE(openbsd)FEATURE(nouucp, ‘reject’)FEATURE(virtusertable)FEATURE(‘masquerade envelope’)MAILER(local)MAILER(smtp)MASQUERADE AS(‘ifost.org.au’)

Page 77: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

77/102

JJIIJI

Back

Close

Exercise

Real-life .mc files

Page 78: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

78/102

JJIIJI

Back

Close

Tweaking Rulesets

•Rulesets 0 - 5 call “local” rulesets• “Local” rulesets can be modified•Use the name of the main ruleset

Page 79: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

79/102

JJIIJI

Back

Close

LOCAL CONFIG

• Introducing other classes or maps . . .

Page 80: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

80/102

JJIIJI

Back

Close

Exercise

A sense of deja vu. . .

Page 81: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

81/102

JJIIJI

Back

Close

Configuration Options

confPRIVACY FLAGS Allow EXPN, VRFY?confSMTP LOGIN MSG Option SmtpGreetingMessage

confMIN FREE BLOCKS Full filesystem– stop receiving mail!

confMAX MESSAGE SIZE Defaults to in-finite

confMATCH GECOS From /etc/passwd

Page 82: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

82/102

JJIIJI

Back

Close

MAILERS

You probably want:•MAILER(local)•MAILER(smtp)

Page 83: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

83/102

JJIIJI

Back

Close

DOMAINS

• For big sites only•Centralises names for relay servers•Not necessary at all

Page 84: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

84/102

JJIIJI

Back

Close

Reducing SPAM

Page 85: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

85/102

JJIIJI

Back

Close

Statistics for my servers

1078 Total rejected messages147 HELO failures269 Non-existant domains469 Common invalid mailboxes190 Other non-existant names

2 Yahoo oddity1 Misconfiguration

Page 86: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

86/102

JJIIJI

Back

Close

What sendmail does automatically

•Reject unresolvable domains•Reject unqualified names (user, but no

domain)•Reject invalid HELOs

Page 87: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

87/102

JJIIJI

Back

Close

Blacklists

•A DNS domain•Keeps track of IP addresses that send

SPAM•Many organisations maintain blacklists

Page 88: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

88/102

JJIIJI

Back

Close

Using a blacklist manually

•You get a connect from IP address A.B.C.D

• Look up the A record for D.C.B.A. relays.ordb.org• If you get a response – it’s a SPAM do-

main, see TXT record for the reason• If you don’t get a response, it’s not a known

spammer

Page 89: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

89/102

JJIIJI

Back

Close

Very quick blacklist exercise

Slightly contrived, but helpful

Page 90: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

90/102

JJIIJI

Back

Close

Lists I use / have used

Subdomain Purposerelays.ordb.org Open relay serversopm.blitzed.org Open proxieslists.dsbl.org Unsecure serversspl.spamhaus.org Known spammerscbl.abuseat.org Worms, trojans, etc.

Page 91: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

91/102

JJIIJI

Back

Close

Configuring

• FEATURE(‘dnsbl’)• FEATURE(‘dnsbl’,’relays.ordb.org’)• FEATURE(‘dnsbl’,’opm.blitzed.org’, ‘”451

Temporarily rejected from proxy list”’)

Page 92: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

92/102

JJIIJI

Back

Close

More information

The whole scoop from cf/README

Page 93: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

93/102

JJIIJI

Back

Close

Anti-spam exercises

Using a blacklist

Page 94: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

94/102

JJIIJI

Back

Close

Integration with other ser-vices

Page 95: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

95/102

JJIIJI

Back

Close

IMAP, POP – Plan 1

• sendmail delivers into /var/mail filesor equivalent

• POP/IMAP server needs to read from there•Both WU-IMAP and Dovecot can do this•Run imapd and/or pop3d from inetd

Page 96: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

96/102

JJIIJI

Back

Close

Plan 1 problems

• imapd has to re-read and re-write theuser’s whole mail file.

•No support for folders• Still OK for pop3d though.

Page 97: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

97/102

JJIIJI

Back

Close

IMAP, POP – Plan 2

•Deliver via procmail into a maildir•Use courier-imap and courier-pop3d

Page 98: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

98/102

JJIIJI

Back

Close

Web-based mail

• IMP or many alternatives.• Talks to IMAP server

Page 99: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

99/102

JJIIJI

Back

Close

Exercises

Just a quick demonstration of integration. . .

Page 100: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

100/102

JJIIJI

Back

Close

Milters

Page 101: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

101/102

JJIIJI

Back

Close

What is a milter?

•A filter for mail•Every message gets sent through all mil-

ters•Can do virus or spam checks•Connected to sendmail via sockets

Page 102: Sendmail - IFOST · Method 1: Message Injection Protocol •Runs on port 587 •Can do authentication of the end user •Message may get rewritten •Documented in rfc2476 •Otherwise,

102/102

JJIIJI

Back

Close

How to use milters

• InputMailFilters gives order• X configuration line