Vulnhub靶机:DC-5

标签本地文件包含(LFI)FUZZPHP伪协议nginx日志文件写一句话反弹shellscreen提权

0x00 环境准备

下载地址:https://www.vulnhub.com/entry/dc-5,314/
flag数量:1
攻击机:kali
攻击机地址:192.168.1.31
靶机描述:

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.

0x02 信息搜集

1.探测靶机地址

命令:arp-scan -l
靶机地址是192.168.1.33

2.探测靶机开放端口

命令:nmap -sV -p- 192.168.1.33
开放了80端口,看一下80端口,不是什么CMS。

3.扫描目录

命令:dirb 192.168.1.33 /usr/share/wordlists/fuzzDicts/directoryDicts/php/phpFileName.txt

也没有什么敏感目录,只有contcat模块和用户有交互,看一下这个模块。

0x03 本地文件包含LFI

在Contact模块下可以留言,随便填写一下提交:


提交后页面:


诶,下面的2019好像变成2018了,再刷新几次看看


又变了,这里应该是footer.php控制的,访问一下footer.php看看。


多刷新几次,发现也会改变,所以这应该是刚才那个页面thankyou.php包含了footer.php,这里应该是有个文件包含。fuzz一下


这里通过index.php来爆破参数


发现一个file参数,验证一下,访问:192.168.1.33/thankyou.php?file=/etc/passwd

file确实是文件包含的参数,这是一个Linux系统。
除了这样验证,还可以使用PHP伪协议读取thankyou.php代码来查看是否存在文件包含漏洞,访问http://192.168.1.33/thankyou.php?file=php://filter/read=convert.base64-encode/resource=thankyou.php

Base64解码后可以看到,确实有文件包含漏洞


0x04 nginx日志文件写入shell

使用浏览器插件可以看到web容器是nginx


尝试寻找nginx的日志文件,里面会记录请求的信息。通过请求信息来注入恶意代码。nginx日志文件默认放在/var/log/nginx下,以.log结尾,使用burp爆破一下:

发现该目录下存在两个文件,分别是access.log和error.log。


写入一句话


使用phpinfo验证


连菜刀


连接成功


0x05 反弹shell

/tmp/目录下新建一个php文件,用来反弹shell:

先在kali上监听指定端口,然后文件包含shell.php文件


成功得到shell,切换到bash外壳,命令:python -c 'import pty;pty.spawn("/bin/bash")'

0x06 提权

使用find命令,查找具有suid权限的命令。命令:find / -perm -u=s -type f 2>/dev/null

发现有个screen,别问我为啥用这个提权,表哥们都用,咱也不敢问。
命令:searchsploit screen 4.5.0

发现两个可利用文件,使用第一个,复制下来进行编译。
首先将上部分的c语言代码另存为libhax.c文件:

编译:gcc -fPIC -shared -ldl -o libhax.so libhax.c

将中间部分的C语言代码另存为rootshell.c文件:


编译:gcc -o rootshell rootshell.c

41154.sh中剩下的代码整理一下,另存为dc5.sh,并输入:set ff=unix,保存退出

将整理好的3个文件用菜刀上传到靶机的/tmp目录下


为dc5.sh添加执行权限并执行


提权成功,在/root下找到flag文件


由于我不会每天都登录,所以有什么私信或者评论我都不能及时回复,如果想要联系我最好给我发邮件,邮箱:Z2djMjUxMTBAMTYzLmNvbQ==,如果发邮件请备注“”


参考链接:

1.Vulnhub靶机实战——DC-5
2.VulnHub—DC-5
3.DC-5 vulnhub靶机实战

你可能感兴趣的:(Vulnhub靶机:DC-5)