~ 老兵の引退と新鋭の襲名、そして全拠点開通の全記録 ~
mail3 (CentOS 7)# 規律:パスワードの間にスペースを入れないこと mysql -u[USER] -p[PASS] postfix -N -s -e "SELECT domain FROM domain WHERE backupmx = 1 AND active = 1;" > /tmp/mail3_relay.txt
cat /tmp/mail3_relay.txt でドメイン名が並んでいることを確認せよ。
mail3 の過去データと s2 の現役データを統合し、s1 が引き継ぐべき「正典リスト」を生成する。
s2# mail3 は SSH 規律が厳しいため、画面からコピペで受け止める cat << 'EOF' > /tmp/mail3_relay_list.txt [ここに 37件のドメインを貼り付け] EOF
s2# DNSリスト(43件)とメールドメイン(41件)をそれぞれ抽出 mysql -u root -p$PASS dbispconfig -N -s -e "SELECT origin FROM dns_soa WHERE active = 'Y';" > /tmp/dns_list.txt mysql -u root -p$PASS dbispconfig -N -s -e "SELECT domain FROM mail_domain WHERE active = 'y';" > /tmp/s2_mail_list.txt
s2# mail3 と s2 の和集合から重複を排除 cat /tmp/s2_mail_list.txt /tmp/mail3_relay_list.txt | sort -u | grep -v '^$' > /tmp/final_mx_list.txt
生成したリストを新鋭 s1 へ物理的に搬送する。
s2scp /tmp/dns_list.txt root@109.123.231.61:/tmp/ scp /tmp/final_mx_list.txt root@109.123.231.61:/tmp/
更地の Ubuntu 24.04 LTS を D-Spec 規律へ引き上げる。
s1# アイデンティティ設定 hostnamectl set-hostname s1.dazoo.ne.jp timedatectl set-timezone Asia/Tokyo # /etc/hosts に 109.123.231.61 s1.dazoo.ne.jp を追記 # ISPConfig 3.3.2 導入 wget -O - https://get.ispconfig.org | sh -s -- --use-ftp-ports=40110-40210 --unattended-upgrades
reboot し、再起動後に全く同じ上記コマンドを再実行せよ。インストーラーが続きから処理を完遂する。
s1while read domain; do mysql -u root -p$PASS dbispconfig -e "INSERT INTO dns_slave (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, server_id, origin, ns, active, xfer) VALUES (1, 0, 'riud', 'riud', 1, '$domain', '210.237.157.226', 'Y', '210.237.157.226');" done < /tmp/dns_list.txt
s1while read domain; do TARGET="210.237.157.226" # 基本(s2) if [[ "$domain" =~ "miyasaka" ]]; then TARGET="210.237.157.233"; # 宮坂(sv) elif [[ "$domain" =~ "denkoku" || "$domain" =~ "yonezawa" ]]; then TARGET="210.175.7.66"; fi # 伝国(ns) mysql -u root -p$PASS dbispconfig -e "INSERT INTO mail_relay_domain (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, server_id, domain, access, active) VALUES (1, 0, 'riud', 'riud', 1, '$domain', 'OK', 'y');" mysql -u root -p$PASS dbispconfig -e "INSERT INTO mail_transport (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, server_id, domain, transport, sort_order, active) VALUES (1, 0, 'riud', 'riud', 1, '$domain', 'smtp:[$TARGET]', 1, 'y');" done < /tmp/final_mx_list.txt
s1 /root/force_sync.php<?php require '/usr/local/ispconfig/server/lib/config.inc.php'; require '/usr/local/ispconfig/server/lib/app.inc.php'; function force_sync($table, $id_field) { global $app; $records = $app->db->queryAllRecords("SELECT * FROM $table"); foreach($records as $rec) { $data = array('old' => $rec, 'new' => $rec); // 規律:クローン $app->db->datalogUpdate($table, $data, $id_field, $rec[$id_field]); } } force_sync('dns_slave', 'id'); force_sync('mail_relay_domain', 'relay_domain_id'); force_sync('mail_transport', 'transport_id'); ?>
s1php /root/force_sync.php /usr/local/ispconfig/server/server.sh
s1 を信頼できる仲間として承認する。ここが「全開通」の最後の一手。
s2 / ns(.66)postconf -e "mynetworks = $(postconf -h mynetworks), 109.123.231.61" systemctl reload postfix
sv(.233) [CentOS 6]postconf -e "mynetworks = 127.0.0.1/32 192.168.200.233/32, 213.136.91.179, 109.123.231.61" service postfix reload
/etc/bind/slave/ にファイルが 43件あるか?postmap -q [伝国ドメイン] で .66 が返るか?postmap -q [宮坂ドメイン] で .233 が返るか?s1 の門を絞り、特定の拠点と管理者のみに特権を与える。
s1# 基本規律:全てを拒否 ufw default deny incoming ufw default allow outgoing # 必須サービスの開放 ufw allow 22,25,53,80,443,8080/tcp ufw allow 53/udp ufw allow 40110:40210/tcp # 【最重要】管理者および信頼拠点の聖域化 ufw allow from 116.199.244.138 # 管理者固定IP ufw allow from 210.237.157.224/27 # D-Spec 内部ネットワーク ufw --force enable
Postfix SASL 等の攻撃を自動検知し、即座に投獄する。管理者は ignoreip で保護せよ。
s1 /etc/fail2ban/jail.local[DEFAULT] # 管理者を誤認逮捕させないための聖域規律 ignoreip = 127.0.0.1/8 ::1 116.199.244.138 210.237.157.224/27 destemail = alert@sigma-jpn.co.jp sender = fail2ban@s1.dazoo.ne.jp action = %(action_)s [sshd] enabled = true action = %(action_)s sendmail-whois[name=%(__name__)s, dest="%(destemail)s", sender="%(sender)s", actionstart="", actionstop=""] [postfix-sasl] enabled = true filter = postfix-sasl logpath = /var/log/mail.log action = %(action_)s sendmail-whois[name=%(__name__)s, dest="%(destemail)s", sender="%(sender)s", actionstart="", actionstop=""]
/etc/fail2ban/filter.d/postfix-sasl.conf を s2 譲りの 125バイトの規律(正規表現)で上書きせよ。
s1# 投獄状況の確認 fail2ban-client status postfix-sasl # 聖域(ignoreip)が正しく認識されているかの検閲 fail2ban-server -d | grep ignoreip
s1 (109.123.231.61) の門を絞り、特定の拠点と管理者のみに特権を与える規律である。
s1# 基本規律:全てを拒否 ufw default deny incoming ufw default allow outgoing # 必須サービスの開放(DNS/Mail/Web/ISPConfig) ufw allow 22,25,53,80,443,8080/tcp ufw allow 53/udp ufw allow 40110:40210/tcp # 【最重要】管理者および信頼拠点の聖域化(自爆防止) ufw allow from 116.199.244.138 # 管理者固定IPを承認 ufw allow from 210.237.157.224/27 # D-Spec 内部ネットワークを承認 ufw --force enable
Postfix SASL 等への攻撃を自動検知し、即座に投獄する。管理者は ignoreip で永久に保護せよ。
s1 /etc/fail2ban/jail.local[DEFAULT] # 管理者を誤認逮捕させないための「聖域」規律 ignoreip = 127.0.0.1/8 ::1 116.199.244.138 210.237.157.224/27 destemail = alert@sigma-jpn.co.jp sender = fail2ban@s1.dazoo.ne.jp mta = sendmail backend = auto [sshd] enabled = true action = %(action_)s sendmail-whois[name=%(__name__)s, dest="%(destemail)s", sender="%(sender)s", actionstart="", actionstop=""] [postfix-sasl] enabled = true filter = postfix-sasl logpath = /var/log/mail.log maxretry = 3 action = %(action_)s sendmail-whois[name=%(__name__)s, dest="%(destemail)s", sender="%(sender)s", actionstart="", actionstop=""]
/etc/fail2ban/filter.d/postfix-sasl.conf を手動で作成し、確実に執行せよ。
s1 /etc/fail2ban/filter.d/postfix-sasl.conf[Definition] failregex = ^.*smtpd\[\d+\]: warning: .*\[\]: SASL (?:LOGIN|PLAIN) authentication failed:.* ignoreregex =
正しく投獄が行われ、聖域が機能しているか、以下のコマンドで検閲せよ。
s1# 投獄状況の検閲 fail2ban-client status postfix-sasl # 聖域(ignoreip)が全監獄に浸透しているかの最終検閲 fail2ban-server -d | grep ignoreip