Pages

Subscribe:

Ads 468x60px

Labels

顯示具有 email 標籤的文章。 顯示所有文章
顯示具有 email 標籤的文章。 顯示所有文章

2015年9月11日 星期五

SPF 設定格式教學

資料來源 台網中心電子報
1. 定義使用的 SPF 版本
例如: v=spf1
2. 設定內容
例如: 授權6.6.6.6及7.7.7.7兩台郵件伺服器,設定內容如下:
ip4:6.6.6.6 ip4:7.7.7.7 ~all
設定內容可授權一到多組網路位址(IPv4 / IPv6),網路位址也能是網段(CIDR)。授權網路位址之後通常會加上all設定、include設定。
  1. all 機制為測試結果總是為符合(match) 。
  2. include 機制為觸發遞迴執行 check_host()。
例如:v=spf1 include:example.com include:example.org -all
符號        check_host()結果    處理結果
"+"           Pass                         match
"-"            Fail                          not match
"~"           SoftFail                    not match
"?"           Neutral                     not match
關於all使用 “-” 或 “~”,需視需求使用。若只想將信件標註為未授權主機發送,並不想拒絕接收信件,請使用 “~”。
常用的設定
一、設定兩筆 SPF 設定
錯誤的設定
v=spf1 ip4:6.6.6.6 ~all
v=spf1 ip4:7.7.7.7 ~all
以上的設定將導致SPF檢查失敗. 請改為
v=spf1 ip4:6.6.6.6 ip4:7.7.7.7 ~all
二、設定網段
v=spf1 ip4:6.6.6.0/24 ~all
三、匯入其他網段設定
v=spf1 include:_spf.goodsender.com.tw ~all
_spf.goodsender.com.tw SPF 設定為 v=spf1 ip4:6.6.6.6 ~all
四、參考GMail設定
使用 dig 指令查詢網域的SPF設定,查詢資料類型請使用TXT。
(1) # dig @8.8.8.8 gmail.com TXT
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @8.8.8.8 gmail.com TXT
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- 48488="" br="" id:="" noerror="" opcode:="" query="" status:="">;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;gmail.com.                     IN      TXT
;; ANSWER SECTION:
gmail.com.              299     IN      TXT     "v=spf1 redirect=_spf.google.com"
;; Query time: 15 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Aug 19 10:35:05 2014
;; MSG SIZE  rcvd: 71
可以看到 Gmail 轉向使用 google.com 的設定
(2) # dig @8.8.8.8 _spf.google.com TXT
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @8.8.8.8 _spf.google.com TXT
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- 22749="" br="" id:="" noerror="" opcode:="" query="" status:="">;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;_spf.google.com.               IN      TXT
;; ANSWER SECTION:
_spf.google.com.        279     IN      TXT     "v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"
;; Query time: 11 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Aug 19 10:35:21 2014
;; MSG SIZE  rcvd: 149
可以看到 google.com 匯入三組設定 _netblocks.google.com、 _netblocks2.google.com、_netblocks3.google.com,選擇 _netblocks.google.com 看看其中的設定。
(3) # dig @8.8.8.8 _netblocks.google.com TXT
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @8.8.8.8 _netblocks.google.com TXT
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- 17859="" br="" id:="" noerror="" opcode:="" query="" status:="">;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;_netblocks.google.com.         IN      TXT
;; ANSWER SECTION:
_netblocks.google.com.  3599    IN      TXT     "v=spf1 ip4:216.239.32.0/19 ip4:64.233.160.0/19 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:209.85.128.0/17 ip4:66.102.0.0/20 ip4:74.125.0.0/16 ip4:64.18.0.0/20 ip4:207.126.144.0/20 ip4:173.194.0.0/16 ~all"
;; Query time: 12 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Aug 19 10:36:20 2014
;; MSG SIZE  rcvd: 254
可以看到 _netblocks.google.com 設定授權多組網段。
TWNIC 如何設定 SPF
1. DNS設定使用代管
(1) 登入 RS 網站選擇DNS 設定/代管
(2) 選擇進階模式,輸入主機名稱、設定型態及IP/名稱。
(3) 填寫完成,等候DNS設定生效。
2. DNS設定自行架設主機管理
請至 DNS 服務供應商網站或DNS伺服器設定檔加上一筆TXT設定,設定內容請參考代管設定。
參考資料

防止我公司的 MAIL 不會被設定為 垃圾郵件(SPAM)


公司的業務和主管向你抱怨, Mail 寄出給國外客戶和廠商都收不到(跑倒垃圾信件匣) 甚至被當成垃圾郵件退回來?! 
這一篇是寫給公司 IT/MIS 人員參考 
1. 維護好公司的 smtp relay 安全

1.1 假設貴公司開放 SMTP ports 讓外部可以透過 smtp 發信 則要做好權限控管,沒有透過認證者 or IP 不再安全清單一律不許使用 SMTP 發信。 (也可考慮 VPN) 
1.2 定期檢查使用者是否濫用 SMTP 寄送非公司相關信件 
1.3 定期檢查使用者電腦是否中毒、中木馬成為發送廣告信的跳板 
1.4 教育使用者足夠的資訊安全概念 
1.5 請主要客戶、廠商幫忙,設定從公司來的郵件為「非垃圾郵件」 e.g. Google Gmail 篩選器 (Filter) -> 不要將它傳送到垃圾郵件 http://mail.google.com/support/bin/answer.py?hl=b5&answer=6579 
Yahoo奇摩 信箱的 「自動分類」 http://tw.promo.yahoo.com/tutorial/mail20/cg_filter1.html 
Microsoft Outlook 的 「安全的收件者」 http://office.microsoft.com/zh-tw/outlook/HP052433571028.aspx 


1.6 安裝相關的 Antivirus Mail Gateway or Mail-Server AntiVirus 
1.7 定期檢查 Delivery Failures 的信件, 看看是否有定期寄給客戶、廠商的 mail address 已經失效,sent failed 請聯絡他們更換 address,減少 send/deliver failures。 

2. 設定 DNS SPF TXT (Sender Policy Framework)記錄

詳細請看官網 http://www.openspf.org/ 
2.1 如何檢查 SPF TXT 記錄? => 使用 SPF 官網提供的 Tools http://www.openspf.org/Why http://www.kitterman.com/spf/validate.html 
=> 或者用 dig 來查詢 Google & Hinet's public DNS 代碼:
dig @8.8.8.8 -t TXT your-company-org-school.com dig @168.95.1.1 -t TXT your-company-org-school.com 


2.2 或者寄送一封信到 spf-test@openspf.org 然後一分鐘內,你就會收到一個退信, 裡面有 Result="pass" 表示通過 SPF 測試驗證 
如果是 Result="none" 那就表示 SPF 還沒有設定完成 
2.3 如果你是使用 Google Apps 應用服務 (Google 代管郵件) 
你的 SPF 應該長得是這樣子,都在同一行! 有 "double quote" 然後 all 前面是 ~ 波浪符號 代碼:
"v=spf1 include:aspmx.googlemail.com ~all" 


2.4 另外記住 TXT 也是 DNS entries 的一部分,DNS 生效需要 24~48 小時。 
2.5 舉例,成功的設定 SPF 會讓 Google Mail Gmail 更不會誤判垃圾信件 
Example BEFORE-SET-SPF-TXT "NEUTRAL" 未設定之前,判定為「中立」 代碼:
Received-SPF: neutral (google.com: 74.125.82.52 is neither permitted nor denied by domain of XXXXXXXX) client-ip=74.125.82.52; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.52 is neither permitted nor denied by domain of XXXXXXXXX) smtp.mail=XXXXXXXXX 

Example AFTER-SET-SPF-TXT "PASS" 設定之後,判定為「認證通過」 代碼:
Received-SPF: pass (google.com: domain of XXXXXXXXX designates 74.125.82.52 as permitted sender) client-ip=74.125.82.52; Authentication-Results: mx.google.com; spf=pass (google.com: domain of XXXXXXXXX designates 74.125.82.52 as permitted sender) smtp.mail=XXXXXXXXXXX 


3. 設定反查

相較於正查: Host Name / Domanin --> IP Address 所謂的反查就是 IP Address --> Host Name / Domain Name 
有一些 Mail server 會透過檢查反查來判定 SPAM 的分數。 設定反查在某些狀況可以降低被誤判的機率。 
如果公司自己有自己的 DNS server,就自己改 (記得 ns1, ns2, ns3 ... 所有 ns 都要改) 
如果是請 IDC/ISP 代管, 大部分的 IDC/ISP (Hinet/Seednet) 都可以請工程師幫忙設定反查,應該也免費; 有 IDC/ISP 的和上述 TXT 一樣,提供 DNS manager 介面提供可設定。 
4. 減少強制附加「智財權聲明」簽名檔

有一些公司,在 outbound 的 mail 會強制附上 類似下面這種「智財、版權」聲明稿。 
英文叫做 legal statement signature legal declaration signature copyright statement signature ... 
而這個動作, 導致「郵件本文」有時候比「聲明簽名檔」還要小... 如果某一些舊機器判定的公式有這一條, 可能會增加被誤判的機率。 
建議: 換成適當大小的圖片、減少字數、或者選擇適當的顏色、適當的字體(例如避免,白底白字)。 

引言回覆:

本郵件之資訊可能含有受機密或特殊管制之資訊,僅供指定之收件人使用。若您並非指定之收件人,切勿轉寄、散佈、複製或公開本通訊內容之任何部份,並請即通知寄件人並完全刪除本郵件。
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. Please consider the environment before printing this email. 


5. 時常查詢是否貴公司已經在黑名單

SPAM Black List or Block List Query 
http://www.spamhaus.org/ http://www.spamhaus.org/lookup.lasso (SBL, XBL PBL) http://www.dnsstuff.com/tools http://www.openrbl.org/ 
時常檢查,或者寫一個簡單的 script 照三餐檢查。 

6. 避免公布貴公司的 Mail,防止 SPOOF

避免 SPAM/Spoof Address Spider 
6.1 有 Contact 需求請盡量用 Contact Web-Form or Skype or 電話號碼 
6.2 如果真要公布請用 E-Mail 圖片 (e-mail address 用圖片展示) 
6.3 盡量減少公布可以 group mail 的 address 


7. 考慮使用 DKIM or Domainkey 金鑰簽署郵件

e.g. 使用 Google Apps 提供的 DKIM 功能, 一樣是 DNS TXT FIELD 
代碼:
google._domainkey    v=DKIM1; k=rsa; p=ABCDEFG..... 



DKIM/DomainKeys 參考網址 http://www.dkim.org/ http://support.google.com/a/bin/answer.py?hl=zh-Hant&answer=174124 http://support.google.com/a/bin/answer.py?hl=zh-Hant&answer=180504&topic=2752442&ctx=topic 

實作如下圖,多了一個「金鑰簽署者欄位」