Latest News

Home » openwebmail » 【Linux主機】郵件工具OpenWebmail的安裝與設定

【Linux主機】郵件工具OpenWebmail的安裝與設定

郵件工具OpenWebmail 因習慣上有大多數再使用,以下總教頭針對OpenWebmail的安裝做詳細的說明
要如何自己安裝 openwebmail 呢?

以下的語法執行動作,均是以 root 身份,在 /root 目錄底下運作。
(請先確認linux 主機更新表列設置網址是否正確?)

套件庫設定:

資料夾:/etc/apt
套件庫設定檔: /etc/apt/sources.list
—————————————————————–
先執行:   
       apt-get update
—————————————————————–
移除(否則無法安裝 OpenWebmail):
    apt-get remove libcrypt-eksblowfish
—————————————————————–
 安裝所需套件:   apt-get install libparent-perl perl-suid libnet-ldap-perl libauthen-pam-perl libpg-perl libconvert-asn1-perl libcrypt-eksblowfish-perl
—————————————————————–
下載OpenWebmail套件:
    wget http://ftp.debian.org/pool/main/libm/libmd5-perl/libmd5-perl_2.03-1_all.deb
    wget http://openwebmail.org/openwebmail/download/debian/owm2.53-2.deb
—————————————————————–
執行下載套件之安裝:
    dpkg -i *.deb
—————————————————————–
更換檔案:  
下載:
wget http://myip.tw/download/auth_unix.pl.zip
解壓縮:
    unzip auth_unix.pl.zip
更換:
    cd /usr/lib/cgi-bin/openwebmail/auth/
    mv auth_unix.pl auth_unix.pl.old
    cp /root/auth_unix.pl ./
    cd
—————————————————————–
執行安裝時 Openwebmail 設定訊息
Send the site report?(Y/n) n
—————————————————————–
網址路徑修正(網址輸入簡便):

    debian:~# cd /var/www/openwebmail/
    debian:/var/www/openwebmail# mv index.html b_index.html
    debian:/var/www/openwebmail# ln -s redirect.html index.html

    檢查/etc/mailname是否為正常的主機名稱?
打開瀏覽器輸入http://你的網址/openwebmail
使用IP分享器內部連線時(例如):

http://192.168.0.3/openwebmail
*****************************************************************
如果您要將Openwebmail 加密的網頁通道(HTTPS; 443)其設定如下:

把 OpenWebmail 納入加密的網頁通道(HTTPS; 443)

把 OpenWebmail 納入加密的網頁通道(HTTPS; 443)最大的好處在於,使用者於公眾網路(餐廳、車站…etc)收發信件時,所有傳輸的封包皆被加密,因此若網段內有人偷裝封包攔截器,也無法直接取得使用者的帳號、密碼及信件內容等個人資料。

為 apache2 建置 ssl 通道

請參考右文: 在Linux 上建立加密網頁通訊

把 OpenWebmail 改為 HTTPS

    編輯 /usr/lib/cgi-bin/openwebmail/openwebmail.pl , 在最上面註解下面, 加上

#
if ($ENV{'HTTPS'} ne 'on') {
   print "Content-type: text/html ";
   print <<HERE;
<html>
<head><meta http-equiv="Refresh" content="0;URL=https://$ENV{'HTTP_HOST'}/cgi-bin/openwebmail/openwebmail.pl">
</head>
<body onload="window.open('https://$ENV{'HTTP_HOST'}/cgi-bin/openwebmail/openwebmail.pl','_top')">
</body>
</html>

HERE

   exit;
}

    本段是說, 若使用者輸入 http://your.host.name/openwebmail/ 強制轉到 https 通道

———————————————————————————

OpenWebmail資安–Fail2Ban

要使用 fail2ban 的原因在於網路上有很多網蟲會使用 network script 不斷的 try OpenWebmail 上使用者密碼,一旦被試中,立即變成垃圾信的跳板。
因此就如同 denyhosts 之於 SSH 服務一樣,可以採用 fail2ban 來防止駭客透過 OpenWebmail 猜使用者密碼。

Fail2ban 是一套使用 Python 開發,並以自由軟體授權(GPLv2)的資安軟體。
它可藉由分析記錄檔,對「猜測密碼」的行為具有一定程度的阻擋作用。因此它適用於 ftp, SSH, mail 等系統。

    官網 http://www.fail2ban.org
    中文文件 http://net.nthu.edu.tw/2009/security:fail2ban

———————————————————————————
作法
 Linux sqz 安裝
        root@dns:~# apt-get update
        root@dns:~# apt-get install fail2ban
—————————————————–
執行 client 程式測試,若可正常跑出使用說明即代表安裝完成
        fail2ban-client -h

—————————————————–
設定

要修改兩個設定檔,一個是 /etc/fail2ban/jail.conf –> 設定要啟用 openwebmail 的防禦;
另一個是配套設定檔 /etc/fail2ban/filter.d/openwebmail-auth.conf ,這裡頭放了過濾的細則。

    編輯 /etc/fail2ban/jail.conf 並修改/新增(紅字部分)部分內容

# 以下這三個參數值,請自行斟酌修改

# 其意義為:在 findtime 秒之內,密碼輸入錯誤高達 maxretry 次以上時,便得阻擋 bantime 秒
bantime = 1200
findtime = 20
maxretry = 5

[openwebmail-auth]

enabled = true
filter = openwebmail-auth
# action 是指:符合狀況時,使用 iptables 來阻擋對方 ip adress
# sendmail-whois 是指:出現任何狀況(啟動/關閉/阻擋)時,皆以 email 通知 admin
action = iptables[name=openwebmail-auth, port=http, protocol=tcp]
      sendmail-whois[name=openwebmail, dest=me@example.com]
logpath = /var/log/openwebmail.log

—————————————————–
    新增 /etc/fail2ban/filter.d/openwebmail-auth.conf

# Author: Cyril Jaquier
# $Revision: 569

[Definition]

# Option: failregex
# Notes.: regex to match the password failure messages in the logfile. The
#         host must be matched by a group named "host". The tag "<HOST>" can
#         be used for standard IP/hostname matching and is only an alias for
#         (?:::f{4,6}:)?(?P<host>S+)
# Values: TEXT
#
failregex = (<HOST>) .* Password incorrect
            (<HOST>) .* no such user

# Option:  ignoreregex
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
# Values:  TEXT
#
ignoreregex =

—————————————————–
啟動/關閉

    B2D Server
    由於 B2D Server 必須由原始碼安裝,因此無法套用至 ntsysv 或使用 service 指令來處理。
        啟動
        root@dns~# fail2ban-client start
        關閉
        root@dns~# fail2ban-client stop
        將下面指令寫入 /etc/init.d/rc.local 最後一行即可在開機時自動啟動

strFail2ban=$(netstat -nlp|grep fail2ban.sock)
if [ "$strFail2ban" == "" ]; then
   /usr/bin/fail2ban-client start
fi

   Linux 啟動/關閉
        啟動
        root@dns:~# service fail2ban start
        關閉
        root@dns:~# service fail2ban stop
        永遠啟用,請執行 ntsysv 設定
—————————————————–

About

發佈留言