本篇筆者介紹關于加密的電子郵件,郵件在使用pop3和smtp協定傳輸的過程中。都是基于明文的傳輸,如果網絡上有人抓包,則可能丢失賬号資訊,導緻郵件内容被盜。本篇筆者
使用CA伺服器為郵件發送伺服器(sendmail)和郵件接收伺服器(dovecot)頒發證書,實作電子郵件的安全傳輸。這裡使用smtps(端口号465)和pop3(端口号995),兩外
還有imaps(加密的郵件接收協定,端口号993)
思路:建立使用者user1和user2,搭建dns伺服器,搭建sendmail和dovecot,發送郵件,然後抓包,檢視是否能獲得賬号和密碼;然後搭建CA伺服器,并為sendmail和dovecot伺服器頒發證書,發送郵件,檢視是否能獲得賬号和密碼。
修改主機名:
[root@lyt ~]# vim /etc/sysconfig/network
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631848Yjfu.png"></a>
[root@lyt ~]# vim /etc/hosts
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_134763184988f6.png"></a>
[root@lyt ~]# hostname mail.163.com #使用此指令使剛才修改的主機名生效,這樣就不用再重新開機系統了
[root@lyt ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo #編輯本地yum
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631850Rw4x.png"></a>
[root@lyt ~]# mkdir /mnt/cdrom
[root@lyt ~]# mount /dev/cdrom /mnt/cdrom/
[root@lyt ~]# cd /mnt/cdrom/Server/
[root@lyt Server]# yum install wireshark –y #安裝wireshark抓包工具
建立使用者:
[root@lyt Server]# useradd user1 #建立使用者user1
[root@lyt Server]# passwd user1 #為user1建立密碼
[root@lyt Server]# useradd user2
[root@lyt Server]# passwd user2
搭建dns伺服器:
[root@lyt Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm
[root@lyt Server]# rpm -ivh bind-chroot-9.3.6-4.P1.el5.i386.rpm
[root@lyt Server]# rpm -ivh caching-nameserver-9.3.6-4.P1.el5.i386.rpm
[root@lyt Server]# cd /var/named/chroot/etc/
[root@lyt etc]# cp -p named.caching-nameserver.conf named.conf
[root@lyt etc]# vim named.conf
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631851GorM.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631852GGGL.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631855pHdG.png"></a>
[root@lyt etc]# vim named.rfc1912.zones
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631856oNPL.png"></a>
[root@lyt etc]# cd ../var/named/
[root@lyt named]# cp -p localhost.zone 163.com.db
[root@lyt named]# vim 163.com.db
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476318571bkj.png"></a>
[root@lyt named]# service named start
[root@lyt named]# chkconfig named on #設定開機啟動
[root@lyt named]# vim /etc/resolv.conf
搭建sendmail伺服器(郵件發送服務):
[root@lyt named]# cd /mnt/cdrom/Server/
[root@lyt Server]# rpm -qa |grep sendmail #檢視安裝與sendmail有關的已經安裝的軟體包
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631859UMdF.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476318602lry.png"></a>
[root@lyt Server]# rpm -ivh sendmail-cf-8.13.8-2.el5.i386.rpm #該軟體包用于直接編輯sendmail.mc檔案,不用編輯sendmail.cf檔案
[root@lyt Server]# cd /etc/mail
[root@lyt mail]# vim sendmail.mc #編輯sendmail的主配置文檔
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631861CYwI.png"></a>
[root@lyt mail]# vim access #編輯sendmail的中繼檔案
[root@lyt mail]# vim local-host-names
搭建dovecot(郵件接收):
[root@lyt mail]# cd /mnt/cdrom/Server/
[root@lyt Server]# yum install dovecot –y
[root@lyt Server]# service dovecot start
[root@mail Server]# chkconfig dovecot on #設定開機自動啟動
注:在windows server 2003主機上建立電子郵件使用者user1和user2的方法在(上)篇中已經給出,這裡不再詳述
抓包檢視能否獲得使用者名和密碼:使用windows server 2003測試:
[root@mail Server]# tshark -ni eth0 -R "tcp.dstport eq 110" #如圖是以,可以看到使用者名和密碼
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631865uMXT.png"></a>
搭建CA伺服器:
[root@lyt Server]# cd /etc/pki/tls/
[root@lyt tls]# vim openssl.cnf
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631867z7ir.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476318686M3e.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631870xv6L.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631874bdL1.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631877ZM1j.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476318782p3a.png"></a>
[root@mail tls]# cd /etc/pki/CA/
[root@mail CA]# mkdir crl #放置證書吊銷清單
[root@mail CA]# mkdir certs #已經發行過的證書存放的位置
[root@mail CA]# mkdir newcerts #新發行的證書存放位置
[root@mail CA]# touch serial #頒發證書的初始值
[root@mail CA]# touch index.txt #資料庫的索引檔案
[root@mail CA]# echo "01"&gt;serial #将01賦予serial,作為初始值
[root@mail CA]# openssl genrsa 1024 &gt; private/cakey.pem #利用1024的非對稱加密算法rsa,算出一個密鑰放置在cakey.com檔案中
[root@mail CA]# chmod 600 private/cakey.pem #将cakey.com檔案設定為600
[root@mail CA]# openssl req -new -key private/cakey.pem -x509 -out cacert.pem -days 3650 ##利用自己的私鑰為自己(CA伺服器)産生一個證書叫
cacert.pem。-x509表示證書類型,證書有效時間3650天,-out表示輸出
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631883bpUS.png"></a>
[root@mail CA]# mkdir -pv /etc/mail/certs #為sendmail伺服器産生一個存放私鑰,證書請求檔案,證書的目錄
[root@mail CA]# cd /etc/mail/certs/
[root@mail certs]# openssl genrsa 1024 &gt;sendmail.key #為sendmail伺服器端産生一個私鑰
[root@mail certs]# openssl req -new -key sendmail.key -out sendmail.csr #利用私鑰産生一個證書請求檔案sendmail.csr
[root@mail certs]# openssl ca -in sendmail.csr -out sendmail.cert #利用證書請求檔案sendmail.csr産生一個證書叫做sendmail.cert
[root@mail certs]# chmod 600 * #将目前目錄中所有的檔案權限修改為600
[root@mail certs]# vim /etc/mail/sendmail.mc #編輯該檔案
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631894I5O8.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631895EIwN.png"></a>
[root@mail certs]# service sendmail restart
[root@mail certs]# telnet 127.0.0.1 25 #使用telnet登入本地郵件伺服器
在windows server 2003上user1發送郵件作為測試:
[root@mail Server]# tshark -ni eth0 -R "tcp.dstport eq 25" #使用tsharek抓包工具抓包,檢視能否抓獲郵件用戶端的使用者名和密
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631903F4Bs.png"></a>
由于在windows server 2003上沒有安裝證書,故出現下面情況:
抓包檢視能否獲得使用者名和密碼:
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631908nOwS.png"></a>
使用CA伺服器為郵件伺服器頒發證書之後,所抓的資料包全都是加密的
[root@mail Server]# pkill -9 tshark #終止tshark工具
[root@mail Server]# jobs #檢視tshark是否還在背景運作
為郵件接收服務建立證書:
[root@mail Server]# mkdir -pv /etc/dovecot/certs
[root@mail Server]# cd /etc/dovecot/certs/
[root@mail certs]# openssl genrsa 1024 &gt;dovecot.key
[root@mail certs]# openssl req -new -key dovecot.key -out dovecot.csr
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631914u2Iv.png"></a>
[root@mail certs]# openssl ca -in dovecot.csr -out dovecot.cert #利用請求證書檔案申請證書dovecot.cert
[root@mail certs]# vim /etc/dovecot.conf #編輯該檔案
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631916XCcE.png"></a>
[root@mail certs]# service dovecot restart #重新開機dovecot服務
在windows server 2003上user2接收郵件作為測試:
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631917UGlk.png"></a>
[root@mail certs]# tshark -ni eth0 -R "tcp.dstport eq 995" #針對995端口進行抓包
由于在windows server 2003上沒有安裝證書,故出現下面情況:
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631921yhjL.png"></a>
<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476319254Tl5.png"></a>
本文轉自 liuyatao666 51CTO部落格,原文連結:http://blog.51cto.com/5503845/991090,如需轉載請自行聯系原作者