Yuri Slobodyanyuk Blog on Information Security 2024年09月12日
SMTP inspection with policy-map in ASA
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了在 Cisco ASA 8.0(3) 上配置 SMTP 邮件检查以防止内部邮件服务器发送垃圾邮件的步骤。文章首先介绍了使用 SMTP 资源在 Checkpoint 中进行邮件检查的简单方法,然后展示了在 ASA 中使用正则表达式、策略映射和 ACL 规则来实现类似功能的详细配置过程。文章还强调了在配置策略映射时需要注意的细节,例如 mail-relay 参数的限制和应用检查规则的时机。

👌 为了防止内部邮件服务器发送垃圾邮件,文章首先介绍了使用正则表达式来匹配客户端域名,并使用 NOT 运算符来阻止来自其他域名的邮件。例如,使用 `@microsoft.com|@apple.com` 正则表达式匹配客户端域名,并使用 `match not sender-address regex PermittedSenders` 规则阻止来自其他域名的邮件。

👍 为了进一步限制邮件中继,文章使用策略映射来配置邮件中继规则,以阻止来自内部邮件服务器的邮件转发到其他域名。例如,使用 `mail-relay apple.com action drop-connection log` 规则阻止来自内部邮件服务器的邮件转发到除 apple.com 以外的任何域名。

👏 文章还强调了在配置策略映射时需要注意的细节,例如 mail-relay 参数的限制和应用检查规则的时机。例如,文章指出 mail-relay 参数只能使用一次,如果有多个域名需要配置,则需要使用其他方法来实现。另外,文章还指出应用检查规则的时机是在 NAT 规则完成之后。

😊 文章还提到了在配置 SMTP 检查时,可以使用 `reset` 而不是 `drop` 来处理来自其他域名的邮件,这样可以避免恶意软件利用超时机制进行攻击。

😉 文章最后还提醒读者,可以通过 LinkedIn、Github 和博客等平台关注作者的最新内容。

This is the first time I was disappointed by the cisco.com . I had a simple task at hand – configure SMTP inspection in ASA 8.0(3) and cisco.com documentation didn’t help me at all. But first the task:Secure internal mail server by preventing it from sending spam outbound. It comes to mind two very simple but largely effective measures – block mails with From: field set to any domain but ours, and block attempts to relay Through the internal mail server mails destined to any domain but ours. In Checkpoint I can do it quite simply with SMTP Resource. Unfortunately in ASA it is not the case. Let’s look at final SMTP inspection I configured in ASA.Input :

Internal server having outside IP address of 199.202.2.3 serves two domains apple.com and microsoft.com Task:
- block mails with From: field set to any domain but apple.com or microsoft.com
- block mail relying for any domain but microsoft.com or apple.com

NOTE. Here I did this config on the production ASA so had no room for experimenting with all “what ifs” Identify mails direction from inside server outbound. I did it as didn’t find reliable info about sender-address match condition – does it match in any direction if applied globally on all traffic ? I mean , if it just looks at Mail from: field and acts on mails in both directions then it would block mails coming in from any domain but client’s own.

To prevent even checking this on client I did this ACL that will apply this SMTP inspection to outgoing mails anyway.

BigInJapan(config)#access-list Mail-server permit tcp host 199.202.2.3 any eq 25

To block mails with From filed other than client’s domains I use regex that matches client’s domains and the use negation with NOT.

BigInJapan(config)# regex PermittedSenders "@microsoft.com|@apple.com "

Create policy-map where all the tweaked parameters are set (as of ASA 8.2 there is still no class-map type inspect esmtp) .

BigInJapan (config)# policy-map type inspect esmtp NoSpamOutside

Match all mails that Mail from field is anything but *@microsoft.com or *@apple.com. Action is reset and log.It is more secure I guess to drop instead of reset as in drop malware would have to wait until some timeout, but I didn’t care here anyway.

BigInJapan(config-pmap)# match not sender-address regex PermittedSenders  BigInJapan(config-pmap-c)# reset log  BigInJapan(config-pmap-c)# exit

Various parameters. Here you set internal domain the mail server is serving, so trying to deliver mails to any other domain would be seen as illegal relaying and dropped. But also I was surprised to know here that policy-map mail-relay parameter can be used only once, leaving you without this protection if you have multiple domains served from the same server. So below is theoretical configuration if my client had just one domain on his server.

BigInJapan(config-pmap)# parametersBigInJapan(config-pmap-p)# mail-relay apple.com action drop-connection log  BigInJapan(config-pmap-p)# exit  BigInJapan(config-pmap)# exit

Now create general policy-map to tie it all together.

BigInJapan(config)# policy-map NoSpamFromUs  BigInJapan(config-pmap)# class Mail-server  BigInJapan(config-pmap-c)# inspect esmtp NoSpamOutside  BigInJapan(config-pmap-c)# exit  BigInJapan(config-pmap)# exit

And apply it on some interface.

Important: according to Hucaby’s ASA handbook application protocol inspection is applied AFTER the NAT rules are done, so you need to use in your class-map/ACL IPs that are after the translation. Internal IP of the mail server is 192.168.3.3 that is statically NATed to 199.202.2.3, so I used 199.202.2.3 in class-map’s ACL.

On which interface to apply the policy-map I guess doesn’t matter but to be sure I did it on the outside.

BigInJapan(config)# service-policy NoSpamFromUs interface outside 

Link to Inspection page in ASA 8.
Applying Application Layer Protocol Inspection

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Cisco ASA SMTP 检查 垃圾邮件 邮件安全 策略映射
相关文章