數百萬個網站用着 WordPress ,這當然是有原因的。WordPress 是眾多內容管理系統中對開發者最友好的,本質上說你可以用它做任何事情。不幸的是,每天都有些嚇人的報告說某個主要的網站被黑了,或者某個重要的數據庫被泄露了之類的,嚇得人一愣一愣的。
如果你還沒有安裝 WordPress ,可以看下下面的文章。
在基於 Debian 的系統上:
在基於 RPM 的系統上:
我之前的文章 如何安全加固 WordPress 站點 里面列出的備忘錄為讀者維護 WordPress 的安全提供了一點幫助。
在這篇文章里面,我將介紹 wpscan 的安裝過程,以及怎樣使用 wpscan 來定位那些已知的會讓你的站點變得易受攻擊的插件和主題。還有怎樣安裝和使用一款免費的網絡探索和攻擊的安全掃描軟件 nmap 。最后展示的是使用 nikto 的步驟。

(題圖來自:codersmount.com)
用 WPScan 測試 WordPress 中易受攻擊的插件和主題
WPScan 是一個 WordPress 黑盒安全掃描軟件,用 Ruby 寫成,它是專門用來尋找已知的 WordPress 的弱點的。它為安全專家和 WordPress 管理員提供了一條評估他們的 WordPress 站點的途徑。它的基於開源代碼,在 GPLv3 下發行。
下載和安裝 WPScan
在我們開始安裝之前,很重要的一點是要注意 wpscan 不能在 Windows 下工作,所以你需要使用一台 Linux 或者 OS X 的機器來完成下面的事情。如果你只有 Windows 的系統,拿你可以下載一個 Virtualbox 然后在虛擬機里面安裝任何你喜歡的 Linux 發行版本。
WPScan 的源代碼放在 Github 上,所以需要先安裝 git(LCTT 譯注:其實你也可以直接從 Github 上下載打包的源代碼,而不必非得裝 git )。
sudo apt-get install git
git 裝好了,我們就要安裝 wpscan 的依賴包了。
sudo apt-get install libcurl4-gnutls-dev libopenssl-ruby libxml2 libxml2-dev libxslt1-dev ruby-dev ruby1.9.3
把 wpscan 從 github 上 clone 下來。
git clone https://github.com/wpscanteam/wpscan.git
現在我們可以進入這個新建立的 wpscan 目錄,通過 bundler 安裝必要的 ruby 包。
cd wpscansudo gem install bundler && bundle install --without test development
現在 wpscan 裝好了,我們就可以用它來搜索我們 WordPress 站點潛在的易受攻擊的文件。wpcan 最重要的方面是它能列出不僅是插件和主題,也能列出用戶和縮略圖的功能。WPScan 也可以用來暴力破解 WordPress —— 但這不是本文要討論的內容。
更新 WPScan
ruby wpscan.rb --update
列舉插件
要列出所有插件,只需要加上 “--enumerate p” 參數,就像這樣:
ruby wpscan.rb --url http(s)://www.yoursiteurl.com --enumerate p
或者僅僅列出易受攻擊的插件:
ruby wpscan.rb --url http(s)://www.yoursiteurl.com --enumerate vp
下面是一些例子:
| Name: ukiscet| Location: http://********.com/wp-content/plugins/akismet/| Name: audio-player| Location: http://********.com/wp-content/plugins/audio-player/|| * Title: Audio Player - player.swf playerID Parameter XSS| * Reference: http://seclists.org/bugtraq/2013/Feb/35| * Reference: http://secunia.com/advisories/52083| * Reference: http://osvdb.org/89963| * Fixed in: 2.0.4.6| Name: bbpress - v2.3.2| Location: http://********.com/wp-content/plugins/bbpress/| Readme: http://********.com/wp-content/plugins/bbpress/readme.txt|| * Title: BBPress - Multiple Script Malformed Input Path Disclosure| * Reference: http://xforce.iss.net/xforce/xfdb/78244| * Reference: http://packetstormsecurity.com/files/116123/| * Reference: http://osvdb.org/86399| * Reference: http://www.exploit-db.com/exploits/22396/|| * Title: BBPress - forum.php page Parameter SQL Injection| * Reference: http://xforce.iss.net/xforce/xfdb/78244| * Reference: http://packetstormsecurity.com/files/116123/| * Reference: http://osvdb.org/86400| * Reference: http://www.exploit-db.com/exploits/22396/| Name: contact| Location: http://********.com/wp-content/plugins/contact/
列舉主題
列舉主題和列舉插件差不多,只要用"--enumerate t"就可以了。
ruby wpscan.rb --url http(s)://www.host-name.com --enumerate t
或者只列出易受攻擊的主題:
ruby wpscan.rb --url http(s)://www.host-name.com --enumerate vt
例子的輸出:
| Name: path| Location: http://********.com/wp-content/themes/path/| Style URL: http://********.com/wp-content/themes/path/style.css| Description:| Name: pub| Location: http://********.com/wp-content/themes/pub/| Style URL: http://********.com/wp-content/themes/pub/style.css| Description:| Name: rockstar| Location: http://********.com/wp-content/themes/rockstar/| Style URL: http://********.com/wp-content/themes/rockstar/style.css| Description:|| * Title: WooThemes WooFramework Remote Unauthenticated Shortcode Execution| * Reference: https://gist.github.com/2523147| Name: twentyten| Location: http://********.com/wp-content/themes/twentyten/| Style URL: http://********.com/wp-content/themes/twentyten/style.css| Description:
列舉用戶
WPscan 也可以用來列舉某個 WordPress 站點的用戶和有效的登錄記錄。攻擊者常常這么做——為了獲得一個用戶清單,好進行暴力破解。
ruby wpscan.rb --url http(s)://www.host-name.com --enumerate u
列舉 Timthumb 文件
關於 WPscan ,我要說的最后一個功能是列舉 timthub (縮略圖)相關的文件。近年來,timthumb 已經成為攻擊者眼里的一個常見目標,因為無數的漏洞被找出來並發到論壇上、郵件列表等等地方。用下面的命令可以通過 wpscan 找出易受攻擊的 timthub 文件:
ruby wpscan.rb --url http(s)://www.host-name.com --enumerate tt
用 Nmap 掃描你 VPS 的開放端口
Nmap 是一個開源的用於網絡探索和安全審查方面的工具。它可以迅速掃描巨大的網絡,也可一單機使用。Nmap 用原始 IP 數據包通過不同尋常的方法判斷網絡里那些主機是正在工作的,那些主機上都提供了什么服務(應用名稱和版本),是什么操作系統(以及版本),用的什么類型的防火牆,以及很多其他特征。
在 Debian 和 Ubuntu 上下載和安裝 nmap
要在基於 Debian 和 Ubuntu 的操作系統上安裝 nmap ,運行下面的命令:
sudo apt-get install nmap
輸出樣例
Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following NEW packages will be installed:nmap0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.Need to get 1,643 kB of archives.After this operation, 6,913 kB of additional disk space will be used.Get:1 http://mirrors.service.networklayer.com/ubuntu/ precise/main nmap amd64 5.21-1.1ubuntu1 [1,643 kB]Fetched 1,643 kB in 0s (16.4 MB/s)Selecting previously unselected package nmap.(Reading database ... 56834 files and directories currently installed.)Unpacking nmap (from .../nmap_5.21-1.1ubuntu1_amd64.deb) ...Processing triggers for man-db ...Setting up nmap (5.21-1.1ubuntu1) ...
舉個例子
輸出 nmap 的版本:
nmap -V
或者
nmap --version
輸出樣例
Nmap version 5.21 ( http://nmap.org )
在 Centos 上下載和安裝 nmap
要在基於 RHEL 的 Linux 上面安裝 nmap ,輸入下面的命令:
yum install nmap
輸出樣例
Loaded plugins: protectbase, rhnplugin, security0 packages excluded due to repository protectionsSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package nmap.x86_64 2:5.51-2.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================Package Arch Version Repository Size================================================================================Installing:nmap x86_64 2:5.51-2.el6 rhel-x86_64-server-6 2.8 MTransaction Summary================================================================================Install 1 Package(s)Total download size: 2.8 MInstalled size: 0Is this ok [y/N]: yDownloading Packages:nmap-5.51-2.el6.x86_64.rpm | 2.8 MB 00:00Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionInstalling : 2:nmap-5.51-2.el6.x86_64 1/1Verifying : 2:nmap-5.51-2.el6.x86_64 1/1Installed:nmap.x86_64 2:5.51-2.el6Complete!
舉個例子
輸出 nmap 版本號:
nmap --version
輸出樣例
Nmap version 5.51 ( http://nmap.org )
用 Nmap 掃描端口
你可以用 nmap 來獲得很多關於你的服務器的信息,它可以讓你站在對你的網站不懷好意的人的角度看你自己的網站。
因此,請僅用它測試你自己的服務器或者在行動之前通知服務器的所有者。
nmap 的作者提供了一個測試服務器:
scanme.nmap.org
有些命令可能會耗時較長:
要掃描一個 IP 地址或者一個主機名(全稱域名),運行:
nmap 192.168.1.1
輸出樣例:

Fig.01: nmap in action
掃描以獲得主機的操作系統:
sudo nmap -O 192.168.1.1
加上“-”或者“/24”來一次性掃描某個范圍里面的多個主機:
sudo nmap -PN xxx.xxx.xxx.xxx-yyy
掃描某個范圍內可用的服務:
sudo nmap -sP network_address_range
掃描 IP 地址時部進行反向 DNS 解析。多數情況下這會加快你獲得結果的速度:
sudo nmap -n remote_host
掃描一個特定端口而不是所有常用端口:
sudo nmap -p port_number remote_host
掃描一個網絡,找出哪些服務器在線,分別運行了什么服務。
這就是傳說中的主機探索或者 ping 掃描:
nmap -sP 192.168.1.0/24
輸出樣例:
Host 192.168.1.1 is up (0.00035s latency).MAC Address: BC:AE:C5:C3:16:93 (Unknown)Host 192.168.1.2 is up (0.0038s latency).MAC Address: 74:44:01:40:57:FB (Unknown)Host 192.168.1.5 is up.Host nas03 (192.168.1.12) is up (0.0091s latency).MAC Address: 00:11:32:11:15:FC (Synology Incorporated)Nmap done: 256 IP addresses (4 hosts up) scanned in 2.80 second
理解端口配置和如何發現你的服務器上的攻擊目標只是確保你的信息和你的 VPS 安全的第一步。
用 Nikto 掃描你網站的缺陷
Nikto 網絡掃描器是一個開源的 web 服務器的掃描軟件,它可以用來掃描 web 服務器上的惡意的程序和文件。Nikto 也可以用來檢查軟件版本是否過期。Nikto 能進行簡單而快速地掃描以發現服務器上危險的文件和程序。掃描結束后會給出一個日志文件。`
在 Linux 服務器上下載和安裝 Nikto
Perl 在 Linux 上是預先安裝好的,所以你只需要從項目頁面下載 nikto ,解壓到一個目錄里面,然后開始測試。
wget https://cirt.net/nikto/nikto-2.1.4.tar.gz
你可以用某個歸檔管理工具解包,或者如下同時使用 tar 和 gzip :
tar zxvf nikto-2.1.4.tar.gzcd nikto-2.1.4perl nikto.pl
安裝正確的話會得到這樣的結果:
- ***** SSL support not available (see docs for SSL install) *****- Nikto v2.1.4---------------------------------------------------------------------------+ ERROR: No host specified-config+ Use this config file-Cgidirs+ scan these CGI dirs: 'none', 'all', or values like "/cgi/ /cgi-a/"-dbcheck check database and other key files for syntax errors-Display+ Turn on/off display outputs-evasion+ ids evasion technique-Format+ save file (-o) format-host+ target host-Help Extended help information-id+ Host authentication to use, format is id:pass or id:pass:realm-list-plugins List all available plugins-mutate+ Guess additional file names-mutate-options+ Provide extra information for mutations-output+ Write output to this file-nocache Disables the URI cache-nossl Disables using SSL-no404 Disables 404 checks-port+ Port to use (default 80)-Plugins+ List of plugins to run (default: ALL)-root+ Prepend root value to all requests, format is /directory-ssl Force ssl mode on port-Single Single request mode-timeout+ Timeout (default 2 seconds)-Tuning+ Scan tuning-update Update databases and plugins from CIRT.net-vhost+ Virtual host (for Host header)-Version Print plugin and database versions+ requires a valueNote: This is the short help output. Use -H for full help.
這個報錯只是告訴我們沒有給出必要的參數。SSL 支持可以通過安裝相關的 perl ssl 模塊得到(sudo apt-get install libnet-ssleay-perl)。
更新 nikto 數據庫
在開始使用之前我們需要先更新 nikto 數據庫:
/usr/local/bin/nikto.pl -update
下面的命令可以列出可用的 nikto 插件。
nikto.pl -list-plugins // To list the installed plugins //
掃描以尋找缺陷
我們用一個 url 來在做個簡單的測試。
perl nikto.pl -h http://www.host-name.com
輸出樣例
會有十分冗長的輸出,可能一開始會讓人感到困惑。許多 Nikto 的警報會返回 OSVDB 序號。這是由開源缺陷數據庫(http://osvdb.org/)所指定。你可以在 OSVDB 上找出相關缺陷的深入說明。
$ nikto -h http://www.host-name.com- Nikto v2.1.4---------------------------------------------------------------------------+ Target IP: 1.2.3.4+ Target Hostname: host-name.com+ Target Port: 80+ Start Time: 2012-08-11 14:27:31---------------------------------------------------------------------------+ Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/1.0.1c DAV/2+ robots.txt contains 4 entries which should be manually viewed.+ mod_ssl/2.2.22 appears to be outdated (current is at least 2.8.31) (may depend on server version)+ ETag header found on server, inode: 5918348, size: 121, mtime: 0x48fc943691040+ mod_ssl/2.2.22 OpenSSL/1.0.1c DAV/2 - mod_ssl 2.8.7 and lower are vulnerable to a remote buffer overflow which may allow a remote shell (difficult to exploit). CVE-2002-0082, OSVDB-756.+ Allowed HTTP Methods: GET, HEAD, POST, OPTIONS, TRACE+ OSVDB-877: HTTP TRACE method is active, suggesting the host is vulnerable to XST+ /lists/admin/: PHPList pre 2.6.4 contains a number of vulnerabilities including remote administrative access, harvesting user info and more. Default login to admin interface is admin/phplist+ OSVDB-2322: /gallery/search.php?searchstring=<script>alert(document.cookie)</script>: Gallery 1.3.4 and below is vulnerable to Cross Site Scripting (XSS). Upgrade to the latest version. http://www.securityfocus.com/bid/8288.+ OSVDB-7022: /calendar.php?year=<script>alert(document.cookie);</script>&month=03&day=05: DCP-Portal v5.3.1 is vulnerable to Cross Site Scripting (XSS). http://www.cert.org/advisories/CA-2000-02.html.+ OSVDB-3233: /phpinfo.php: Contains PHP configuration information+ OSVDB-3092: /system/: This might be interesting...+ OSVDB-3092: /template/: This may be interesting as the directory may hold sensitive files or reveal system information.+ OSVDB-3092: /updates/: This might be interesting...+ OSVDB-3092: /README: README file found.+ 6448 items checked: 1 error(s) and 14 item(s) reported on remote host+ End Time: 2012-08-11 15:52:57 (5126 seconds)---------------------------------------------------------------------------+ 1 host(s) tested$
Nikto 是一個非常輕量級的通用工具。因為 Nikto 是用 Perl 寫的,所以它可以在幾乎任何服務器的操作系統上運行。
