web-dev-qa-db-ja.com

スパマーになりすましたローカルホスト?またはサーバーに障害が発生しましたか?どうすればこれを防ぐことができますか?

スパマーがpostgreyAND SpamAssassinを通過したことに気づきましたが、これは非常に奇妙なことでした。調べた/var/log/mail.logそしていくつかの疑わしい行を見ました:

以下のログ、またはPastebinにログインしてください: http://Pastebin.com/k7sKnvGE

Jul 19 07:59:06 mail postfix/smtpd[15492]: connect from unknown[37.215.63.185]
Jul 19 07:59:07 mail postfix/smtpd[15492]: NOQUEUE: reject_warning: RCPT from unknown[37.215.63.185]: 504 5.5.2 <37.215.63.185>: Helo command rejected: need fully-qualified hostname; from=<> to=<[email protected]> proto=SMTP helo=<37.215.63.185>
Jul 19 07:59:07 mail postgrey[13086]: action=pass, reason=triplet found, delay=316, client_name=unknown, client_address=37.215.63.185, [email protected]
Jul 19 07:59:07 mail postfix/smtpd[15492]: B8D5D20BDD: client=unknown[37.215.63.185]
Jul 19 07:59:09 mail postfix/cleanup[15500]: B8D5D20BDD: message-id=<>
Jul 19 07:59:09 mail postfix/qmgr[3224]: B8D5D20BDD: from=<>, size=493, nrcpt=1 (queue active)
Jul 19 07:59:09 mail amavis[11960]: (11960-14) NOTICE: reconnecting in response to: err=2006, HY000, DBD::mysql::st execute failed: MySQL server has gone away at (eval 111) line 170, <GEN39> line 9463.
Jul 19 07:59:10 mail postfix/smtpd[15492]: disconnect from unknown[37.215.63.185]
Jul 19 07:59:11 mail postfix/smtpd[15505]: connect from localhost[127.0.0.1]
Jul 19 07:59:11 mail postfix/smtpd[15505]: 96E1820C16: client=localhost[127.0.0.1]
Jul 19 07:59:11 mail postfix/cleanup[15500]: 96E1820C16: message-id=<[email protected]>
Jul 19 07:59:11 mail postfix/qmgr[3224]: 96E1820C16: from=<>, size=1166, nrcpt=1 (queue active)
Jul 19 07:59:11 mail postfix/smtpd[15505]: disconnect from localhost[127.0.0.1]
Jul 19 07:59:11 mail amavis[11960]: (11960-14) Passed CLEAN {RelayedInbound}, [37.215.63.185]:55743 <> -> <[email protected]>, Queue-ID: B8D5D20BDD, mail_id: d6hKjzEiMtex, Hits: 1.296, size: 493, queued_as: 96E1820C16, 2128 ms
Jul 19 07:59:11 mail postfix/smtp[15502]: B8D5D20BDD: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10024, delay=4.2, delays=2.1/0.01/0.01/2.1, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 96E1820C16)
Jul 19 07:59:11 mail postfix/qmgr[3224]: B8D5D20BDD: removed
Jul 19 07:59:11 mail dovecot: auth-worker(15508): mysql(localhost): Connected to database vimbadmin
Jul 19 07:59:11 mail dovecot: lda([email protected]): sieve: msgid=<[email protected]>: stored mail into mailbox 'INBOX'
Jul 19 07:59:11 mail postfix/pipe[15506]: 96E1820C16: to=<[email protected]>, relay=dovecot, delay=0.05, delays=0/0/0/0.04, dsn=2.0.0, status=sent (delivered via dovecot service)
Jul 19 07:59:11 mail postfix/qmgr[3224]: 96E1820C16: removed

誰かがサーバーを悪用してローカルホストをスプーフィングしたのか、それともAmavisまたはMySQLが私の側で失敗し、電子メールの通過を許可したのかがわかりません。これについての洞察は大いに高く評価されます!

/etc/postfix/main.cf:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# The first text sent to a connecting process.
smtpd_banner = $myhostname ESMTP $mail_name
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
readme_directory = no

# SASL parameters
# ---------------------------------

# Use Dovecot to authenticate.
smtpd_sasl_type = dovecot
# Referring to /var/spool/postfix/private/auth
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
smtpd_sasl_authenticated_header = yes

# TLS parameters
# ---------------------------------

# The default snakeoil certificate. Comment if using a purchased
# SSL certificate.
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

# Uncomment if using a purchased SSL certificate.
smtpd_tls_cert_file=/etc/ssl/mail.myhost.com/crt
smtpd_tls_key_file=/etc/ssl/mail.myhost.com/key

# The snakeoil self-signed certificate has no need for a CA file. But
# if you are using your own SSL certificate, then you probably have
# a CA certificate bundle from your provider. The path to that goes
# here.
smtpd_tls_CAfile=/etc/ssl/mail.myhost.com/ca-bundle

smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
#smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# Note that forcing use of TLS is going to cause breakage - most mail servers
# don't offer it and so delivery will fail, both incoming and outgoing. This is
# unfortunate given what various governmental agencies are up to these days.
#
# Enable (but don't force) all incoming smtp connections to use TLS.
smtpd_tls_security_level = may
# Enable (but don't force) all outgoing smtp connections to use TLS.
smtp_tls_security_level = may

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

# SMTPD parameters
# ---------------------------------

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
# will it be a permanent error or temporary
unknown_local_recipient_reject_code = 450
# how long to keep message on queue before return as failed.
# some have 3 days, I have 16 days as I am backup server for some people
# whom go on holiday with their server switched off.
maximal_queue_lifetime = 7d
# max and min time in seconds between retries if connection failed
minimal_backoff_time = 1000s
maximal_backoff_time = 8000s
# how long to wait when servers connect before receiving rest of data
smtp_helo_timeout = 60s
# how many address can be used in one message.
# effective stopper to mass spammers, accidental copy in whole address list
# but may restrict intentional mail shots.
smtpd_recipient_limit = 16
# how many error before back off.
smtpd_soft_error_limit = 3
# how many max errors before blocking it.
smtpd_hard_error_limit = 12

# This next set are important for determining who can send mail and relay mail
# to other servers. It is very important to get this right - accidentally producing
# an open relay that allows unauthenticated sending of mail is a Very Bad Thing.
#
# You are encouraged to read up on what exactly each of these options accomplish.

# Requirements for the HELO statement
smtpd_helo_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_hostname, reject_invalid_hostname, permit
# Requirements for the sender details
smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, warn_if_reject reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit
# Requirements for the connecting server
smtpd_client_restrictions = 
# Requirement for the recipient address. Note that the entry for
# "check_policy_service inet:127.0.0.1:10023" enables Postgrey.
smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service inet:127.0.0.1:10023, permit
smtpd_data_restrictions = reject_unauth_pipelining
# This is a new option as of Postfix 2.10, and is required in addition to
# smtpd_recipient_restrictions for things to work properly in this setup.
#smtpd_relay_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service inet:127.0.0.1:10023, permit

# require proper helo at connections
smtpd_helo_required = yes
# waste spammers time before rejecting them
smtpd_delay_reject = yes
disable_vrfy_command = yes

# General Host and delivery info
# ----------------------------------

myhostname = mail.myhost.com
#myorigin = /etc/hostname
# Some people see issues when setting mydestination explicitly to the server
# subdomain, while leaving it empty generally doesn't hurt. So it is left empty here.
# mydestination = mail.example.com, localhost
mydestination = mail.myhost.com, localhost.localdomain, localhost
# If you have a separate web server that sends outgoing mail through this
# mailserver, you may want to add its IP address to the space-delimited list in
# mynetworks, e.g. as 10.10.10.10/32.
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
mynetworks_style = Host

# This specifies where the virtual mailbox folders will be located.
virtual_mailbox_base = /var/vmail
# This is for the mailbox location for each user. The domainaliases
# map allows us to make use of Postfix Admin's domain alias feature.
#virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/mysql_virtual_mailbox_domainaliases_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/vimb/virtual_mailbox_maps.cf
# and their user id
virtual_uid_maps = static:150
# and group id
virtual_gid_maps = static:8
# This is for aliases. The domainaliases map allows us to make
# use of Postfix Admin's domain alias feature.
#virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/mysql_virtual_alias_domainaliases_maps.cf
virtual_alias_maps = mysql:/etc/postfix/vimb/virtual_alias_maps.cf
# This is for domain lookups.
#virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/vimb/virtual_domains_maps.cf

alias_maps=hash:/etc/aliases

# Integration with other packages
# ---------------------------------------

# Tell postfix to hand off mail to the definition for dovecot in master.cf
virtual_transport = dovecot
#dovecot_destination_recipient_limit = 1

# Use amavis for virus and spam scanning
content_filter = amavis:[127.0.0.1]:10024

# Header manipulation
# --------------------------------------

# Getting rid of unwanted headers. See: https://posluns.com/guides/header-removal/
header_checks = regexp:/etc/postfix/header_checks
# getting rid of x-original-to
enable_original_recipient = no

/etc/postfix/master.cf:

#
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       -       -       -       smtpd
#smtp      inet  n       -       -       -       1       postscreen
#smtpd     pass  -       -       -       -       -       smtpd
#dnsblog   unix  -       -       -       -       0       dnsblog
#tlsproxy  unix  -       -       -       -       0       tlsproxy
#submission inet n       -       -       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       -       -       -       smtpd
#  -o syslog_name=postfix/smtps
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#628       inet  n       -       -       -       -       qmqpd
pickup    fifo  n       -       -       60      1       pickup
  -o content_filter=
  -o receive_override_options=no_header_body_checks
cleanup   unix  n       -       -       -       0       cleanup
qmgr      fifo  n       -       n       300     1       qmgr
#qmgr     fifo  n       -       n       300     1       oqmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent.  See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
#   lmtp    cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
#  mailbox_transport = lmtp:inet:localhost
#  virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus     unix  -       n       n       -       -       pipe
#  user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix  -       n       n       -       -       pipe
#  flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -   n   n   -   2   pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

# The next two entries integrate with Amavis for anti-virus/spam checks.
amavis      unix    -       -       -       -       2       smtp
  -o smtp_data_done_timeout=1200
  -o smtp_send_xforward_command=yes
  -o disable_dns_lookups=yes
  -o max_use=20
127.0.0.1:10025 inet    n       -       -       -       -       smtpd
  -o content_filter=
  -o local_recipient_maps=
  -o relay_recipient_maps=
  -o smtpd_restriction_classes=
  -o smtpd_delay_reject=no
  -o smtpd_client_restrictions=permit_mynetworks,reject
  -o smtpd_helo_restrictions=
  -o smtpd_sender_restrictions=
  -o smtpd_recipient_restrictions=permit_mynetworks,reject
  -o smtpd_data_restrictions=reject_unauth_pipelining
  -o smtpd_end_of_data_restrictions=
  -o mynetworks=127.0.0.0/8
  -o smtpd_error_sleep_time=0
  -o smtpd_soft_error_limit=1001
  -o smtpd_hard_error_limit=1000
  -o smtpd_client_connection_count_limit=0
  -o smtpd_client_connection_rate_limit=0
  -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

# Integration with Dovecot - hand mail over to it for local delivery, and
# run the process under the vmail user and mail group.
dovecot      unix   -        n      n       -       -   pipe
  flags=DRhu user=vmail:mail argv=/usr/lib/dovecot/dovecot-lda -d $(recipient)
2
CaptSaltyJack

上記のログは、postfixとamavisからの予想される動作です。 amavisのようなキュー後のコンテンツフィルターの場合、フィルターはpostfixに電子メールを再挿入する必要があります。詳細については、 公式ドキュメント を参照してください。ここでは、接尾辞とamavisアクションの説明を示します。

Jul 19 07:59:06 mail postfix/smtpd[15492]: connect from unknown[37.215.63.185]

37.215.63.185のクライアントがメールサーバーに接続します。

Jul 19 07:59:07 mail postfix/smtpd[15492]: NOQUEUE: reject_warning: RCPT from unknown[37.215.63.185]: 504 5.5.2 <37.215.63.185>: Helo command rejected: need fully-qualified hostname; from=<> to=<[email protected]> proto=SMTP helo=<37.215.63.185>

HELOコマンドに完全修飾されていないホスト名が含まれているためPostfixが警告しますが、main.cfwarn_if_reject を指定しているため、引き続き電子メールを渡します。

Jul 19 07:59:07 mail postgrey[13086]: action=pass, reason=triplet found, delay=316, client_name=unknown, client_address=37.215.63.185, [email protected]

クライアントが以前にpostgreyのチェックに合格したため、Postgreyは電子メールを拒否しません。

Jul 19 07:59:07 mail postfix/smtpd[15492]: B8D5D20BDD: client=unknown[37.215.63.185]
Jul 19 07:59:09 mail postfix/cleanup[15500]: B8D5D20BDD: message-id=<>
Jul 19 07:59:09 mail postfix/qmgr[3224]: B8D5D20BDD: from=<>, size=493, nrcpt=1 (queue active)

すべての制限に合格するため、Postfixはqueue-idを電子メールに割り当てます。この段階で、posfixはメールを受け入れました。

Jul 19 07:59:09 mail amavis[11960]: (11960-14) NOTICE: reconnecting in response to: err=2006, HY000, DBD::mysql::st execute failed: MySQL server has gone away at (eval 111) line 170, <GEN39> line 9463.

PostfixがあなたのEメールをamavisに転送し始めました、そしてamavisはmysql接続が失敗したことをあなたに通知しています。

Jul 19 07:59:10 mail postfix/smtpd[15492]: disconnect from unknown[37.215.63.185]

Postfixがメールを受け入れるため、37.215.63.185のクライアントはサーバーから切断されます。

Jul 19 07:59:11 mail postfix/smtpd[15505]: connect from localhost[127.0.0.1]

Amavisは、ポート10025に電子メールを再挿入しようとしています。デフォルトでは、Amavisは、電子メールのステータスがPASSED CLEAN(以下のログ行に基づく)の場合にのみメッセージを再挿入します。

Jul 19 07:59:11 mail postfix/smtpd[15505]: 96E1820C16: client=localhost[127.0.0.1]
Jul 19 07:59:11 mail postfix/cleanup[15500]: 96E1820C16: message-id=<[email protected]>
Jul 19 07:59:11 mail postfix/qmgr[3224]: 96E1820C16: from=<>, size=1166, nrcpt=1 (queue active)

明らかにPostfixはamavisからのメールを受け入れました。

Jul 19 07:59:11 mail postfix/smtpd[15505]: disconnect from localhost[127.0.0.1]

Amavisは送信プロセスを終了しました

Jul 19 07:59:11 mail amavis[11960]: (11960-14) Passed CLEAN {RelayedInbound}, [37.215.63.185]:55743 <> -> <[email protected]>, Queue-ID: B8D5D20BDD, mail_id: d6hKjzEiMtex, Hits: 1.296, size: 493, queued_as: 96E1820C16, 2128 ms

アマビスは自分の行動をメールログに記録します。 SpamAssasinスコアは比較的低く(1.296)、電子メールはすべてのamavisチェックに合格しました。

Jul 19 07:59:11 mail postfix/smtp[15502]: B8D5D20BDD: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10024, delay=4.2, delays=2.1/0.01/0.01/2.1, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 96E1820C16)

Postfixは、電子メールスキャンが成功したことを通知します。

Jul 19 07:59:11 mail postfix/qmgr[3224]: B8D5D20BDD: removed

キューが削除されました。次に、以下のdovecotにメールが配信されます。

Jul 19 07:59:11 mail dovecot: auth-worker(15508): mysql(localhost): Connected to database vimbadmin
Jul 19 07:59:11 mail dovecot: lda([email protected]): sieve: msgid=<[email protected]>: stored mail into mailbox 'INBOX'
Jul 19 07:59:11 mail postfix/pipe[15506]: 96E1820C16: to=<[email protected]>, relay=dovecot, delay=0.05, delays=0/0/0/0.04, dsn=2.0.0, status=sent (delivered via dovecot service)
Jul 19 07:59:11 mail postfix/qmgr[3224]: 96E1820C16: removed
5
masegaloeh

Masegaloehからの説明に加えて、指摘したいのですが、なぜあなたのケースではスパマーが通り抜けました。ログの次の行を見てください。

Jul 19 07:59:07 mail postfix/smtpd[15492]: NOQUEUE: reject_warning: RCPT from unknown[37.215.63.185]: 504 5.5.2 <37.215.63.185>: Helo command rejected: need fully-qualified hostname; from=<> to=<[email protected]> proto=SMTP helo=<37.215.63.185>

これはすでに問題を解決するための指示なので、構成を見てみましょう(warn_if_rejectに注意してください:

smtpd_helo_restrictions = [...] warn_if_reject reject_non_fqdn_hostname, [...], permit
smtpd_sender_restrictions = [...], warn_if_reject reject_non_fqdn_sender, [...], permit

ログには、reject_non_fqdn_hostnameがトリガーされたが、保留されて警告に変換されたことが示されています(ログに表示されます)。それを削除すると、スパマーは拒否されます。

reject_non_fqdn_hostnameを使用すると、有効な送信者が失われることはありません。すべてのメールサーバーが適切に設定され、heloに有効なFQDNが使用されます。

編集:あなたの設定を片付けることを検討してください:)他の人とあなたは、各行の3つのコメントアウトされたバリアントなしで、設定で自分自身をより良く方向付けることができます。

5
sebix