為我的WordPress做安全防護實錄

來源:互聯網
上載者:User

最近看了infosec 出品的<<Protecting WordPress Installations in an IaaS Environment》,決定給裸奔的wordpress做做安全強化。

wordpress是國人搭建個人部落格的首選,其地位等同於論壇搭建首選discuz(話說,discuz才報出全域變數繞過導致的命令執行大洞,唉,開源的APP都是不產蜜而產getshell的蜂巢)

wordpress以豐富的外掛程式(外掛程式漏洞)聞名,因此攻擊者一般會對wordpress來個指紋識別(除去找暴力破解/社工後台登陸口的快捷方法)

一、wpscan  – WordPress指紋識別及漏洞檢查工具

該網站被喪心病狂的GFW封掉了,翻牆吧psiphon搔年,或者使用滲透套裝kali(重點不是wpscan,瞭解攻擊才能給出相應防禦措施)

a.安裝

以ubuntu安裝為例

apt-get install libcurl4-gnutls-dev libxml2 libxml2-dev libxslt1-dev ruby-dev build-essential
git clone https://github.com/wpscanteam/wpscan.git
cd wpscan/
gem install bundler && bundle install --without test

b.基本使用

枚舉網站資訊:使用者名稱、外掛程式、樣式等資訊

ruby wpscan.rb --url www.tanjiti.com --enumerate

察看詳細的探測資訊

ruby wpscan.rb --url www.tanjiti.com --debug-output --random-agent >debug.log

(注意:wpscan 預設User-Agent為WPScan v2.5.1 (http://wpscan.org),掃描器使用常識之一使用正常變化的ua,避免觸發WAF之類的防禦部署)
基本察看LOG,我們就可以知道wpscan是如何收集資訊
例如檢查回應標頭X-Pingback: http://www.tanjiti.com/xmlrpc.php 頭 (xmlrpc漏洞)
檢查xmlrpc.php (xmlrpc漏洞)
檢查robots.txt檔案 (敏感資訊泄露)
檢查readme.html檔案(敏感資訊泄露)
檢查/wp-content/debug.log(敏感資訊泄露)
檢查設定檔(能夠明文讀取設定檔基本就是掛掉了),wp-config.php.swo,%23wp-config.php%23,wp-config.orig,wp-config.php_bak,wp-config.original,wp-config.php.orig,wp-config.php.old,.wp-config.php.swp,wp-config.php.save,wp-config.bak,wp-config.txt,wp-config.php~ ,wp-config.save ,wp-config.old,wp-config.php.swp (敏感資訊泄露)
識別指紋後,一般會去漏洞資訊庫中尋找可以利用的漏洞,例如MSF

二、MSF-wordpress漏洞利用(已方使用就是漏洞掃描)


msf > search wordpress
 
Matching Modules
================
 
   Name                                                      Disclosure Date  Rank       Description
   ----                                                      ---------------  ----       -----------
   auxiliary/admin/http/wp_custom_contact_forms              2014-08-07       normal     WordPress custom-contact-forms Plugin SQL Upload
   auxiliary/dos/http/wordpress_xmlrpc_dos                   2014-08-06       normal     WordPress XMLRPC DoS

以前段時間有名的XMLRPC DoS為例(漏洞說明見 《[科普]什麼是 billion laughs-WordPress與Drupal的DoS攻擊有感》)

msf > use auxiliary/dos/http/wordpress_xmlrpc_dos
msf auxiliary(wordpress_xmlrpc_dos) > show options
 
Module options (auxiliary/dos/http/wordpress_xmlrpc_dos):
 
   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   Proxies                     no        Use a proxy chain
   RHOST                       yes       The target address
   RLIMIT     1000             yes       Number of requests to send
   RPORT      80               yes       The target port
   TARGETURI  /                yes       The base path to the wordpress application
   VHOST                       no        HTTP server virtual host
 
msf auxiliary(wordpress_xmlrpc_dos) > set RHOST www.tanjiti.com
RHOST => xxx
msf auxiliary(wordpress_xmlrpc_dos) > set TARGETURI /
TARGETURI => /wordpress/wordpress/
msf auxiliary(wordpress_xmlrpc_dos) > run

(再次強調,重點不是Metasploit,瞭解攻擊才能給出相應防禦措施)

三、wordpress防護——使用ModSecurity進行防護


安裝及規則編寫的基礎知識見《[科普文]ubuntu上安裝Apache2+ModSecurity及自訂WAF規則》

vim /usr/share/modsecurity-crs/activated_rules/MY.conf

(1) 添加防禦xmlrpc漏洞的規則

SecRule REQUEST_URI "@endsWith /xmlrpc.php" "deny,tag:'WEB_ATTACK/WORDPRESS',msg:'block wordpress xmlrpc.php',id:0000003,phase:2"

service apache2 restart

使用MSF發送攻擊包

msf auxiliary(wordpress_xmlrpc_dos) > use auxiliary/scanner/http/wordpress_pingback_access
msf auxiliary(wordpress_pingback_access) > show options
 
Module options (auxiliary/scanner/http/wordpress_pingback_access):
 
   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   Proxies                     no        Use a proxy chain
   RHOSTS                      yes       The target address range or CIDR identifier
   RPORT      80               yes       The target port
   TARGETURI  /                yes       The path to wordpress installation (e.g. /wordpress/)
   THREADS    1                yes       The number of concurrent threads
   VHOST                       no        HTTP server virtual host
 
msf auxiliary(wordpress_pingback_access) > set RHOSTS www.tanjiti.com
RHOSTS => xxx
msf auxiliary(wordpress_pingback_access) > set TARGETURI /
TARGETURI => /wordpress/wordpress/
msf auxiliary(wordpress_pingback_access) > run

可以看到攔截日誌如下

Message: Warning. String match "/xmlrpc.php" at REQUEST_URI. [file "/usr/share/modsecurity-crs/activa
ted_rules/MY.conf"] [line "4"] [id "0000003"] [msg "block wordpress xmlrpc.php"] [tag "WEB_ATTACK/WOR
DPRESS"]

(2) 添加防禦wpscan預設掃描磁頭的規則

SecRule REQUEST_HEADERS:User-Agent "@contains wpscan" "t:lowercase,deny,tag:'WEB_ATTACK/WORDPRESS',ms
g:'block wpscanner default useragent',id:0000004,phase:1"

再次運行wpscan,可以看到攔截日誌如下

essage: Warning. String match "wpscan" at REQUEST_HEADERS:User-Agent. [file "/usr/share/modsecurity-
crs/activated_rules/MY.conf"] [line "6"] [id "0000004"] [msg "block wpscanner default useragent"] [ta
g "WEB_ATTACK/WORDPRESS"]

大夥可以針對性地添加規則,對個人網站而已,添加白規則較之黑規則會事半功倍,這裡的樣本規則僅僅是拋磚引玉。

四、wordpress防護——屏蔽敏感資訊訪問


vim /etc/apache2/apache2.conf
<FilesMatch ".(sw[po]|old|save|bak|orig(?:inal)?|php(?:~|_bak|x23))$">
        Require all denied
</FilesMatch>
service apache2 restart

五、wordpress防護——啟用安全頭


vim /etc/apache2/conf-available/security.conf

(1) 防止在IE9、chrome和safari中的MIME類型混淆攻擊

Header set X-Content-Type-Options: "nosniff"
(2) 防止clickjacking,只允許遵守同源策略的資源(和網站同源)通過frame載入那些受保護的資源。

Header set X-Frame-Options: "sameorigin"
(3) 開啟xss防護並通知瀏覽器阻止而不是過濾使用者注入的指令碼。

Header set X-XSS-Protection "1;mode=block"
service apache2 restart

六、wordpress防護——登陸口防爆破

一般的方法是設定一個登陸口白名單,但現在越來越多的網站使用CDN服務,明顯不再是個好的防護方案
安裝Login LockDown 外掛程式,wordpress後台外掛程式管理處搜尋即可,設定也超級簡單

設定執行個體:



如果在5分鐘失敗3次就會封鎖IP60分鐘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.