postfix 仅允许 localhost 本地用户

postfix 仅允许 localhost 本地用户

我遇到了一个小问题。我允许一些客户端访问我的服务器,以便执行自己的脚本(当然是在他们自己的 chroot 环境中,等等)。今天出现的问题:有些人通过端口 25 获得对本地主机的 telnet 访问权限,并向几乎是开放中继的世界发送电子邮件 :(

我正在使用 postfix,它也需要身份验证:

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:/etc/postfix/mysql-virtual_recipient.cf, reject_unauth_destination

但本地脚本显然不需要进行 sasl 身份验证。如果从 permit_mynetworks 中删除 localhost,某些反垃圾邮件程序将不再起作用...

那么,如何配置 postfix 以允许 localhost 在本地传递邮件,但不在未经身份验证的情况下向外部传递邮件?

有什么建议么?

答案1

因此,您的反垃圾邮件程序正在使用 localhost,而坏人正在使用 localhost 和postfix 无法区分

禁止坏人或从受信任网络 ( permit_mynetworks) 中删除 localhost,并将反垃圾邮件配置为使用其他内容。或者允许使用smtpd_客户端限制 check_ccert_access

回到你的问题。你要求的是这样的:

/etc/postfix/main.cf:
    smtpd_recipient_restrictions =
        /* replace permit_mynetworks with the next line */ 
        check_client_access hash:/etc/postfix/client_access,
        /* your other stuff */
        permit_sasl_authenticated,
        check_recipient_access mysql:/etc/postfix/mysql-virtual_recipient.cf,
        reject_unauth_destination

    smtpd_restriction_classes = local_only
    local_only = 
        check_recipient_access hash:/etc/postfix/local_domains, reject

/etc/postfix/client_access:
    localhost      local_only
    127.0.0.1      local_only
    /* check bash#postconf mynetworks for full list of your networks */

/etc/postfix/local_domains:
    this.domain     OK      matches this.domain and subdomains
    that.domain     OK      matches that.domain and subdomains

但可能行不通,因为你的反垃圾邮件程序会重新注入带有外部收件人的邮件。但这取决于具体情况。

请向我们提供有关您的反垃圾邮件工具的更多信息,也许我们能够提供帮助。

UDP:

您能否向我解释一下邮件流是如何通过此设置的。

不能更好地解释限制类别官方文档

后缀限制类

Postfix SMTP 服务器支持在 SMTP 服务器访问 (5) 表的右侧设置访问限制,例如,reject_rbl_client 或 rejection_unknown_client_hostname。这允许您针对不同的客户端或用户实施不同的垃圾邮件限制。

必须为每个收件人指定访问限制列表很快就会变得乏味。后缀限制类允许您为 UCE 限制组指定易于记忆的名称(例如“允许”、“限制”等)。

Postfix 限制类存在的真正原因更为平凡:您无法在 Postfix 访问表的右侧指定查找表。这是因为 Postfix 需要提前打开查找表,但读者可能并不关心这些低级细节。

local_only我们用 来定义我们的限制类smtpd_restriction_classes = local_only。并且

local_only = 
        check_recipient_access hash:/etc/postfix/local_domains,
        reject

说“每当检查这个类时检查检查收件人访问(搜索指定访问(5)数据库中解析的 RCPT TO 地址、域、父域或 localpart@,并执行相应的操作。)否则拒绝邮件。文件local_domains说“如果是 this.domain 则通过检查,如果是 that.domain 则通过检查”。

但我们不想将此限制类应用于所有电子邮件。我们希望在发送主机为 localhost 时应用它并删除permit_mynetworks规则。为此,我们添加check_client_access 哈希:/etc/postfix/client_access(在指定的访问数据库中搜索客户端主机名、父域、客户端 IP 地址或通过剥离最低有效八位字节获得的网络。请参阅访问(5)请参阅手册页以了解详情。)到 smtpd_recipient_restrictions。它说检查/etc/postfix/client_access文件并确定其是否localhost应用local_only限制。这正是我们想要做的。

希望能帮助到你。

邮件流程如下:

  • 邮件到达
  • 循环遍历 smtpd_recipient_restrictions
    • check_client_access(如果发送主机localhost应用local_only限制类)
      • 现在 check_recipient_access(如果收件人 RCPT TO 地址、域、父域或 localpart@ 是“this.domain”或“that.domain”则接受此邮件)(跳过进一步检查)
      • 否则拒绝
    • 否则继续使用 permit_sasl_authenticated、check_recipient_access mysql:/etc/postfix/mysql-virtual_recipient.cf 等

UPD2 我刚刚发现了 smtpd_recipient_restrictions (和其他自定义类)的另一个选项,您可能会感兴趣

允许_授权_目的地

当下列条件之一成立时,允许该请求:

  • Postfix 是邮件转发器:解析后的 RCPT TO 域与 $relay_domains 或其子域匹配,并且地址不包含发件人指定的路由(user@elsewhere@domain),
  • Postfix 是最终目的地:解析的 RCPT TO 域与 $mydestination、$inet_interfaces、$proxy_interfaces、$virtual_alias_domains 或 $virtual_mailbox_domains 匹配,并且地址不包含发件人指定的路由(user@elsewhere@domain)。

答案2

一个选项是使用 iptables 来阻止这些用户连接到本地主机的 25 端口。例如:

iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 25 -m owner --uid-owner user1 -j REJECT
iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 25 -m owner --uid-owner user2 -j REJECT
[etc]

相关内容