qmailの情報収集 2016/03/31

新しい情報があったので「qmailの情報収集 2019/08/26」で更新しました。


2012年に作成した「いまさらqmailのパッチ情報収集 2012/02/17」という記事に、いまでも時々アクセスがある。

あれから4年。何か変わったところがあるか調べてみた。

・新星 s/qmail登場
なんと「s/qmail」という新作が登場。

これまで普通のqmail向けに、SMTP Authentication, Spamcontrol(4年前の記事でも紹介)などを作成してきた開発者が提供するqmail 2016年版、的なもの。
IPv4,IPv6にちゃんと対応し、vpopmailなどのqmailを使用するソフトウェアがそのまま使用できるものとなっている。

SSL/TLS対応はs/qmail自身ではなく「ucspi-ssl」が提供しているようだ。
SPF,DKIMには対応していない。

・IndiMail
qmail, serialmail, qmailanalog, dotforward, fastforward, mess822, daemontools, ucspi-tcp, Courier IMAP/POP3, Bogofilter – A Bayesian Spam Filter, Fetchmailをまとめてパッケージングしている「www.indimail.org」にアーキテクチャ図あり
SPF,DKIM対応
各ディストリビューション用のレポジトリーが用意されている。(RHEL/CentOS5~7,Debian7~8,Ubuntu12.04~15.10,OpenSuSE11.4など)
安定版:http://download.opensuse.org/repositories/home:/indimail/
開発版:http://download.opensuse.org/repositories/home:/mbhangui/

基本的にパッケージとして使うためものであるため、qmail単独で使うにはちょっと厳しい感じがある。
vpopmailと組み合わせて使えるか、というと、結構謎。

qmail-isp
qmail-1.03に対するパッチをまとめたもの。netqmail-1.06相当のパッチも含まれている。
2013年6月に更新版が出ていた。
こいつはvpopmailと一緒に使えるらしい

Courier-IMAPからdovecotへの移行

Courier-IMAPの最近のバージョンが使っているcourier-authlibは、vpopmail連携機能が切られてしまい使えなくなってしまっているため代替策を検討中。

まず、dovecotに乗り換え実験中。

Dovecotのwikiを探すと「AuthDatabase/VPopMail」というページを発見。
vpopmail専用のデータベースファイルを使っている場合は、「–with-vpopmail」でコンパイル。
vpopmailからmysqlを使っている場合は、「–with-sql –with-mysql」でコンパイルということが分かる。

次に、設定。

うちの環境では、単純なvpopmailではなく、ユーザ管理にmysqlを利用している。
このため、vpopmail由来のmysqlを使う場合に重要なポイントのみを記載する。

・「/etc/dovecot/dovecot-sql.conf.ext」

password_query = SELECT CONCAT( pw_name,'@', pw_domain ) AS user,\
        pw_passwd AS password \
        FROM vpopmail  \
        where pw_name='%n' AND pw_domain='%d' ;
user_query = SELECT pw_dir as home, \
        <vpopmailのUID> AS uid, <vchkpwのGID> AS gid \
        FROM vpopmail \
        WHERE pw_name = '%n' AND pw_domain = '%d'

なお、動作確認時はmysqlを起動して「SELECT CONCAT( pw_name,’@’, pw_domain ) AS user, pw_passwd AS password FROM vpopmail where pw_name=’ユーザ名’ AND pw_domain=’ドメイン名’ ;」という感じで実行して、以下の様な感じで表示されればok。

# mysql -u root --password=パスワード
mysql> use vpopmail;
Database changed
mysql> SELECT CONCAT( pw_name,'@', pw_domain ) AS user, pw_passwd AS password FROM vpopmail where pw_name='ユーザ名' AND pw_domain='ドメイン名';
+---------------------+------------------------------------+
| user                | password                           |
+---------------------+------------------------------------+
| ユーザ名@ドメイン名   | 文字列~                           |
+---------------------+------------------------------------+
1 row in set (0.00 sec)

mysql> quit
Bye
#

・「/etc/dovecot/conf.d/10-auth.conf」と「/etc/dovecot/conf.d/auth-sql.conf.ext」
上記で作成したsql設定ファイルをここで指定
10-auth.confでは、下記の「sql」に関するところだけを修正。(vpopmailはいじらない)

!include auth-sql.conf.ext

auth-sql.conf.extでは、dovecot-sql.conf.extのパスがきちんと指定されていることを確認。

・「/etc/dovecot/conf.d/10-mail.conf」
Maildirを操作する際のユーザ権限のチェックをしている項目の設定を変更する。
今回は元々vpopmailの1アカウントのみで全ユーザを動かしていたため、UIDを1つだけ指定している形になる。

first_valid_uid=<vpopmailのUID>
last_valid_uid=<vpopmailのUID>
first_valid_gid=<vchkpwのGID>
last_valid_gid=<vchkpwのGID>

なお、この設定をしていないと、POP3などでログインしてみると、/var/log/maillogに以下のようなエラーが出力される。

Feb 25 15:21:46 サーバ名 dovecot: pop3: Error: user ユーザ名@ドメイン名: Mail access for users with UID <vpopmailのUID> not permitted (see first_valid_uid in config file, uid from userdb lookup).
Feb 25 15:21:46 サーバ名 dovecot: pop3: Error: Invalid user settings. Refer to server log for more information.

・POP3の未読管理の移行
標準設定だとPOP3のUIDLコマンドの出力結果が全然違うので、メーラ側の未読管理がリセットされる。
dovecot公式wikiに「Migration」という項目がある。

「/etc/dovecot/conf.d/20-pop3.conf」内の「pop3_uidl_format」を定義することで対処できる、とあるが、20-pop3.conf内に記載されている「Courier: %f or %v-%u (both might be used simultaneosly)」を設定してみると、「%f」と「%v-%u」は、Courier-IMAPでの結果と異なるものになる。

よく見てみると、「Migration/Courier v0.43 and later to Dovecot v1.1+」と専用の項目がある。
「courier-dovecot-migrate.pl」を使って、各Maildir内にある「courierimapuiddb」などをdovecot用の「dovecot-uidlist」にコンバートする、というもの。
コレを実行することで、同じUIDLの結果が得られるようになった。

・「/etc/dovecot/conf.d/15-mailboxes.conf」
IMAP用メールボックスの標準名調整。
いままで下書きフォルダ名「Draft」、スパムメール用「Spam」と設定していた。
dovecotの標準設定では「Drafts」、「Junk」であるため、読み替え設定を入れる

  mailbox Draft {
    special_use = \Drafts
  }
  mailbox Spam {
    special_use = \Junk
  }
  mailbox Trash {
    special_use = \Trash
  }

・・・・・・・

で、ここまでやって気がついたこと。
Courier-IMAPでも、vpopmail関係無く、直接MySQLを見れば良かったんじゃね?ということ。

まぁ、2つのバージョンの並行動作が難しいので、動作確認がしにくく、やりたくはないですがね。

RoundCubeは次の1.1でIE8とFirefox 3.6のサポートを切る

Webmailソフトの「RoundCube」に、version 1.0.1が出ていたのに気がついて、アップデート。

ついでに、「System Requirements」を確認・・・

Internet Explorer 6 (Windows 2000/XP) – not supported since Roundcube 1.1
Internet Explorer 7 (Windows XP) – requires legacy_browser plugin since Roundcube 1.1
Internet Explorer 8 (Windows XP/7) – requires legacy_browser plugin since Roundcube 1.1
Firefox 3.6 (Windows XP, Linux) – requires legacy_browser plugin since Roundcube 1.1

おや?
次のバージョン 1.1から、古いブラウザのサポートをやめるようです。

RoundCube 1.1から、内部で使用しているjQueryのバージョンを2.xに変更するようで、そのjQuery 2.xがこれらのブラウザをサポートしていない(jQuery 2.0 Releasedより)ということに起因する変更点である模様です。

とりあえずは、legacy_browser pluginを使うという、救済処置がIE6以外にはあるようです。

案外SPAMにダマされる人がいるのか?

先週、以下のようなSPAMメールが来ているのに気がついた。

It Is Our New Low Float Sub-Penny Special! And Our Next
Trading Idea!!!

Symbol to buy: HA I_R
Long Term Target Price: $1.50
Name: Biostem Corp.
Last Trade: 0.045
Trading Date: Jul 22

Mega Bagger Announcement! 10 Trading Rules!!!

意味がわかんなかったので、検索してみると、どうやら、現在$0.045のBiostem社の株を買っとくと長期保有してりゃ最終的には$1.5あたりまで値上がるぜ!という意味っぽい。
確認してみると現状は「Last Trade」にある値段ではあるものの、ここんところどんどん価格が下落しているような株だった。

「ふ~ん」という感じで放置していたら、また同様のメールがいくつか・・・

This Company has legs! This is on High Alert After Yesterday`s Big News
Day; Full Details Inside!!!

Trade Date: Jul, 29
To buy: H_A IR
Last Trade: .035
Short Term Target Price: $1.15
Company Name: Biostem U.S.

This stock is perfectly positioned for HUGE growth! This Company Releases
Breaking News This Morning!

こっちは短期で$1.15になるぜ、とか言ってたりする。

で・・・もしかして、これって、結構前からこの種のメールが来てたのでは無いか?と思い当たって検索してみると、2013年6月8日に以下のようなメールが来ていたのが最古だった。

Trading Tip: HA I_R. Biostem US Corp. To Soar! Add on Immediately. As
Stem Cell Industry Skyrockets In 2013 Biostem U.S. Corp is rolling out a
hair restoration process referred to as: The Biostem Method. This
technique involves the usage of platelet rich plasma injections, low
level laser solution. This mix has proven highly effective in fixing
growth of hair in women and men. This will gonna go skyrocket this
undervalued company as headlines circulate. Buyers who trade fast could
get big profits… Our rd shows this stock is about to trade big. As much
as 1300%. Getting brokers, who be in now to cash amazing gains. Now,
company insiders reported buying up shares in the firms stock. Why is
this important?! Thinking that stock is at all-time lows, this became a
brilliant and planned move. According to financers, when firms insiders
grab a ton of stock, the price of that stock jumps up over twelve months.
Conservatively… Much of Its latest value. A smaller USD 8’000 purchase
must come to… $70’000. Buy HA I_R on Mon, June 10th.

このメールが来たJun 8の時点では「0.2ドル」近辺。
biostem
その後のJun 20ぐらいから取引数が増加している。

そして、最近の取引数はすごいことに・・・
いままでの動きからすると異常なぐらいですね。

というあたりを考えると、このSPAMメールって、株を動かしたい人が送信してるんだなぁ、と感じる次第で。

メールアカウント乗っ取り系のSPAM送信

ある日、メールの送信失敗率が急上昇した。
qmailsend-week-mod
(上記画像は対処して落ち着いた後に取ったもの)

慌ててメールキューを確認するとエラーメールが大量に・・・

調べてみると、全てある1ユーザに関するもの。
ログを確認していくと、そのユーザが、さまざまなIPアドレスからSMTP認証をかけてきて、認証に成功した上でSPAM送信が行われているじゃないですか。

Jul 22 18:47:21 mailserver qmail: 1374486441.012502 starting delivery 77399: msg 90220 to local example.com-hello@example.com
Jul 22 18:47:21 mailserver qmail: 1374486441.012529 status: local 2/100 remote 0/50
Jul 22 18:47:21 mailserver spamd[937]: spamd: connection from localhost.localdomain [127.0.0.1] at port 43120
Jul 22 18:47:21 mailserver spamd[937]: spamd: handle_user unable to find user: 'hello@example.com'
Jul 22 18:47:21 mailserver spamd[937]: spamd: processing message <201307220947.r6M9lLNe013087@mailserver.example.com> for hello@example.com:109
Jul 22 18:47:26 mailserver spamd[937]: spamd: clean message (0.0/18.0) for hello@example.com:109 in 5.9 seconds, 2050 bytes.
Jul 22 18:47:26 mailserver spamd[937]: spamd: result: . 0 - AWL,BAYES_20,CONTENT_TYPE_PRESENT,INVALIDYAHOOJP,ISO2022JP_BODY,ISO2022JP_CHARSET,SUBJECT_NEEDS_ENCODING,SUBJ_ILLEGAL_CHARS,URI_HEX scantime=5.9,size=2050,user=hello@example.com,uid=109,required_score=18.0,rhost=localhost.localdomain,raddr=127.0.0.1,rport=43120,mid=<201307220947.r6M9lLNe013087@mailserver.example.com>,bayes=0.090684,autolearn=disabled
Jul 22 18:52:46 mailserver vpopmail[17115]: vchkpw-submission: (PLAIN) login success hello@example.com:83.242.101.27
Jul 22 18:52:57 mailserver qmail: 1374486777.611039 new msg 90219
Jul 22 18:52:57 mailserver qmail: 1374486777.611077 info msg 90219: bytes 1364 from <hello@example.com> qp 17121 uid 103
Jul 22 18:52:57 mailserver qmail: 1374486777.638528 starting delivery 77421: msg 90219 to remote ~@~
Jul 22 18:52:57 mailserver qmail: 1374486777.638582 status: local 0/100 remote 1/50
Jul 22 18:52:57 mailserver qmail: 1374486777.641128 starting delivery 77422: msg 90219 to remote ~@~
Jul 22 18:52:57 mailserver qmail: 1374486777.641155 status: local 0/100 remote 2/50
Jul 22 18:52:57 mailserver qmail: 1374486777.641173 starting delivery 77423: msg 90219 to remote ~@~
Jul 22 18:52:57 mailserver qmail: 1374486777.641192 status: local 0/100 remote 3/50
Jul 22 18:52:57 mailserver qmail: 1374486777.641314 starting delivery 77424: msg 90219 to remote ~@~
Jul 22 18:52:57 mailserver qmail: 1374486777.641339 status: local 0/100 remote 4/50
Jul 22 18:52:57 mailserver qmail: 1374486777.641518 starting delivery 77425: msg 90219 to remote ~@~
Jul 22 18:52:57 mailserver qmail: 1374486777.641543 status: local 0/100 remote 5/50

そう、そのユーザのメールアカウント情報がどこかで漏れ、SPAMシステムに投入されたようなのです。

とりあえず、該当アカウントのパスワード変更し、メールキュー内のエラーメール群を消去したあと、対処開始。

確認すると、約24時間の間に、880のIPアドレスからSMTP認証のloginが行われているという事態。
また、ほとんどのIPアドレスからは1回しかアクセスがなかったので、相当大規模なシステムである模様。

# cat /var/log/maillog.? |grep vchkpw-submission|grep hello@example.com|grep succ|awk '{ print $10 }'|awk -F: '{ print $2 }' |sort|uniq -c|sort|wc
    880    1760   19476
# cat /var/log/maillog.? |grep vchkpw-submission|grep hello@example.com|grep succ|awk '{ print $10 }'|awk -F: '{ print $2 }' |sort|uniq -c|sort | tail
      2 93.85.128.230
      2 94.156.244.75
      2 94.170.246.170
      2 94.180.194.222
      2 95.52.132.238
      3 178.125.185.161
      3 46.118.66.80
      3 93.175.125.67
      3 93.78.3.92
      3 95.42.37.153
#

そんな確認を行っていると、30分が経過。
すると、いままで出ていた「password fail」のログが消えた。
そう、どうやらSPAM送信システム側で、このサーバでは送れない、という認識がされたようだ。

これで終わりかな?と思ったのですが、その後も12時間ごとに10回のメール送信を試みてる形跡が確認されています。

Jul 24 07:11:42 mailserver vpopmail[32749]: vchkpw-submission: password fail hello@example.com:91.225.163.32
Jul 24 07:16:21 mailserver vpopmail[1287]: vchkpw-submission: password fail hello@example.com:89.74.114.28
Jul 24 07:20:57 mailserver vpopmail[2147]: vchkpw-submission: password fail hello@example.com:192.162.224.10
Jul 24 19:13:23 mailserver vpopmail[8339]: vchkpw-submission: password fail hello@example.com:94.139.211.248
Jul 24 19:18:54 mailserver vpopmail[9449]: vchkpw-submission: password fail hello@example.com:178.120.193.67
Jul 24 19:24:18 mailserver vpopmail[10359]: vchkpw-submission: password fail hello@example.com:178.127.107.5
Jul 24 19:29:58 mailserver vpopmail[11422]: vchkpw-submission: password fail hello@example.com:114.41.229.41
Jul 24 19:35:23 mailserver vpopmail[13866]: vchkpw-submission: password fail hello@example.com:178.122.175.143
Jul 24 19:40:48 mailserver vpopmail[14894]: vchkpw-submission: password fail hello@example.com:46.211.194.44
Jul 24 19:46:03 mailserver vpopmail[16036]: vchkpw-submission: password fail hello@example.com:91.230.30.142
Jul 24 19:56:39 mailserver vpopmail[18000]: vchkpw-submission: password fail hello@example.com:176.115.59.82
Jul 24 20:02:02 mailserver vpopmail[19925]: vchkpw-submission: password fail hello@example.com:37.215.9.145
Jul 24 20:12:06 mailserver vpopmail[21887]: vchkpw-submission: password fail hello@example.com:115.187.55.14