How to detect and prevent brute force attacks on Zimbra
การป้องกันเหล่าผู้ไม่ประสงค์ดีทำการเดา password ด้วยวิธีการ Brute-force attack สามารถทำได้โดยการตั้งค่า password policy บนระบบ ZIMBRA แต่ดูเหมือนวิธีการนี้จะไม่ช่วยให้เราสามารถแก้ไขปัญหาได้ครบถ้วน เพราะหากระบบทำการ lock out user ที่ถูกเดา password ไปแล้ว spammer ก็ยังสามารถใช้ user อื่น (กรณีที่รู้ user) ในการเดา password ได้
ดังนั้นการใช้งาน password policy เพียงอย่างเดียวอาจจะไม่ช่วยให้เราสามารถป้องกันการเดา password ด้วยวิธีการ Brute-force ได้ อีกทั้งอาจจะสร้างความรำคาญใจให้กับ user ที่ถูกใช้ในการเดา password อีกด้วยเพราะเมื่อเราปลด lock แล้วก็จะถูกโจมตีด้วย spammer อีกทำให้ user นี้ไม่สามารถใช้งานระบบ mail ได้อย่างต่อเนื่อง
วิธีการแก้ไขปัญหา
วิธีการแก้ไขปัญหานี้สามารถนำ fail2ban หรือ OSSEC เข้ามาช่วยในการป้องกันอีกขั้นหนึ่งเพื่อให้ spammer ที่ทำการเดา password ผิดแล้วจะถูก block ด้วย IP แทนการถูก lock ด้วย user ซึ่งหากใช้ควบคู่กับ password policy แล้วจะมีประสิทธิภาพการป้องกันได้อีกไม่น้อย
ในบทความนี้จะรำเสนอการติดตั้งและ config fail2ban บน ZIMBRA เพื่อเพิ่มความสามารถในการป้องกันได้อีกระดับ
การติดตั้งและ config fail2ban
-
ติดตั้ง EPEL repo เพิ่อให้สามารถติดตั้ง fail2ban ได้
[root@EzyMailHosting ~]# yum install fail2ban -
แก้ไข config ไฟล์ /etc/fail2ban/jail.conf โดยเพิ่มข้อมูลด้านล่างลงไป โดยให้แก้ไข bantime (หน่วยวินาที) และแก้ไขค่า maxretry ตามความต้องการ
[sasl-iptables] enabled = true filter = sasl backend = polling action = iptables-multiport[name=sasl, port="smtp,465,587", protocol=tcp] sendmail-whois[name=sasl, [email protected]] logpath = /var/log/maillog bantime = 86400 maxretry = 5 [postfix-iptables] enabled = true filter = postfix backend = polling action = iptables-multiport[name=postifx, port="smtp,465,587", protocol=tcp] sendmail-whois[name=postifx, [email protected]] logpath = /var/log/maillog bantime = 6400 maxretry = 5 [zimbra-account] enabled = true filter = zimbra action = iptables-allports[name=zimbra-account] sendmail[name=zimbra-account, [email protected]] logpath = /opt/zimbra/log/mailbox.log bantime = 86400 maxretry = 5 [zimbra-audit] enabled = true filter = zimbra action = iptables-allports[name=zimbra-audit] sendmail[name=Zimbra-audit, [email protected]] logpath = /opt/zimbra/log/audit.log bantime = 86400 maxretry = 5 [zimbra-recipient] enabled = true filter = zimbra action = iptables-allports[name=zimbra-recipient] sendmail[name=Zimbra-recipient, [email protected]] logpath = /var/log/maillog findtime = 900 bantime = 86400 maxretry = 5* หากต้องการเพิ่ม IP whitelist ก็สามารถแก้ไขและเพิ่มได้ที่ ignoreip เช่นต้องการเพิ่ม 192.168.0.0/24 เป็น whitelist ก็แก้ไขค่าดังนี้
ignoreip = 127.0.0.1/8 192.168.0.0/24 -
สร้างไฟล์ zimbra.conf ที่ /etc/fail2ban/filter.d/ โดยให้ copy ด้านล่างเข้าไป
[Definition] failregex = \[ip=<HOST>;\] account - authentication failed for .* \(no such account\)$ \[ip=<HOST>;\] security - cmd=Auth; .* error=authentication failed for .*, invalid password;$ ;oip=<HOST>;.* security - cmd=Auth; .* protocol=soap; error=authentication failed for .* invalid password;$ \[oip=<HOST>;.* SoapEngine - handler exception: authentication failed for .*, account not found$ WARN .*;ip=<HOST>;ua=ZimbraWebClient .* security - cmd=AdminAuth; .* error=authentication failed for .*;$ INFO .*ip=<HOST>;ua=zclient.*\] .* authentication failed for \[.*\], (invalid password|account not found)+$ # NOQUEUE: reject: RCPT from .*\[<HOST>\]: 550 5.1.1 .*: Recipient address rejected: -
การทำ start fail2ban service ด้วยคำสั่ง
[root@EzyMailHosting ~]# service fail2ban start