环境准备

wordpress

我们用上一篇文章(传送门:在Ubuntu中安装docker快速搭建测试环境)中写道的官方出品的 Docker 镜像:wpscanteam/vulnerablewordpress 快速搭建:

docker pull wpscanteam/vulnerablewordpress
docker run --name vulnerablewordpress -d -p 80:80 -p 3306:3306 wpscanteam/vulnerablewordpress

我们配置下账号密码:

账户名是admin,密码是password123,标准的弱密码

然后进入网站后台,提示更新wordpress版本:

顺势更新了所有的插件,主题,随便又下了两个插件:

创建了几个用户:

testadmin:123456haha:作者
soapffz:abc123456:管理员
wpscan
WPScan是Kali Linux默认自带的一款漏洞扫描工具,它采用Ruby编写,能够扫描WordPress网站中的多种安全漏洞,其中包括主题漏洞、插件漏洞和WordPress本身的漏洞。最新版本WPScan的数据库中包含超过18000种插件漏洞和2600种主题漏洞,并且支持最新版本的WordPress。值得注意的是,它不仅能够扫描类似robots.txt这样的敏感文件,而且还能够检测当前已启用的插件和其他功能。

Kali中是自带wpscan的,但是我打开扫描就会一直卡在Updating the Database处,过了一会报了timeout错误

Kali也能访问工具的主页:https://wpscan.org/,但是挂了vpn也是更新不了,我们这里用Docker拉取一个wpscan,教程在wpscan的Github上也有:https://github.com/wpscanteam/wpscan

  • 拉取一个wpscan:docker pull wpscanteam/wpscan

docker run -it --rm wpscanteam/wpscan --url https://yourblog.com [options]

后面的[options]为参数,可为空则进行默认的扫描,当然这样每次都需要执行一次docker命令,如果想直接进入這個wpscan的docker image上执行wpscan可以使用以下指令:

docker run -it --entrypoint /bin/sh wpscanteam/wpscan

这个--entrypoint /bin/sh是什么意思呢,字面意思是用/bin/sh作为入口,我们可以理解为用/bin/sh即shell执行后面的脚本

渗透站点

我们这里默认你已经进入这个docker image中,则可以使用wpscan开头的语句:

  • wpscan --url 192.168.2.18 对整个站点进行扫描

额,可以看到服务器和php版本信息,下面扫描了一些敏感目录和文件备份,还有主题和插件信息扫描

东西太多了,我们一样一样看,但是后面的每条指令扫描出的结果都会包含以下内容:

[+] URL: http://192.168.2.18/
[+] Started: Wed Jan 30 10:12:18 2019

Interesting Finding(s):

[+] http://192.168.2.18/
 | Interesting Entries:
 |  - Server: Apache/2.4.7 (Ubuntu)
 |  - X-Powered-By: PHP/5.5.9-1ubuntu4.24
 |  - SecretHeader: SecretValue
 |  - via: Squid 1.0.0
 | Found By: Headers (Passive Detection)
 | Confidence: 100%

[+] http://192.168.2.18/robots.txt
 | Found By: Robots Txt (Aggressive Detection)
 | Confidence: 100%

[+] http://192.168.2.18/searchreplacedb2.php
 | Found By: Search Replace Db2 (Aggressive Detection)
 | Confidence: 100%
 | Reference: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

[+] http://192.168.2.18/xmlrpc.php
 | Found By: Link Tag (Passive Detection)
 | Confidence: 100%
 | Confirmed By: Direct Access (Aggressive Detection), 100% confidence
 | References:
 |  - http://codex.wordpress.org/XML-RPC_Pingback_API
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner
 |  - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access

[+] http://192.168.2.18/readme.html
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] http://192.168.2.18/wp-content/debug.log
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%
 | Reference: https://codex.wordpress.org/Debugging_in_WordPress

[+] Upload directory has listing enabled: http://192.168.2.18/wp-content/uploads/
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] WordPress version 5.0.3 identified (Latest, released on 2019-01-09).
 | Detected By: Rss Generator (Passive Detection)
 |  - http://192.168.2.18/index.php/feed/, <generator>https://wordpress.org/?v=5.0.3</generator>
 |  - http://192.168.2.18/index.php/comments/feed/, <generator>https://wordpress.org/?v=5.0.3</generator>

[+] WordPress theme in use: twentyfifteen
 | Location: http://192.168.2.18/wp-content/themes/twentyfifteen/
 | Latest Version: 2.3 (up to date)
 | Last Updated: 2019-01-09T00:00:00.000Z
 | Readme: http://192.168.2.18/wp-content/themes/twentyfifteen/readme.txt
 | Style URL: http://192.168.2.18/wp-content/themes/twentyfifteen/style.css?ver=5.0.3
 | Style Name: Twenty Fifteen
 | Style URI: https://wordpress.org/themes/twentyfifteen/
 | Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen's simple, st...
 | Author: the WordPress team
 | Author URI: https://wordpress.org/
 |
 | Detected By: Css Style (Passive Detection)
 |
 | Version: 2.3 (80% confidence)
 | Detected By: Style (Passive Detection)
 |  - http://192.168.2.18/wp-content/themes/twentyfifteen/style.css?ver=5.0.3, Match: 'Version: 2.3'

于是我们知道了它wpscan默认每次都会扫描敏感文件备份文件上传目录wordpress版本信息主题信息

接下来我们来扫描一些比较敏感的东西:

  • wpscan --url 192.168.2.18 --enumerate u对用户名进行枚举

可以看到很轻易就得到了用户名

  • wpscan --url 192.168.2.18 --enumerate t对主题进行扫描

得到了主题的名字和版本

  • wpscan --url 192.168.2.18 --enumerate p对插件进行扫描

  • wpscan --url 192.168.2.18 --enumerate vp扫描插件中的安全漏洞

没有插件的漏洞,同样的,扫描脆弱的主题将后面的参数t改为vt即可

  • wpscan --url 192.168.2.18 --enumerate tt扫描TimThumb文件
TimThumb 是一个非常简洁方便用于裁图的 PHP 程序,只要给他设置一些参数,它就可以生成缩略图。现在很多 WordPress 主题中,都使用 TimThumb 这个 PHP 类库进行缩略图的处理。通过 TimThumb的漏洞很容易获得站点 root 权限。

没有找到

  • wpscan --url 192.168.2.18 --passwords /mnt/passwd.txt --username admin –-threads 100暴力破解admin密码

这里发现读不到文件:

了解到是需要将宿主机目录挂载到镜像中的,所以我们删除这个容器重新创建一个容器:

exit
docker ps -a (查看wpscan这个container的id)
docker stop [id] 先停止
docker rm [id] 再删除
docker run -it -v /mnt:/tmp --entrypoint /bin/sh wpscanteam/wpscan 多加一个-v参数,使用:分割宿主机目录和镜像目录

关于镜像内挂载目录的详解可以参考这篇:https://www.cnblogs.com/ivictor/p/4834864.html

然后我们爆破:

账号密码只有--passwords/--usernames选项,都有s,但是不但可以指定字典也可以指定单个用户名:

wpscan --url 192.168.2.18 --passwords /tmp/passwd.txt --usernames admin –-threads 100

wpscan -h帮助中的说明:
-P, --passwords FILE-PATH List of passwords to use during the password attack.
If no --username/s option supplied, user enumeration will be run.
-U, --usernames LIST List of usernames to use during the password attack.

开100个线程效果如下:

爆破效果及速度都取决于字典和线程的大小,爆破admin密码的效果如下:

密码在16878行,花费了35分20秒,速度,emmm,爆破是世界上最没有效率的办法

其他的参数可以使用wpscan -h 来查看

利用searchreplacedb2.php修改邮箱重置密码拿下管理员账号

这是一个用于WordPress网站更换域名之后批量替换数据库内容的工具。但是用了两下之后可以看出,它只能替换,并没有找到查询数据的方法。

另外,searchreplacedb2.php会自动读取wp-config.php,然后返回的表单里面也包含数据库用户名和密码。存在一个遗留后门searchreplacedb2.php,可以利用它修改管理员admin预留的邮箱,点击忘记密码发送重置密码链接,然后重置密码。

这个文件的利用方式参考文章:https://blog.csdn.net/t91zzh5f/article/details/55805438

防范措施

1.怎么防止wordpress网站被人暴力破解管理员密码呢?

防止暴力破解的最好方式是限制一个IP地址的尝试登录次数。WordPress有n多插件可以实现这个功能,比如:

  • Login Security Solution
  • Brute Force Login Protection
  • 也可以写一个脚本防止爆出个人密码

2.如何防范扫描插件、主题、TimThumb文件

使用Block Bad Queries (BBQ)插件,就可以屏蔽和禁止这类扫描

最后修改:2019 年 07 月 13 日
如果觉得我的文章对你有用,请随意赞赏