Home > Articles > Security > Network Security

Notable Features of Postfix to Keep You Secure

Almost all mail transfer agents offer some form of security to help protect your system and your mail users from the growing number and types of attacks on the Internet today. What makes Postfix different from many of the others is that security is designed in as one of the basic tenets, not as an add-on afterthought.

This upfront prioritization of security allows you to configure Postfix so that it is not only possible to put some preventative measures in place, but to make it easy to do so. Sendmail is capable of just about any sort of manipulation of email imaginable; the problem is learning enough of Sendmail's internals and configuration syntax directives to get it to perform. Let's take a quick look at how Sendmail and Postfix can be configured to protect against a common problem facing our Windows email clients today—Internet worms.

Turning Away the Worm

To simplify this comparison, we will make use of the notorious LoveLetter worm that compromised thousands of corporations, universities, and other organizations last year. Many virus and worm-detection techniques depend on identifying specific characteristics that uniquely identify the infected carriers from otherwise normal email traffic. These characteristics, collectively known as signatures, are commonly used by virus detection software and in mail and Web proxy servers to shield the targeted user base.

In the LoveLetter worm example, one of the signature attributes was the use of the phrase "ILOVEYOU" in the Subject line of an infected email message. A simplistic preventative measure then would be to scan all inbound email message headers for a Subject line that contains "ILOVEYOU".

Blocking Using Sendmail

Sendmail's configuration file, sendmail.cf, normally looks like line noise to the uninitiated. A much simpler method of configuring Sendmail is via the sendmail.mc macro configuration file, which generates a usable sendmail.cf configuration file using the m4 macro processor. Carefully adding the following text to your sendmail.mc will stop the transmission and spread of the LoveLetter worm.

LOCAL_RULESETS
HSubject:      $>Check_Subject
D{MPat}ILOVEYOU
D{MMsg}This message may contain the LoveLetter virus.

SCheck_Subject
R${MPat} $*     $#error $: 550 ${MMsg}
RRe: ${MPat} $*    $#error $: 550 ${MMsg}

Why do you need to be careful? Why couldn't you just cut and paste the above into your sendmail.mc and be done with it? Sendmail is quite picky about the format of its configuration file, and specifically about the rewriting rulesets (the lines above that begin with R). Specifically, you cannot use spaces between the $* and $#, you must use TABs; otherwise, you will generate an invalid Sendmail rule.

Now, let's play the real world catch-up game of virus and worm signatures. Shortly after we protect our users from the LoveLetter worm, we find out that there is a new variant that uses a different subject. The new signature attribute is "Important message from" in the Subject line.

What steps do we need to do to protect our Windows users? What do you would need to add to your sendmail.mc LOCAL_RULESET? First, add the new D defines and R rules to catch the variant to your sendmail.mc file. The modified sendmail.mc would then look like the following:

LOCAL_RULESETS
HSubject:      $>Check_Subject
D{MPat}ILOVEYOU
D{MPat2}Important message from
D{MMsg}This message may contain the LoveLetter virus.

SCheck_Subject
R${MPat} $*     $#error $: 550 ${MMsg}
RRe: ${MPat} $*    $#error $: 550 ${MMsg}
R${MPat2} $*     $#error $: 550 ${MMsg}
RRe: ${MPat2} $*    $#error $: 550 ${MMsg}

Next, you would need to convert your sendmail.mc file to a usable sendmail.cf file by passing it through the m4 macro processor, test the new sendmail.cf configuration, and finally move this new configuration into place permanently.

This is a complex, multistep process that has several opportunities to introduce errors. Or undo configuration changes made directly to the sendmail.cf rather than incorporated into the sendmail.mc file. And this does not scale well to multiple mail servers. Let's examine how this is accomplished using Postfix.

Blocking Using Postfix

Postfix is modular in nature, and that is reflected in the configuration file design as well. There are several core configuration files that govern how Postfix operates, and additional external mapping type files can be specified within those core configuration files.

The main configuration file for Postfix is named, conveniently enough, mail.cf. The main.cf configuration file has quite a bit of documentation built in to help explain some of the features and configuration options available. The feature we are concerned with, in our LoveLetter worm example, is scanning the email header Subject line. So in the /etc/postfix/main.cf file, add the following line:

header_checks = regexp:/etc/postfix/header_checks

The header_checks directive instructs Postfix to check the header of each email message using regular expressions contained in the external file /etc/postfix/header_checks. By referencing an external file, we can then add or remove patterns to that without having to restart Postfix.

We can now maintain the external /etc/postfix/header_checks file independently of the configuration. Simply add the following line:

/^Subject:.*ILOVEYOU/ REJECT

We now have the same protection that the previous Sendmail example affords our Windows user base. Adding additional signatures to catch new variants of the LoveLetter worm now just requires a new line in the header_checks file:

/^Subject:.*Important message from/	REJECT

There are several key points here:

  • Virus and worm signatures are kept in an external file, independent of the Postfix configuration. This allows for easy centralized management of multiple mail servers by just pushing out the updated and tested header_checks file. None of the Postfix processes need to be stopped or restarted, and no configuration files need to be rewritten or reloaded.

  • Postfix patterns use industry-standard POSIX 1003.2 regular expressions, or Perl Compatible Regular Expressions. This allows a broad reuse and application of practical knowledge. Regular Expressions can be applied to any number of applications, from text editors such as vi, shell scripts, normal UNIX utilities, scripting languages such as Perl and Python, and Web servers such as Apache. Learning Sendmail rewriting rules has no other application.

  • The simplified configuration file and pattern maps allow for a lower barrier to maintenance. In the long term, this reduces both the possibility of introducing errors and the overall cost of operations.

So how can Postfix be used to stop newer, more devious worms and virii embedded in email attachments? Postfix has an additional feature to allow scanning of message bodies.

Blocking Using Postfix Body Checks

The header_checks directive instructs Postfix to check the message headers for a particular pattern. The complimentary body_checks directive will configure Postfix to check the body of the message. The body of an email is normally where the MIME attachments are that carry the worm and virus payloads. To enable body checks, just edit the /etc/postfix/main.cf, and add the following line:

body_checks = regexp:/etc/postfix/body_checks

Then in the /etc/postfix/body_checks file, add the following line:

/^(.*)name="?(.*)\.(bat|chm|cmd|com|eml|exe|hta|js|jse|lnk|pif|scr|shs|vbs|vbe|vxd)"?(.*)$/ REJECT

The above might look a little complex, but in reality it is just a common POSIX 1003.2 regular expression, compatible with many regular expression-matching utilities or scripting languages such as grep, AWK, sed, Perl and Python. This pattern basically looks for the MIME header that contains the name of the attachment that ends in any of the listed filename extensions (those two or three letters separated by the '|' symbol).

Those sites that had a line similar to that in their Postfix MTA would have ensured that their sites were safe from infection via email of the Nimda and W32.Vote worms.

Postfix Pattern Matching Maps Explained

Both the header_checks and body_checks pattern maps use the same format for defining checks and actions. The simplest form, and the only form discussed in this article, is the following:

/regular expression/ ACTION

The matching occurs with the pattern, in this case a regular expression, which is the text between the forward slashes. Ignoring what a regular expression is for now, the ACTION is one of three possible actions:

  • OK—The pattern match is OK, so do not reject or modify the message. This action is not particularly useful for header or body scanning because it would otherwise cause a delay to the default action: to deliver the email.

  • IGNORE—Silently remove the header or body line that matches the pattern.

  • REJECT—Reject the entire message.

  • 4xx/5xx messages—Reject the entire message with a custom 4xx or 5xx SMTP result code and message. The 4xx series of STMP result codes is generally used for temporary failure, whereas the 5xx series is used for permanent failure.

So, rather than just reject the LoveLetter infected email messages, we can provide a specific response as to why it was rejected by changing the REJECT action to

550 This Email potentially contains LoveLetter worm payload

Back to regular expressions, if you have never written a regular expression before, all the symbols and their relevance could seem a bit overwhelming. Explaining regular expressions and their syntax is well beyond the scope of this article. Luckily, you don't normally need to take advantage of any esoteric features of regular expressions to make a useful match. For further reading about creating regular expressions, you should refer to the regular expression syntax documentation in any number of sources: the Perl homepage (http://www.perl.com/), the Python homepage (http://www.python.org/), Perl Compatible Regular Expression library home page (http://pcre.sourceforge.net/), and even UNIX man pages for grep(1), regex(7), or perlrequick(1).

Go Directly To chroot Jail

As mentioned previously, Postfix was designed with security in mind from the beginning. The Postfix architecture is broken up into many small, more manageable programs that are specialized into specific tasks (otherwise known as "The Unix Way"—do one thing and do it well). Each of these programs can be replaced, if necessary, to provide different functionality without replacing Postfix as a whole. The smaller nature of the programs also makes source code auditing easier.

The Postfix programs never trust any of the data that they cannot verify directly. Postfix runs a specific user that has limited, low-exposure permissions on the system. The Postfix programs never run set-uid, which is a Unix attribute that allows a program to effectively run as a specific user. Sendmail, for example, runs set-uid root, meaning that it runs with root-level privileges.

Postfix was designed to be able to be run in a chroot jail. A chroot jail is quite similar to what it sounds like: you change the root of the file system environment to a lower-level directory for a specific program. The term jail is denoting that the program is basically restricted to its newly defined file system hierarchy, and thus does not have access to other critical system files.

Placing and operating Postfix in a chroot jail ensures that if an exploit was developed against Postfix and your server was compromised, the damage to the system would be both localized and minimized. As you can see, there are many layers of security in the Postfix architecture with little or no trust between each layer. Achieving each of the stated design goals is a major contributing factor to Postfix's growing success.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020