目的
DMARC p=rejectを設定した際の挙動を確認するために、なりすましメール送信用のSMTPサーバを構築してみた。
環境
以下の感じで環境を構築してみた。
1)正規SMTPサーバは、さくらインターネットサービスを利用
→ 構築方法は、以下の記事参照。
https://qiita.com/Darjeeling5656/items/649a903c2e25ba11f0aa
2)なりすましSMTPサーバはノートパソコンに仮想化ソフトを導入して構築
ホストOS:Windows11
仮想化ソフト:VMware Workstation Pro
仮想化OS:Rocky Linux
メールソフト:Postfix
3)受信メーラーは、「Yahoo!メール」を使用
なりすましSMTPサーバの構築
1)仮想化ソフトのセットアップ
VMware Worksationのインストーラーは以下サイトから取得する。
https://support.broadcom.com/web/ecx
①アカウントを作成する。
②作成したアカウントでログインする。
③インストーラー(exeファイル)をダウンロードする。
④ダウンロードしたexeファイルを実行し、VMware Workstation インストールする。
2)仮想化OSのセットアップ
VMware Workstation上でRocky Linuxを稼働させる。
インストーラーは以下サイトから取得する。
①以下サイトからisoファイルをダウンロードする。
②VMware Workstationを起動させる。
③ダウンロードしたisoファイルを指定し、ブートする。
④起動したRocky Linuxにログインし、インターネットにアクセスできることを確認する。
※疎通確認はpingコマンドで実施。
宛先はGoogleのDNSサーバー(8.8.8.8)とする。
以下の通り疎通できているので問題無し。
ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=6.87 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=128 time=7.91 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=128 time=7.49 ms
^C
以下はオプションとして実施した。
⑤言語を日本語にする。(Rocky Linuxはデフォルトだと英語)
sudo dnf install glibc-langpack-ja
sudo localectl set-locale LANG=ja_JP.utf8
localectl
あわせて、keymapも変更。
localectl list-keymaps | grep jp
sudo localectl set-keymap jp106
3)postfixのセットアップ
① postfixを確認
yum info postfix
Rocky Linux 9 - BaseOS 1.8 MB/s | 2.5 MB 00:01
Rocky Linux 9 - AppStream 7.6 MB/s | 9.6 MB 00:01
Rocky Linux 9 - Extras 15 kB/s | 16 kB 00:01
Available Packages
Name : postfix
Epoch : 2
Version : 3.5.25
Release : 1.el9
Architecture : x86_64
Size : 1.5 M
Source : postfix-3.5.25-1.el9.src.rpm
Repository : appstream
Summary : Postfix Mail Transport Agent
URL : http://www.postfix.org
License : (IBM and GPLv2+) or (EPL-2.0 and GPLv2+)
Description : Postfix is a Mail Transport Agent (MTA).
➁ インストール
sudo yum -y install postfix
➂ バージョン確認
postconf | grep mail_version
mail_version = 3.5.25
milter_macro_v = $mail_name $mail_version
④ 自動起動を設定
sudo systemctl enable postfix.service
⑤ 起動
sudo systemctl start postfix.service
⑥ プロセス確認
ps aux
postfix 3998 0.0 0.4 46620 8320 ? S 06:30 0:00 pickup -l -t unix -u
postfix 3999 0.0 0.4 46664 8320 ? S 06:30 0:00 qmgr -l -t unix -u
⑦ postfix設定値確認
postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
compatibility_level = 2
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
meta_directory = /etc/postfix
mydestination = $myhostname, localhost.$mydomain, localhost
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix/README_FILES
sample_directory = /usr/share/doc/postfix/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
shlib_directory = /usr/lib64/postfix
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_tls_CApath = /etc/pki/tls/certs
smtp_tls_security_level = may
smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
smtpd_tls_security_level = may
unknown_local_recipient_reject_code = 550
⑧ Postfixコンフィグのバックアップ
postfixのconfigは、「/etc/postfix/main.cf」に作成されるのでコピーを取得する。
sudo cp -p /etc/postfix/main.cf /etc/postfix/main.cf.bk
※ -p 元のファイルのオーナー、グループ、パーミション、タイムスタンプを保持
⑨ パラメータの設定
メールサーバのホスト名とメールドメインを変更する。
vi /etc/postfix/main.cf
【変更前】
myhostname = host.domain.tld
mydomain = virtual.domain.tld
masquerade_domains = host.domain.tld
【変更後】
myhostname = mail.hoge.com
mydomain = hoge.com
masquerade_domains = hoge.com
⑩ 設定の反映
postfix reload
postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
compatibility_level = 2
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
masquerade_domains = hoge.com
meta_directory = /etc/postfix
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = hoge.com
myhostname = mail.hoge.com
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix/README_FILES
sample_directory = /usr/share/doc/postfix/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
shlib_directory = /usr/lib64/postfix
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_tls_CApath = /etc/pki/tls/certs
smtp_tls_security_level = may
smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
smtpd_tls_security_level = may
unknown_local_recipient_reject_code = 550
4)telnetのセットアップ
sudo yum -y install telnet
5)偽装メール送信
① telnet接続〜メール送信
[liveuser@localhost-live postfix]$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mail.hoge.com ESMTP Postfix
telnet localhost 25
helo localhost
<送信元>
mail from:test@hoge.com
<送信先>
rcpt to:XXX@yahoo.co.jp
[liveuser@localhost-live postfix]$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mail.hoge.com ESMTP Postfix
helo localhost
250 mail.hoge.com
mail from:test@hoge.com
250 2.1.0 Ok
rcpt to:XXX@yahoo.co.jp
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test!!
.
250 2.0.0 Ok: queued as D82CC24D41
quit
221 2.0.0 Bye
Connection closed by foreign host.
② 送信結果確認
[liveuser@localhost-live postfix]$ sudo less /var/log/maillog
接続拒否されていることが確認できた。
Jun 8 08:02:00 localhost-live postfix/qmgr[4326]: D82CC24D41: from=<test@hoge com>, size=313, nrcpt=1 (queue active)
Jun 8 08:02:14 localhost-live postfix/smtpd[4353]: disconnect from localhost[::1] helo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Jun 8 08:02:25 localhost-live postfix/smtp[4371]: connect to mx2.mail.yahoo.co.jp[124.83.237.246]:25: Connection refused
Jun 8 08:02:46 localhost-live postfix/smtp[4371]: connect to mx2.mail.yahoo.co.jp[202.93.77.239]:25: Connection refused
Jun 8 08:03:07 localhost-live postfix/smtp[4371]: connect to mx5.mail.yahoo.co.jp[183.79.221.213]:25: Connection refused
Jun 8 08:03:28 localhost-live postfix/smtp[4371]: connect to mx2.mail.yahoo.co.jp[124.83.237.247]:25: Connection refused